Code Monkey home page Code Monkey logo

Comments (8)

Beider avatar Beider commented on August 15, 2024 1

I don't think there is any point in exposing NodeSynchCompleted in the framework itself as the event mentioned above pretty much gives you that information. Of course if you really want it I would suggest just overriding the MDGameSynchronizer and exposing it.

from mdframework.

Beider avatar Beider commented on August 15, 2024
  1. Did you check the MDStatics class? It has a few methods such as MDStatics.IsNetworkActive(), MDStatics.IsServer() and MDStatics.IsClient(). Documenation is a bit lacking at the moment. I do plan on making some video tutorials and writing some guides in the wiki once the framework is in a bit more of a complete state.

  2. I agree with this one, in theory you could use MDGameSession.GetAllPlayerInfos() and do a count on that, but exposing player count directly would be better.

  3. I agree with this as well, I think we should just swap the order of the MDPlayerInfo being removed and the event being sent out. It would make a lot more sense to send out the event while the player info still exists.

  4. Probably also worth adding.

I would wait to see what @DoubleDeez says about this, but I would think you could just make those three changes on your fork and just create a pull request.

from mdframework.

DoubleDeez avatar DoubleDeez commented on August 15, 2024
  1. The helpers Beider mentioned are probably what you want. As for the synch'd event, there's OnSynchCompleteEvent on MDGameSynchronize. We do need to improve our documentation so these are easier to find.
    public delegate void SynchCompleteHandler(float ResumeGameIn);
    public event SynchCompleteHandler OnSynchCompleteEvent = delegate {};
  2. Yup, I agree we should add this.
  3. I can't think of any reason to remove the object before sending the event so yeah I think we should just swap the order
 private void OnPlayerLeft_Internal(int PeerId) 
 {
     OnPlayerLeftEvent(PeerId);
     RemovePlayerObject(PeerId);
 } 
  1. That's a good idea. There's probably other settings we should be exposing too, but instead of having to add a bunch of parameters I wonder if we should have a virtual void ConfigurePeer(peer); function or something along those lines.

and yeah, if you can, please create a pull request with these changes, otherwise we'll get to it when we have the time.

from mdframework.

Meister1593 avatar Meister1593 commented on August 15, 2024

Ok i will make pull request, but:

  1. The helpers Beider mentioned are probably what you want. As for the synch'd event, there's OnSynchCompleteEvent on MDGameSynchronize. We do need to improve our documentation so these are easier to find.
    public delegate void SynchCompleteHandler(float ResumeGameIn);
    public event SynchCompleteHandler OnSynchCompleteEvent = delegate {};

This does work, but this triggers every time synch is happening, for every player every time someone joins.

  1. Did you check the MDStatics class? It has a few methods such as MDStatics.IsNetworkActive(), MDStatics.IsServer() and MDStatics.IsClient(). Documenation is a bit lacking at the moment. I do plan on making some video tutorials and writing some guides in the wiki once the framework is in a bit more of a complete state.

MDStatics.IsNetworkActive() seems only count that we're connected but isn't synched yet. For event this needs custom logic, i've used this to actually know if i'm synched or not and exposed this to my GameSynchronizer.

protected bool NodeSynchCompleted = false;

I'm planning to expose this var and make event that happends inside OnSynchCompleteEvent. Not sure if that's right to do nested events.

from mdframework.

Beider avatar Beider commented on August 15, 2024

Alright so if I get you right you want an event that tells you the first time a player has finished synching? Should this be on master, the joining player or all players?

I would suggest adding a completely new event called something like OnPlayerSynchComplete(int PeerId)

The best place to add this is probably to this method in the game synchronizer,

[Puppet]
protected void UpdateSynchStatus(int PeerId, float SynchStatus)
{
    OnPlayerSynchStatusUpdateEvent(PeerId, SynchStatus);
}

Just change OnPlayerSynchStatusUpdateEvent(Multiplayer.GetRpcSenderId(), 1f); in ClientSynchDone() so it also calls UpdateSynchStatus(...)

Then just check if the synch status is 1f, which means it is done, in which case you can send the event. You would probably have to introduce another list like the ClientSynchList, something like InitialSychDoneList to track so it only happens the first time. And remove them from the synch list if they leave.

Other alternative would be simply to subscribe to the OnPlayerSynchStatusUpdateEvent somewhere in your own code, then check when it is 1f and send your event there. Then you would also have to track which peers this event has been sent for already but would be the best solution if you don't want to change the framework.

from mdframework.

Meister1593 avatar Meister1593 commented on August 15, 2024

Alright so if I get you right you want an event that tells you the first time a player has finished synching? Should this be on master, the joining player or all players?

This event should be invoked on player who joins to server, only one time when he finished connection and finished synching.

from mdframework.

Beider avatar Beider commented on August 15, 2024

The easiest way to do this without changing the framework would be for you to subscribe to the OnPlayerSynchStatusUpdateEvent

Then just do something like this

protected bool AlreadySynched = false;
    protected void SynchStatusUpdate(int PeerId, float ProgressPercentage)
    {
        if (AlreadySynched)
        {
            return;
        }

        // Float compares are annoying
        if (PeerId == MDStatics.GetPeerId() && ProgressPercentage >= 0.99f)
        {
            // Do your stuff here
            AlreadySynched = true;
        }
    }

Edit: I added this example to the wiki page for the Game Synchronizer.

from mdframework.

Meister1593 avatar Meister1593 commented on August 15, 2024

The easiest way to do this without changing the framework would be for you to subscribe to the OnPlayerSynchStatusUpdateEvent

Then just do something like this

protected bool AlreadySynched = false;
    protected void SynchStatusUpdate(int PeerId, float ProgressPercentage)
    {
        if (AlreadySynched)
        {
            return;
        }

        // Float compares are annoying
        if (PeerId == MDStatics.GetPeerId() && ProgressPercentage >= 0.99f)
        {
            // Do your stuff here
            AlreadySynched = true;
        }
    }

This is actually nice, i might just use that for my event.
Is that good idea to make NodeSynchCompleted exposed in case user needs to know or it is not?

from mdframework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.