Closed Beider closed 4 years ago
After more consideration it might be possible to do all this with attributes.
First a new type of [MDReplicatedType] should be added.
Modify [MDReplicated] to contain three new settings
Then add another attribute [MDReplicationGroup] that is allowed multiple times on class level.
If a group is active it overrides any settings on all group members. The only exception is precision which is not part of the group as I think this should be a per member setting.
I think with this it would be possible to figure out everything else inside the replicator, at the very least I would be very much in favour of Precision being added for floats, doubles and vectors.
The biggest challenge I see here is figuring out how to send this data without too much overhead. As sending the nodepath with every group would defeat the entire point of trying to reduce overhead. As such perhaps there needs to be some sort of group registry managed by the server where groups are added and given a sequential ID number when a node that uses a group is greated, then this group ID is distributed to all clients with the info of which node it belongs to.
I'm wondering if Precision could be accomplished by creating a custom type instead and replicating that. eg. a float16
type, not sure how Godot would handle that in a Rset
call though, might have to be stored as a ushort or something.
The only problem I see with a custom type is you are unable to decide the precision level in that case, unless you want to add one type for every precision level up until a set point. In addition this setting could apply to Vector2, Vector3, Float, Decimal and Double.
Even though one could argue Decimal and Double may not be neeeded.
Yeah I meant one type for every set precision: float8
, float16
, Vector2_8
, Vector2_16
, etc
Either way, for the framework I want it to be built on top of Godot's Rpc/Rset (high level networking) system rather than replacing it which I think will limit us from setting a tunable precision which is why I recommend type-based precision. That will depend on Godot's ability to handle custom types which I haven't tested yet.
Closing this as this issue has been solved in scope of other issues. It was simply forgotten about and not closed.
This is another thing I plan on adding eventually but will mention here in case someone else want to do it or have a better idea.
As it currently stands the [MDReplicated] property is great when you want to just synchronize properties that are not changed often. Or a single property that is changed often.
However in cases for things like a player where a lot of data might be sent at regular intervals (say 10 times a second or so). Having one MDReplicated member for each value is highly inefficient as such I would like to suggest a new class that allows for compression of multiple values easily.
My initial idea for this was to simpl add something like MDNetworkCompressor then have functions like: AddString(int key, MemberInfo member) AddVector2(int key, MemberInfo member, int precision) AddFloat(int key, MemberInfo member, int precision) GetNetworkString() SetNetworkString(String value) GetFloatValue(int key) etc..
Then the user would simply instance this class, add all their values to it with the compression level they want and finally introduce a MDReplicated string property where they just update with the GetNetworkString and then do SetNetworkString in the setter for this property.
However after looking at the code I think it might be possible to do this automatically, but I am not so sure. Adding a class that can do something like this would probably offer more control as it could be hard for the Replicator to know how often each replicated property is changed. The precision could be easily extended into the [MDReplicated] attribute.
Anyway this was just a passing idea I had that I know I will have to do at some point in the future. This is in no way urgent for my game so I probably won't put any work into this for quite a while. I just wanted to suggest this here to start a discussion on how this could be done.