alecmce / xember

A riff on the Ember entity system
MIT License
48 stars 7 forks source link

If two entities reference the same component, then when encoded and decoded identity must be preserved #14

Open alecmce opened 12 years ago

alecmce commented 12 years ago

In a scenario where entity A and B share a component World:

world = new World(); entityA.addComponent(world); entityB.addComponent(world);

then you encode

encodedA = encoder.encode(entityA); encodedB = encoder.encode(entityB);

then you decode

entityA = decoder.decode(encodedA); entityB = decoder.decode(encodedB);

unfortunately

trace(entityA.getComponent(World) == entityB.getComponent(World)) // outputs false

boo!

hyakugei commented 12 years ago

Is there a possibility of using RL/DI "like" tools here? Ie. a map for where World is being used? So, when decoding an encoded entity, you check each of its components for matches to existing rules/maps, and use an existing instance, or create and cache it.

That sounds pretty complex.

alecmce commented 12 years ago

My plan is to create an ID for each entity and component, then to separate encoding into two parts: 1. encode the components under their IDs into a hash and 2. encode the entity-component relationships into a separate hash.

I just haven't had the time to work on XEmber for a while as I've just started a new job and because I am commuting by car. Once my job settles down a bit and I start commuting by train, I'll have more time to invest in this!