Note that there are some explanatory texts on larger screens.

plurals
  1. POSynchronizing arbitrary properties in an object transparently in D
    primarykey
    data
    text
    <p>Let's say I have a class like so:</p> <pre><code>class Gerbil{ int id; float x,y,z; } </code></pre> <p>Let's further say this is part of a real-time simulation where I have a server/client setup and I change a property on the server-side:</p> <pre><code>//... gerbil.x = 9.0; //... </code></pre> <p>Now I want to send over this change to the client to synchronize the world state. However, the problem is I have potentially vast amounts of gerbils, and these gerbils also potentially have long lists of properties—not just x,y,z as depicted here. </p> <p>My question is: <strong>Is there a way we can intercept these property assignments, transparently, and compile a diff from them?</strong></p> <p>From reading the D reference I got the impression <code>opAssign</code> might be the right thing, only there's actually no examples of how to use it? (<a href="http://www.digitalmars.com/d/2.0/operatoroverloading.html#Assignment" rel="nofollow">D Ref. / opAssign</a>) I suppose it would look something like this, but I'm just shooting from the hip:</p> <pre><code>void opAssign(string name)(float val){ //Just guessing here if(name in floatProps){ if(isServer){ changedProps.push(this.id, name, val); } floatProps[name] = val; } } </code></pre> <p>And then opAssign would be called when we do:</p> <pre><code>gerbil.x = 9.0; //Same as gerbil.opAssign!("x")(9.0) ?? </code></pre> <p>Apart from possibly wrong syntax, is this a step in the right direction? What is the right syntax? What about performance? It looks like it could be quite slow? Is there a faster, more "direct" way of this?</p> <p>What I'd really like to avoid here are elaborate setups like:</p> <pre><code>gerbil.incProp(Prop.X, 9.0); </code></pre> <p>Thanks for your time.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload