Using RTS units, inventory and shots.

Started by
3 comments, last by origil 18 years, 8 months ago
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.
The Department of Next Life - Get your Next-Life Insurance here!
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++.
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd
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?
(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 ).
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!
The Department of Next Life - Get your Next-Life Insurance here!

This topic is closed to new replies.

Advertisement