xember icon indicating copy to clipboard operation
xember copied to clipboard

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

Open alecmce opened this issue 13 years ago • 2 comments

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!

alecmce avatar Oct 24 '11 02:10 alecmce

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.

hyakugei avatar Nov 10 '11 17:11 hyakugei

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!

alecmce avatar Nov 10 '11 19:11 alecmce