# Events and entity communication

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

## Recommended Posts

Hi.

I've been searching around, and found a few bits about this topic. I was looking mostly for events and component systems, but I don't feel the fact I use component over hierarchy makes a difference really.

My system is based off what I saw a while ago on here, where components are just methods and all the data is in the entity (as long as the naming is sensible, then there's no chance of duplicates) in properties.
Entity foo;foo.AddComponent<MovementComponent>("Movement").Init(20.f);foo.AddComponent<RenderComponent>("Render").Init(MESH, "foo.fbx");

And this would be equivalent to doing:
foo.AddProperty<float>("Speed", 20.f);foo.AddProperty<MeshModel>("MeshModel", /*mesh data*/);//And the components

And then the Update call iterates the entities, which iterate the child entities and components Updates.

However, I like that design and I'm not having an issue with it.
What I am thinking of is inter-entity communication (Intra-communication would just be component->owner.<do stuff>). I'm stuck between a signals/slots method, which seems to be overly complicated, and a standard message handling/event idea.

All entities inherit from EventListener, as do the major subsystems (graphics, audio) and the GUI.
If something interesting happens, then the entity would send a message to the global message pool. It would have the sender's ID (a uint), a type(string, such as TakeDamage or EntityCreated), and then an optional target as well as params.

Before update, probably in the input handling, the queue would send the events. If it had a target ID, then it would just send it to that. Else, it would be sent to everything. A 'targeted' message could be 'TakeDamage' and a global one could be 'EntityCreated'.
Then, the entities pass it to the components and subsystems and whatever else respond, probably with a switch.

I think this would work well, but the issue is for a lot of things, everything gets everything. I could sort it, but then it would be a lot of manual setting and registering of types.

Can anyone hand in some advice? It'd be much appreciated.
Thanks.

##### Share on other sites
"I think this would work well, but the issue is for a lot of things, everything gets everything. I could sort it, but then it would be a lot of manual setting and registering of types."

The way I'm dealing with that particular part of the entity-system problem is to have components which act as filters for messages.

I read a lot about the actor model while dreaming up my system. The way it's handled in that model is for an actor to filter and forward messages to other actors. I liked the flexibility of that, and came up with an idea like this.

1) Player causes explosion at (x,y,z)
2) EXPLODE(x,y,z) goes out to every entity who is registered, _BUT_, the only one who's registered is a "localizer" entity, who knows where all entities are located. His job is to forward a message to all the entities who are close to (x,y,z) in the form of NEARBY_EXPLOSION(x,y,z) Those entities can deal with the NEARBY_EXPLOSION message in any way they wish.

I should mention, that my component/entity system is 100% for fun, experimental pie-in-the-sky, and will probably be too slow to ever be used in production code. It's sometimes been called a "Flurry of Messages" system. Just wanted to disclose that in case you try to do something similar.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632995
• Total Posts
3009774
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!