Jump to content
  • Advertisement
Sign in to follow this  
benjaminehill

agents data

This topic is 3888 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

I have dereloped a 2D engine in Directx and C++. All that can be is done within the engine itself (alog with polling input devices and calling the game class's update and render). I like the way it work, games can be developed quickly. the problem i have is when it comes to getting data from one agant to another (e.g. position). at the mo each agant is an inherited class of an interface which is loaded into a state like system. this system holds all the agant classes (that have the same sprite) and will update and render each one. so how can one agant request data from another any ideas

Share this post


Link to post
Share on other sites
Advertisement
Well, that's a broad question...

With what I get from your post, it seems you're implementing the registry pattern in your engine, at least somehow.
With the registry, every object bears a unique identifier, for which you can query the registry, which in turn delivers a reference to the object.

So, for transmitting information from object to object, in your case it would be the simplest way to query the info from the registry mechanism, where you get a reference you can use to query the actual object for the info you need.

Since this can lead to heavy performance hits, I would recommend you to redesign your object system; object management based on quadtrees can simplify a lot of your object interactions, and for 2D, quadtrees are just right.
Plus, you get O(log n) behaviour instead of O(n) behaviour when using a list, like you do at the moment.

Share this post


Link to post
Share on other sites
If your objects use inheritance you can use RTTI to "Request" information from an entity. For instance, some function accepts a base object pointer, and we want to get the position from this object. We attempt to dynamically cast the object to a position object, if it succeeds, we have the position. If it fails, you can assert or handle the case appropriately.

Warning this can be costly.

ex:

class Base
{
public:
virtual ~Base() { }
};

class Position
{
public:
Position() : X(0), Y(0), Z(0) {}
float X, Y, Z;
};

class Player : public Base, Position
{
public:
Player() {}
};

void PrintPosition( const Base *agent )
{
const Position *position = dynamic_cast<const Position*>(agent);

if (position)
{
printf("Position: %f, %f, %f\n", position->X, position->Y, position->Z);
}
else
{
printf("Agent does not have a position component.\n");
}
}

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!