I'm working on a server-based multiplayer game written in C#. The server and the client shares code and each object has the same int ID
. I want to make the networking to be light as possible, by sending only the changed data.
The game has classes, which have numerous fields/properties, and they often change. I'm seeking a way to detect when these values change and send these values to the client side.
Basically, this algorithm:
- Flag object when it's changed
- With the changed objects at network Tick:
- Compare each property with their previous state
- Send only the changed values
- Store old values
- Receive them on the client side
- Instantiate the same type of object, or find it by ID
- Set the new values
Of course, .NET Reflection may be eable to solve this problem, but iterating throuh 1000 object and their properties in each Tick, would be a bottleneck in performance.
I can send the basic types (int, float, vector), and maintain connection. My questions are these:
What's the best approach to send an object's Class
and instantiate it?
How should I detect property change and how to serialise properties so I can find their "pair" on the client when receiving.