Skip to main content
GameDev.net gamedev.net
🔒 Locked

game programming?

Started by FxMazter May 21, 2003 at 4:02 PM 8 replies 950+ views
Original Post
FxMazter
FxMazter
Hello! While looking at posts here on gamedev, I have noticed several people say that you should know about linked lists, trees, stacks and queues, before starting to program a game. Well, I got a bit curious about this... cuz I know very little about those. But I have programmed an topdown aka "Diablo" rpg with DX7. So, could you people briefly explain what those are and in what cases they are used? thx
alnite
alnite
It''s not mandatory, but good to know. As AP has said, they will help you in managing your data.
Zefrieg
Zefrieg
Knowing how to create ABS (Abstract Data Structures) is a part of knowing how to program. It certainly makes programming anything just a bit easier.

You can either learn and use the STL(in C++), which has all the stuff you need, or you can make your own. The plus to making your own is that you can easily inherit and modify a certain one and equip it with more functionality. Also, the STL is built for speed and not safety, so it let''s you make mistakes.

Basically ABS''s make the pains of dynamic memory allocation a breeze. Also, most of the structures don''t require a whole lot of extra work compared to just using arrays. Also, there are plenty of cases when using structures like trees can increase the effeciency of your code.

If you plan on programming these structures, just make sure you do them with templates. That way, you can use them for anything.

pacman2003
pacman2003
hi,
lemme try to give u a brief introduction to linked lists.

suppose u had to write a program which would input - say 5 -numbers from the user and print the sum. u could implement it in 2 ways:

METHOD 1:


      
int a, b, c, d, e ;
int sum ;

print ("Enter number 1") ;
input (a) ;
print ("Enter number 2:") ;
input (b) ;
print ("Enter number 3:") ;
input (c) ;
print ("Enter number 4:") ;
input (d) ;
print ("Enter number 5:") ;
input (e) ;


sum = a+b+c+d+e ;
print ("The sum is %d", sum) ;



METHOD 2:


        
#define MAXNUMS 5

int nums_to_add[MAXNUMS] ;
int sum ;

for (i = 0, sum = 0; i < MAXNUMS; i++)
{
print ("Enter number %d", i) ;
input (nums_to_add[i]) ;
sum += nums_to_add[i] ;
}

print ("The sum is %d", sum) ;



but in case u wanted to sum 100 numbers, the first method would require a BIG change whereas the second method would only require changing the line:

#define MAXNUMS 5
to
#define MAXNUMS 100

this is the advantage of the second method over the first.


but now consider a case where u want the user to decide how many numbers to sum. using arrays this could be done as follows:



        
#define MAXNUMS 1000

int nums_to_add[MAXNUMS] ;
int sum ;

for (i = 0, sum = 0; i < MAXNUMS; i++)
{
print ("Enter number %d", i) ;
input (nums_to_add[i]) ;
sum += nums_to_add[i] ;
if (!continue)
break ;
}

print ("The sum is %d", sum) ;




however the array implementation has a major limitation. speaking generally, you must know the maximum number of items in your collection when you create it (as illustrated by #define MAXNUMS 1000). we use a structure called a linked list to overcome this limitation.

the linked list is a very flexible dynamic data structure. items may be added to it or deleted from it at runtime with some overheads. with linked lists, the number of items is limited only by memory availabilty.

in a linked list, memory is allocated for each item as it is added to the list. a link is kept with each item to the next item in the list by means of a pointer. each node of the list has two elements - the item being stored in the list and a pointer to the next item in the list. the last node in the list contains a NULL pointer to indicate that it is the end or tail of the list.

as items are added to a list, memory for a node is dynamically allocated. thus the number of items that may be added to a list is limited only by the amount of memory available.

am in a hurry now so will explain trees, etc later.

Regards and hope this helped.

P.S. i am only an intermediate programmer (if not a beginner) and definitely not an expert, so plz forgive me for ne mistakes i may have made.

[edited by - pacman2003 on May 22, 2003 1:23:33 PM]
dangerduo
dangerduo
Hey, I just finshed a Data Structure course at my college, and I can tell you that knowing how to do data structure is useful. It is true that you can design kick ass 3D games, but by applying Data Structring, it can help create your programs more efficient, better running, better ways to handle data, and etc.

For example, a flight simulation can be simply implement using a queue.

Also, if you were to design a hospital record system, the splay tree would be the ideal choice for moving records that you always access to the top and the one that you don''t touch to the bottom.

Data Structure is not a pretty class becuase I got bored of it with all the Big O, and differatiating all these formula to prove its efficient speed. But yet, i believe if you want to make it big as a coder, Data Structure is must learn.
Spearhawk
Spearhawk
quote:
Original post by Anonymous Poster
There are numerous reasons why you should know about Abstract Data Types such as stacks, queues, linked lists, and trees before heading off and making a game.


I don''t agree, there''s numerous reasons why you should know about these things after having programmed games for a while. But you don''t need to know them before you start, what you need to know you''ll learn as you goes along (as long as you don''t copy code that you don''t understand of course).




--
Spearhawk Productions
Project Andromeda
Ready4Dis
Ready4Dis
quote:
Original post by Spearhawk
quote:
Original post by Anonymous Poster
There are numerous reasons why you should know about Abstract Data Types such as stacks, queues, linked lists, and trees before heading off and making a game.


I don''t agree, there''s numerous reasons why you should know about these things after having programmed games for a while. But you don''t need to know them before you start, what you need to know you''ll learn as you goes along (as long as you don''t copy code that you don''t understand of course).




--
Spearhawk Productions
Project Andromeda




So you''re saying to first write a game, THEN figure out how it works? I''m sorry, but I''d have to dissagree with that.

"Hey, you know nothing about how to parachute... lets go, pack your own chute, we''ll jump a few times, THEN I''ll teach you the correct way to pack your chute". Yeah, sounds like a GREAT idea in theory, until you splat into the ground because you didn''t feel like learning properly first and wanted to rush right into it. Same with game programming, if you don''t learn things before you use them, you will fall flat on your face.
Kaezin
Kaezin
"So you''re saying to first write a game, THEN figure out how it works? I''m sorry, but I''d have to dissagree with that.

"Hey, you know nothing about how to parachute... lets go, pack your own chute, we''ll jump a few times, THEN I''ll teach you the correct way to pack your chute". Yeah, sounds like a GREAT idea in theory, until you splat into the ground because you didn''t feel like learning properly first and wanted to rush right into it. Same with game programming, if you don''t learn things before you use them, you will fall flat on your face."

I don''t think that''s what he meant. I started game programming before I knew about linked lists or the like, but as I began to develop more complex games I needed better ways of storing data. It was then that I learned about everything about these abstract data types, and I''m still learning. As I find something new, I try to think of where I could use that in my game. Sooner or later, I end up implementing it in some way.
Half the people you know are below average.Trogdor the Burninator

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.