Jump to content
  • Advertisement
Sign in to follow this  
Mephs

Game object connections

This topic is 4771 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 all, I'm after a little help if possible, with a system I'm trying to implement to maintain connections between objects. Basically the problem is trying to maintain a particle system for energy beams, where the beam connects 2 objects and either end of the beam must always match the position of the object it is connected to. This will be used for two purposes. Firstly to represent energy transfer between a variety of objects, and secondly to represent the attachment of the player to an interactive object in the level. So far, I've got a separate class to deal with energy transfer. Objects must inform the class when a connection is initiated. The energy transfer manager (ETM) then returns a unique identifier, which the objects both store in a vector of ints. Every frame, the object sends a message to the ETM containing its position and the unique identifier of any connections it has. After this, the ETM then traverses it's list of received messages and spawns a particle if the connection didn't previously exist, updates the particle if the connection still exists and deletes a particle if it fails to receive a message from both objects involved (if one message is received it can be assumed the connection is inactive as the other object must have been destroyed). If only one message is received, it sends a message back to the object telling it to remove the uID of the inactive connection from its list. In this way, we never have to check any pointers to objects, so if an object is destroyed while there is an active connection, we don't get any horrible crashes. Now this is all well and good, but I can't help but feel perhaps I'm making a mountain out of a molehill.... is there a simpler way to manage such connections without having to worry about objects that may have been destroyed? If anyone has any better suggestions I'd appreciate the advice!! Best Regards, Steve

Share this post


Link to post
Share on other sites
Advertisement
It might be easyer to let the manager interogate the objects insteads of sending messages from objects every frame.
Ex: when you update your ETM and you check the status for every pair. You get the same result with fewer messages.
However you must remove the pairs related to one object when the object is destroyed.

Share this post


Link to post
Share on other sites
maybe do some exception handling. im not real good with it in c++ (ive only dealt with Java exceptions before) but try to access that object (which may or may not exist) and if you catch an error, it means the object no longer exists or is invalid. this way, once you catch this error, maybe null pointer or something, you can discern that it doesnt exist and you can delete the pair connection from your ETM.

Share this post


Link to post
Share on other sites
I agree with c0mas. The messaging system seems like it would take substantially more processing time than simply doing a check to see if the object still exists. I must admit, I wasn't sure about it in your post, i understand you have you energy transfer managment class, but do you also have a class/object for each beam? If not, I would recommend you make an object for each beam (the collection of which can be handled by your management class) -- this way, you can store the ID of the two objects the beam is connecting to and simply move the endpoints in relation to those two objects location (which should be stored in their own object). Each frame you should check to see if both those objects exist and if not, delete the beam object. Finally, if each object has a unique identifier then when the object is deleted that ID should also no longer exist. By checking to see if that ID exists you will not need to worry about refering to non-existant objects, which is much faster than messaging. Only problem with this is if a new object is spawned with the same id (since it is now available) the beam might attach to that object -- HOWEVER, this only applies to the frame RIGHT after the object is destroyed, since once it is detected to no longer exist the beam object should be terminated and deleted anyway.

(plus it is cleaner and easier to understand if each beam exists as it's own object)
I hope this isn't too confusing.

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!