Linked Lists in games
Hi, could someone explain me why linked lists are used in 3d graphics engines ? I''ve seen lot of examples and they use a class called CNode and then derive a class CObject from it. I can''t understand the concept. Please help me out. Thanks.
Bye
Linked lists are used to handle a quantity of objects that is always variable.
For example, if you write a simulation of spacecraft all firing at each other, the craft are objects and the bullets are objects. But there could be any number of bullets in existence at any given time. Even though there might be a given maximum to the number of shots that could be in the arena (meaning that an array COULD be allocated to track all of them), using a linked list makes it dynamic enough that you could actually increase the number of craft and not worry about the shots overflowing a pre-allocated array.
Make sense?
[edited by - Waverider on June 26, 2002 10:28:21 AM]
For example, if you write a simulation of spacecraft all firing at each other, the craft are objects and the bullets are objects. But there could be any number of bullets in existence at any given time. Even though there might be a given maximum to the number of shots that could be in the arena (meaning that an array COULD be allocated to track all of them), using a linked list makes it dynamic enough that you could actually increase the number of craft and not worry about the shots overflowing a pre-allocated array.
Make sense?
[edited by - Waverider on June 26, 2002 10:28:21 AM]
I don''t know if that CNode class is just a singly linked list, but cyclic linked lists are VERY helpful when making an engine or any kind of game.
Deriving CObject from CNode is a common approach IMHO, I''m using it in my game. I derive all my world-based objects from CObject, and then these objects can be linked together.
Doing that just gives the engine some better organization.
Deriving CObject from CNode is a common approach IMHO, I''m using it in my game. I derive all my world-based objects from CObject, and then these objects can be linked together.
Doing that just gives the engine some better organization.
Remember,
if you code in c++ you "should" (or can) use the templated STL "list" class for linked lists.
my advise is to learn STL... it is fast and easy to use.
zilch_
[edited by - zilch_ on June 26, 2002 2:41:31 PM]
if you code in c++ you "should" (or can) use the templated STL "list" class for linked lists.
my advise is to learn STL... it is fast and easy to use.
zilch_
[edited by - zilch_ on June 26, 2002 2:41:31 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement