Hey,
Yeah, that is what I have started to do. I created a little program is dos using all my classes. Also, I have changed the code so that BulletManage puts each object in the linked list. I didn't use the std thing, but wrote my own linked list code. Still the same problem so I will continue to try to find the fault. Well thanks a lot. I have learned a lot about OOP in general in these last 2 days. One question though, should I have all my pBulletFirst, Last, Next, and Prev in the Manager or Bullet Class?
Later,
James
Edited by - JSCFaith on May 14, 2001 8:40:46 AM
Linked Lists
The manager should contain the head and tail of the list - pBulletFirst and Last. As for the prev and next pointers, if you were being really anal, you could create a Node class which contained them and have Bullet inherit from Node. Personally, I think that is over engineering for your project so I would have the prev and next pointers in the bullet class.
-DeVore
ps: can you post your bullet deletion code - ie/ RemoveDeadBullets(...)
-DeVore
ps: can you post your bullet deletion code - ie/ RemoveDeadBullets(...)
quote:
Original post by DeVore
The manager should contain the head and tail of the list - pBulletFirst and Last. As for the prev and next pointers, if you were being really anal, you could create a Node class which contained them and have Bullet inherit from Node. Personally, I think that is over engineering for your project so I would have the prev and next pointers in the bullet class.
It wouldn''t be over-engineering, it would just be plain wrong.
Bullet should not know it is in a list.
Read the above line until you understand that it is true or until your eyes fall out.
What this means is: there should be nothing in bullet.h or bullet.cpp that has anything to do with any list variables or functions. You shouldn''t even include the header files for whatever list management you''re using, and this precludes inheriting from some node class. The reason is, you should be able to put Bullets in a list, a vector, a heap, a hash table, or a static array. If you make Bullet inherit from Node, you''ll have to have ListBullet : public ListNode, HashBullet : public HashNode, etc., etc. This is a very bad thing.
The best way to do it, and the way STL does it, is to have your list manager include a nested class that describes a node. Pseudo-code:
|
Using STL''s list class, this is templated so you can make a list of anything. The restriction this places on Bullet (i.e. the contained data) is that it has to have a valid copy constructor, and that at least one copy of the object will occur (when it is inserted). But this allows you to use anything in the list and do so without wasting any memory (two pointers per object) and encapsulating all of the list functionality in a completely separate class.
Ok.. Well I read your post and am trying to get what you said I should to do, to work. I created a manager class that includes everything related to the list including the nested class. How would I use the Node class? Should I declare it like this:
Here is my entire BulletManager Class. Tell me if I am doing this correct.
Ok, is that correct? Well my next question is this. How would I use pNext, pPrev and stuff in the 'BulletNode' class with the RemoveDeadBullets function. Also, do you really need that 'Bullet _data;' thing? What was it for?
Oh yeah, and DeVoir, here is the RemoveDeadBullets thing, It doesn't work with the changes I made in the class above though.
Ok, well I hope I don't sound too stupid, lol. I really don't feel right asking all these questions. So if you are getting annoyed with me, don't answer. I still have so many questions. I will try to get the changes you suggested I make to work, but we will see. BTW, It doesn't crash anymore, I found the error, but I still want to try to get my code more Object Oriented. Right now its just a bunch of classes all mangled together with each class not having any real purpose.
Well thanks a million guys. I am learning a lot, too bad I let my friend borrow my C++ book. Oh well, you live, you learn.
Later,
James
Edited by - JSCFaith on May 14, 2001 7:06:51 PM
Edited by - JSCFaith on May 14, 2001 7:13:14 PM
|
Here is my entire BulletManager Class. Tell me if I am doing this correct.
|
Ok, is that correct? Well my next question is this. How would I use pNext, pPrev and stuff in the 'BulletNode' class with the RemoveDeadBullets function. Also, do you really need that 'Bullet _data;' thing? What was it for?
Oh yeah, and DeVoir, here is the RemoveDeadBullets thing, It doesn't work with the changes I made in the class above though.
|
Ok, well I hope I don't sound too stupid, lol. I really don't feel right asking all these questions. So if you are getting annoyed with me, don't answer. I still have so many questions. I will try to get the changes you suggested I make to work, but we will see. BTW, It doesn't crash anymore, I found the error, but I still want to try to get my code more Object Oriented. Right now its just a bunch of classes all mangled together with each class not having any real purpose.
Well thanks a million guys. I am learning a lot, too bad I let my friend borrow my C++ book. Oh well, you live, you learn.
Later,
James
Edited by - JSCFaith on May 14, 2001 7:06:51 PM
Edited by - JSCFaith on May 14, 2001 7:13:14 PM
May 14, 2001 06:33 PM
I just reread through your post. I think I understand what the ''Bullet data;'' thing is for. Didn''t notice the "(i.e. the contained data)" Well, I will do some more programming to try to fix all my classes. Damn, I really didn''t know what I was doing. My classe are a mess... ah!!!!
Later.
Later.
I just reread through your post. I think I understand what the ''Bullet data;'' thing is for. Didn''t notice the "(i.e. the contained data)" Well, I will do some more programming to try to fix all my classes. Damn, I really didn''t know what I was doing. My classe are a mess... ah!!!!
Later.
Later.
Hey,
I have been doing some research, but have come up empty handed. I really only have one obstical in my way. You said I should have a nested class in the Manager class. It should contain the next and prev pointers. My question is, if I don''t inherite from Bullet, how does BulletNode access anything? How would I move about the list and use different members of class Bullet. For example: Before, when I had the Bullet class manage the linked list. I would call a function called ''DrawBullets'' which, like the name implies, draws all the bullets that are alive. The code looked like follows:
The code above will not work with the nested class; because, as you know, the ''pNext, pPrev'' do not point to a ''Bullet'' object. They point to a ''BulletNode'' object. So, how would I do the same exact thing as above with this new class layout? I read a few tutorials on STL, hoping they might have some information on the question I am asking. Of course, I did not want to use STL. I still want to try to code my own linked list. Well, if you could help, that would be great.
Later.
I have been doing some research, but have come up empty handed. I really only have one obstical in my way. You said I should have a nested class in the Manager class. It should contain the next and prev pointers. My question is, if I don''t inherite from Bullet, how does BulletNode access anything? How would I move about the list and use different members of class Bullet. For example: Before, when I had the Bullet class manage the linked list. I would call a function called ''DrawBullets'' which, like the name implies, draws all the bullets that are alive. The code looked like follows:
|
The code above will not work with the nested class; because, as you know, the ''pNext, pPrev'' do not point to a ''Bullet'' object. They point to a ''BulletNode'' object. So, how would I do the same exact thing as above with this new class layout? I read a few tutorials on STL, hoping they might have some information on the question I am asking. Of course, I did not want to use STL. I still want to try to code my own linked list. Well, if you could help, that would be great.
Later.
while your pNext and pPrev do not point to Bullets, your BulletNode should.
Here''s the Linked list I am using for my project. It looks incredibly similiar to what you seem to be doing.
In the above example, p is a node in the list, or a BulletNode for you. p looks at its data, which is a Bullet and says "draw yourself". Then p becomes the next node in the list, and the cycle continues until there are no more nodes.
I''m not sure what research you have done, but here''s a link to a tut. on Linked lists.
http://www.gamedev.net/reference/programming/features/uds1/
Here''s the Linked list I am using for my project. It looks incredibly similiar to what you seem to be doing.
|
In the above example, p is a node in the list, or a BulletNode for you. p looks at its data, which is a Bullet and says "draw yourself". Then p becomes the next node in the list, and the cycle continues until there are no more nodes.
I''m not sure what research you have done, but here''s a link to a tut. on Linked lists.
http://www.gamedev.net/reference/programming/features/uds1/
May 15, 2001 05:36 PM
Thanks a lot Big B and everyone else. I think I got it now. Let me ask one last question. I think I get what you told me Big B and I created a CreateBullet function. Does this look correct?
BTW, do I need a copy constructor in the ''Bullet'' class for this to work? I haven''t tested the code yet.
Well thanks a lot everyone.
Later.
|
BTW, do I need a copy constructor in the ''Bullet'' class for this to work? I haven''t tested the code yet.
Well thanks a lot everyone.
Later.
You only seem to pass pointers to Bullet objects so you shouldn''t need a copy constructor. Copy constructors are required when you are passing a whole object to a function since the object will be copied to the stack in that case.
Snale
+--My humble and superior homepage
Snale
+--My humble and superior homepage
Snale+--My humble and superior homepage
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement