Ejemplo n.º 1
0
 public MDReplicatorNetworkKeyIdMap(bool ShowBufferSize)
 {
     if (ShowBufferSize)
     {
         MDOnScreenDebug.AddOnScreenDebugInfo(DEBUG_CAT, "NetworkIDToKeyMap Buffer Size", () => ClockedValueBuffer.Count.ToString());
     }
 }
Ejemplo n.º 2
0
        public override void _Ready()
        {
            MDStatics.GI = this;

            // Configuration first
            CreateConfiguration();

            // Init static classes first
            MDLog.Initialize(GetLogDirectory());
            MDArguments.PopulateArgs();
            MDProfiler.Initialize();
            MDOnScreenDebug.Initialize();

            // Hook up events
            GetTree().Connect("node_added", this, nameof(OnNodeAdded_Internal));
            GetTree().Connect("node_removed", this, nameof(OnNodeRemoved_Internal));

            // Init instances
            CreateGameSession();
            CreateGameSynchronizer();
            CreateReplicator();
            CreateInterfaceManager();

            RegisterNodeAndChildren(GetTree().Root);
        }
Ejemplo n.º 3
0
 private void OnOnScreenDebugClosed(MDScreen Screen)
 {
     if (OnScreenDebug == Screen)
     {
         OnScreenDebug.OnScreenClosed -= OnOnScreenDebugClosed;
         OnScreenDebug = null;
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Cleanup
 /// </summary>
 public void Dispose()
 {
     MDOnScreenDebug.RemoveOnScreenDebugInfo($"Ping({PeerId})");
     if (Godot.Object.IsInstanceValid(PingTimer))
     {
         PingTimer.Stop();
         PingTimer.RemoveAndFree();
     }
 }
Ejemplo n.º 5
0
 private void ToggleOnScreenDebug()
 {
     if (OnScreenDebug == null)
     {
         OnScreenDebug = OpenScreen <MDOnScreenDebug>(OnScreenDebugName, MDScreenLayer.Debug);
         OnScreenDebug.OnScreenClosed += OnOnScreenDebugClosed;
     }
     else
     {
         OnScreenDebug.CloseScreen();
     }
 }
Ejemplo n.º 6
0
        ///<summary>Starts the player ping request cycle</summary>
        private void StartClientPingCycle()
        {
            if (!GameSynchronizer.IsActivePingEnabled())
            {
                return;
            }

            // Onscreen debug for ping
            MDOnScreenDebug.AddOnScreenDebugInfo(DEBUG_CAT, $"Ping({PeerId})", () => MDStatics.GetGameSynchronizer().GetPlayerPing(PeerId).ToString());

            PingTimer = GameSynchronizer.CreateUnpausableTimer($"PingTimer{PeerId}", false, GameSynchronizer.GetPingInterval(),
                                                               false, GameSynchronizer, MDGameSynchronizer.METHOD_ON_PING_TIMER_TIMEOUT, PeerId);
            PingTimer.Start();
        }
Ejemplo n.º 7
0
        public void Initialize()
        {
            MDLog.AddLogCategoryProperties(LOG_CAT, new MDLogProperties(MDLogLevel.Info));
            MDOnScreenDebug.AddOnScreenDebugInfo("KeyToMemberMap Size", () => KeyToMemberMap.Count.ToString());
            MDOnScreenDebug.AddOnScreenDebugInfo("NetworkIDToKeyMap Size", () => NetworkIdKeyMap.GetCount().ToString());
            this.GetGameSession().OnSessionEndedEvent += OnSessionEnded;
            this.GetGameSession().OnPlayerJoinedEvent += OnPlayerJoined;
            PauseMode   = PauseModeEnum.Process;
            RpcSenderId = -1;

            GroupManager    = new MDReplicatorGroupManager(GetReplicationFrameInterval());
            NetworkIdKeyMap = new MDReplicatorNetworkKeyIdMap(ShouldShowBufferSize());

            GameClock = this.GetGameClock();
        }
Ejemplo n.º 8
0
        private void OnSessionStartedEvent()
        {
            if (this.IsClient())
            {
                // Add max ping information between this client and any other client
                // Roundtrip is: client 1 -> server -> client 2 -> server -> client 1.
                // TODO: Max ping should be not identical for each player we ping
                MDOnScreenDebug.AddOnScreenDebugInfo(DEBUG_CAT, "MaxRoundtripPing: ", () => MaxPing.ToString());
                PauseGame();
                SynchronizationState = SynchronizationStates.SYNCHRONIZING_IN_PROGRESS;
            }
            else
            {
                SynchronizationState = SynchronizationStates.SYNCRHONIZED;
            }

            // Reset to tick 0 at start of session
            GameClock?.SetCurrentTick(0);
        }
Ejemplo n.º 9
0
        // Called when the node enters the scene tree for the first time.
        public override void _Ready()
        {
            MDLog.AddLogCategoryProperties(LOG_CAT, new MDLogProperties(MDLogLevel.Info));
            LoadConfig();
            GameSynchronizer                           = this.GetGameSynchronizer();
            CurrentRemoteTickOffset                    = MinimumOffset;
            CurrentRemoteTickOffsetTarget              = MinimumOffset;
            LastRemoteTickOffset                       = MinimumOffset;
            GameSynchronizer.OnPlayerPingUpdatedEvent += OnPlayerPingUpdatedEvent;

            // TODO: Remove this, only here for debug
            MDOnScreenDebug.AddOnScreenDebugInfo("GameClock Current Tick", () => CurrentTick.ToString());
            MDOnScreenDebug.AddOnScreenDebugInfo("OS GetTickMsec", () => OS.GetTicksMsec().ToString());
            MDOnScreenDebug.AddOnScreenDebugInfo("GameClock Remote Offset",
                                                 () =>
                                                 $"{CurrentRemoteTickOffset} ({(int) (CurrentRemoteTickOffset * TICK_INTERVAL_MILLISECONDS)} Msec)");
            MDOnScreenDebug.AddOnScreenDebugInfo("GameClock Remote Target Offset",
                                                 () =>
                                                 $"{CurrentRemoteTickOffsetTarget} ({(int) (CurrentRemoteTickOffsetTarget * TICK_INTERVAL_MILLISECONDS)} Msec)");
        }