DoubleDeez / MDFramework

A multiplayer C# game framework for Godot 3.4 Mono.
https://discord.gg/UH49eHK
MIT License
77 stars 13 forks source link

Suggestion: Parameters for MDReplicated #22

Closed Beider closed 4 years ago

Beider commented 4 years ago

So there are a few things that we want and maybe want to add to MDReplicated, and there will probably be more in the future.

My suggestion to solve all of these is that instead of adding more attributes to [MDReplicated] we instead just add a parameter array.

public MDReplicated(MDReliability InReliability = MDReliability.Reliable, 
                    MDReplicatedType RepType = MDReplicatedType.OnChange, params object[] parameters)

Then we could add flags in the form of a parameter enum to MDReplicatedMember and all inheriting classes, which would look something like

public enum Parameters
{
    OnChangeListener,
    ProcessWhilePaused
}

Then people can just pass in stuff as parameters pairs,

[MDReplicated(MDReliability.Unreliable, MDReplicatedType.Interval, 
         MDReplicatedMember.Parameters.OnChangeListener,  (Action<object>)OnPositionChanged,
         MDCRMInterpolatedVector2.Parameters.Prediction, false)]

// Alternative version
[MDReplicatedSetting(MDReplicatedMember.Parameters.OnChangeListener,  (Action<object>)OnPositionChanged)]
[MDReplicatedSetting(MDCRMInterpolatedVector2.Parameters.Prediction, false)]

We then just process the parameters we know about and pass the parameters up the inheritance tree after we processed our own. I think the good thing about something like this is that it would allow each custom implementation to pick up their own parameters. We could even introduce some in the MDReplicator itself if we need (maybe pause processing goes there).

The downside is that this is less explicit, upside would be very easy to extend with new options. Also I feel like most of the options here are very custom options that you don't need to know about just to use the framework.

Another thing we could in theory do if we introduce this on the MDReplicator as well is to allow people to pass their custom MDReplicatedMember as a parameter instead of having to overwrite the MDReplicator itself.

I have made another suggestion here that could need something like this.

Beider commented 4 years ago

So after thinking about this more I think the alternative version of introducing a new attribute called something like MDReplicatedSetting would be the best approach for this. Then we would just collect these when a new replicated property is created and pass them to the MDReplicatedMember when it is constructed.

Beider commented 4 years ago

Parameters have now been added, for now the following parameters are in.

// Group for replicator to group by in case of interval (default: auto)
[MDReplicatedSetting(MDReplicator.Settings.GroupName, "PlayerPositions")]
// Process while paused (default: true)
[MDReplicatedSetting(MDReplicator.Settings.ProcessWhilePaused, false)]
// Allows to override the type of MDReplicatedMember we use, could be used to disable interpolation or for custom types
[MDReplicatedSetting(MDReplicator.Settings.ReplicatedMemberType, nameof(MDReplicatedMember))]
// A callback for whenever values are changed on remote clients (will not trigger on local client, only for clocked values)
[MDReplicatedSetting(MDClockedReplicatedMember.Settings.OnValueChangedEvent, nameof(OnPositionChanged))]

I intend to write full documentation with examples for this in the wiki before i create a pull request.