implementing classes and linked lists into games, as well as an animation question

This is a discussion on implementing classes and linked lists into games, as well as an animation question within the Game Programming forums, part of the General Programming Boards category; I'm wondering how I would implement linked lists into a game. I use a sort of linked list, but you ...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    implementing classes and linked lists into games, as well as an animation question

    I'm wondering how I would implement linked lists into a game. I use a sort of linked list, but you can't add and delete things. I create a pre-defined number of variables of the same type, and hold the address of the next one. The list size doesn't change during the game, but each one has a flag set to true or false that says whether or not to do anything with it.

    Would it be more efficient to use a linked list for this sort of thing? Instead of setting that flag to true or false you just add/delete a node, right? Get what I mean?

    For example, pretend you had a game with bouncing balls, and you wanted two balls going at once. To do this, I would declare two variables of my struct type, and have a member variable called next, and set them to point to eachother. Then have a flag that is set to true of false (which represents if it is "active" or not). I'm thinking it would be more efficient to use a linked list, and when we need another ball, just add one to the linked list. Then in my drawing routines, collision checking routines, etc. you would just traverse throught the list and perform all actions on each node in the list. Then when I check for the ball disappearing, instead of changing its flag you just delete the node.

    With that method, I wouldn't need to declare [unneeded] variables at the beginning of my program.

    1) Is this a common / efficient way to implement linked lists into a game?

    Secondly, classes. For all my past projects, I've used structs and not classes. I never read a single thing about classes, except very basic things.

    2) What are some advantages of using classes vs. structs in any type of program?

    Thirdly, animations. The way I've come to do animations thus far (not moving a bitmap), is to do this. Give each variable of whatever type (a ship, block, person) of variable you have a bool that stands for if it should be animating or not. Then an int that holds which frame it is on.

    3) Is this a good way to handle animations? Is there a common method used to do things like this when there are large numbers of objects that might possibly need to be animated?

    I'm getting to the point where I have to manage large amounts of common "objects" modularly. Organization is pertinent. Thanks for any responses.

  2. #2
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704

    Hrm.

    If youd like to see a linked list being used in a game, look here:
    first *COMPLETED* game. (Nibbles)

    I use a linked list in my class CWSegment (body segment of worm) with methods of setNext,getNext, setPrev, getPrev. I then use a controll class (CWorm) with methods like AddSegment(), Update(), Render(), ClearList(), etc. Perhaps a perouse through my source *may* help. (Im releasing a directX upgrade of this in about 30 mins)

    As for my opinion on when to use a linked list:
    Its really programmer dependent. Generaly for bullet or ball type objects I would use an array becuase they are generally simple to handle. However, in more complex games like 3D stuff, objects get much more complex having to handle world translations and local translations, there own rendering methods, threre own update methods etc. In this case you generaly create a base object class with linked list built into, and inherit this class into all your other objects. IE:
    class CObject
    {
    // linked list methods vars
    }
    class CBox : public CObject
    {
    // render methods, updating all around handling etc.
    }
    Now you can run through all the objects in your game and call thier overridden methods.

    My outlook on Structs and ClassesIm only vaguely sure on these)
    From what I've heard/read, in c structs didnt have methods(?), and until recently (C++) were they given that performance. Other then that, classes and structs (in c++) are very similar. However I generally keep the practice if something needs methods use classes, if its just variables use structs.

    Hope I helped any.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  3. #3
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I like linked lists. A lot of people tell me to use vectors, but there is just something I don't like about them. In fact, I never use any of STL.

    http://www.inversereality.org/tutori...nkedlists.html

    that's a good site for basics, although his coding ability and style is crap. I basically just learned the basics on how to make one from there and taught myself how to make it a reality. I'm experimenting with Polylinked lists. All the website covers is Monolinked lists (a lot of times referred to as Singly Linked Lists)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubly Linked Lists
    By Swerve in forum C++ Programming
    Replies: 6
    Last Post: 03-23-2009, 01:51 PM
  2. Linked Lists and Classes
    By reversaflex in forum C++ Programming
    Replies: 7
    Last Post: 09-23-2008, 01:25 AM
  3. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 05:32 PM
  4. Radix Sort, Strings, and Linked Lists
    By dark paladin in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2003, 04:24 PM
  5. Linked Lists and Inheritance
    By mattyneedshelp! in forum C++ Programming
    Replies: 6
    Last Post: 02-01-2003, 07:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21