This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Handling creation/deletion of units within game


Handling creation/deletion of units within game

Postby j.edwards » Apr 13, 2004 @ 8:02am

I'm developing a game that has units which are continually created and deleted as units are built and destroyed and am running into problems with objects referencing units.

For instance, a smart missile has a lock target of type Unit. It's locked target may actually get destroyed before the missile gets to it etc causing access violations. I tried a quick fix by adding an "Active" property which helped a bit but doesn't catch all cases and is messy to work with.

Units are currently stored in the player class, ie. Player -> Units.

So I am thinking about having a "Unit Register" which is basically an array of all units. As new units are created they are added to the register, and as destroyed they are deleted, and instead of referrencing the unit directly it referrences the element in the unit register array.

I thought I would post here before implementing just to see if anyone knows of a better way ... any suggestions?
User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby Peter Balogh » Apr 13, 2004 @ 10:28am

I don't see how that would fix your problems. Sure, it'd get rid of access violations, but you'd have a rather high chance of confusion in the game. E.g. the index of the unit your rocket is targeting would be freed after the target is destroyed and would be shortly reused for another rocket objects, etc... The way to do it is either keep a reverse list of objects referencing each unit, so when something happens to the unit it can call a HandleEvent function in all the objects referencing it, so they can all handle the situation in their own fashion. (Like a target-locked rocket could self-destroy or find a new target, etc)

Cheers,
Peter of PDAmill
Download high quality games for your pda: www.pdamill.com
User avatar
Peter Balogh
pm Insider
 
Posts: 163
Joined: Dec 19, 2001 @ 7:54pm
Location: PDAmill HQ


Postby j.edwards » Apr 13, 2004 @ 11:15am

Peter: I was trying to save on lists per object, but you are right. I will give the suggestion a go. Thanks.
User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby Dan East » Apr 13, 2004 @ 6:37pm

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby warmi » Apr 13, 2004 @ 9:08pm

warmi
pm Insider
 
Posts: 518
Joined: Aug 24, 2002 @ 8:07am
Location: Chicago USA


Postby j.edwards » Apr 14, 2004 @ 3:06am

User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby warmi » Apr 14, 2004 @ 4:05am

warmi
pm Insider
 
Posts: 518
Joined: Aug 24, 2002 @ 8:07am
Location: Chicago USA


Postby Peter Balogh » Apr 14, 2004 @ 7:24am

Download high quality games for your pda: www.pdamill.com
User avatar
Peter Balogh
pm Insider
 
Posts: 163
Joined: Dec 19, 2001 @ 7:54pm
Location: PDAmill HQ


Postby kaboomie » Apr 14, 2004 @ 9:04pm

kaboomie
pm Member
 
Posts: 18
Joined: Oct 28, 2002 @ 9:56pm
Location: California


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum