0
\$\begingroup\$

I'm beginning to implement a simple scripting system into my networked server, and I've hit a snag. Before, I've been wrapping my calls into functions on objects that manipulate objects, but lately I've been finding this to be a pain for simple things. For example, if I set 'player.HP = 1'.. this works server-side. But the player side never sees this change unless I explicitly send a packet to inform the client.

For many things like map swapping that require more complicated changes, like change X, Y, Map and do this.. I have a function. That's fine. But what about these small properties I want to sync?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ It's fairly common to use a code generator and a DDL to automate the handling of replicated properties. The main code simply includes the generated file while the replication is handled by the net code built into what the code generator made for you. \$\endgroup\$ Commented Jun 30, 2012 at 22:24
  • \$\begingroup\$ Any examples, Patrick? I've not seen that in middleware or in free engines, nor the one I worked with commercially. \$\endgroup\$
    – Kylotan
    Commented Jul 1, 2012 at 18:10

1 Answer 1

0
\$\begingroup\$

if I set 'player.HP = 1'.. this works server-side. But the player side never sees this change unless I explicitly send a packet to inform the client.

So... explicitly send a packet to inform the client. Not from within the script, from the code that manages the property changes.

On a very basic level, you can send an update message whenever you change a property. Just make sure your property changing mechanism stores the changes, and send out those changes when appropriate.

Another way is to give these properties dirty flags. Set the flag when you change a property, and periodically you check all the properties to see if any are dirty. Copy the new values of the dirty properties into a message, send that message to the client, then clear the dirty flag.

\$\endgroup\$
2
  • \$\begingroup\$ I guess I should have been a little more clear... I'm trying to look for a little more automated way to do this without polluting the Player class with logic. And I really don't want to create a new packet for every single property. I thought of: Mark properties that need syncing with a 'Sync' attribute. Call perhaps a 'PropertyChanged' on all of them.. and write their underlying values. I guess that's not so bad, if the performance is right. Dirty flags is a lot of extra code. \$\endgroup\$ Commented Jun 30, 2012 at 18:58
  • \$\begingroup\$ This is an automated way, and doesn't have to alter the Player class except for wrapping the relevant properties. Nor does it require a new packet for each property - why would it? Your 'sync' approach doesn't sound much different from a dirty flag so I'm not sure what that gains. \$\endgroup\$
    – Kylotan
    Commented Jul 1, 2012 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .