Jump to content
  • Advertisement
Sign in to follow this  
origil

Using RTS units, inventory and shots.

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm having a bit of a problem deciding how to store my unit, weapon and shot classes in an RTS game. As the units, shots and weapons are added and removed from the game in real-time obviously I'll need to use lists. My question is: Should I use lists that point to void pointers? Would that be a good approach for an RTS or would it be too slow for such a game? Should I write 3 different types of LIST classes for each one of them? Thanks in advance, Ori.

Share this post


Link to post
Share on other sites
Advertisement
The way i'm planning on doing all that is through a base class containing all common elements, and then inheriting this base clase and programming individual units, shots, etc as seperate classes. That way I avoid void pointers, and each will have the same interface.

also, why write several different classes to do the same thing? Take advantage of templates if you are using C++.

Share this post


Link to post
Share on other sites
Quote:
Original post by origil
Should I use lists that point to void pointers?

No. You should never use void pointers unless you are doing extremely bizarre, low-level, doing-things-to-bits procedures.

Ask yourself: are these different things you want to store all different KINDS of one thing? does that general thing, of which they are kinds, have nontrivial commonality?

Share this post


Link to post
Share on other sites
(In C++) You should NOT have everything inherit from the the same base. If you do, you'll have to explicitly switch on types, which is what virtual functions are there for.

Make some abstract interface classes for different things, with the appropriate (pure?) virtual functions. Then inherit from those as nessesary and keep lists or vectors to smart pointers to those instead.

Also note that vector is faster than list for small sizes, so you should use vector for most things unless you need a list's iterator invalidation properies ( which you usually don't if you're using smart pointers ).

Share this post


Link to post
Share on other sites
Actually, the 3 types of classes share very little in common. The only things in common are the physical coordinates and speed.
There are plenty of different variables and methods for each data type.
Thanks everyone!
I guess templates is the easiest and fastest way for me to go.
I don't want to delve into inheritance and overly complex data structures as time is currently an expensive resource.
Laters!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!