예제 #1
0
        private void Update()
        {
            //Switch to new subspace if told to - this needs to be before the workerEnabled check as it fires during the initial sync
            if (newSetSubspace != -1)
            {
                DarkLog.Debug("Sent to subspace: " + newSetSubspace);
                timeSyncer.LockSubspace(newSetSubspace);
                newSetSubspace = -1;
            }

            if (!workerEnabled)
            {
                return;
            }

            //Reset warp if we need to
            CheckWarp();

            //Process new warp messages
            ProcessWarpMessages();

            //Write the screen message if needed
            if ((Client.realtimeSinceStartup - lastScreenMessageCheck) > SCREEN_MESSAGE_UPDATE_INTERVAL)
            {
                lastScreenMessageCheck = Client.realtimeSinceStartup;
                UpdateScreenMessage();
            }

            //Send a CHANGE_WARP message if needed
            if ((warpMode == WarpMode.MCW_FORCE) || (warpMode == WarpMode.MCW_VOTE) || (warpMode == WarpMode.SUBSPACE) || warpMode == WarpMode.SUBSPACE_SIMPLE)
            {
                if (!clientWarpList.ContainsKey(dmpSettings.playerName))
                {
                    clientWarpList[dmpSettings.playerName] = new PlayerWarpRate();
                }
                PlayerWarpRate ourRate = clientWarpList[dmpSettings.playerName];
                if ((ourRate.rateIndex != TimeWarp.CurrentRateIndex) || (ourRate.isPhysWarp != (TimeWarp.WarpMode == TimeWarp.Modes.LOW)))
                {
                    ourRate.isPhysWarp  = (TimeWarp.WarpMode == TimeWarp.Modes.LOW);
                    ourRate.rateIndex   = TimeWarp.CurrentRateIndex;
                    ourRate.serverClock = timeSyncer.GetServerClock();
                    ourRate.planetTime  = Planetarium.GetUniversalTime();
                    using (MessageWriter mw = new MessageWriter())
                    {
                        mw.Write <int>((int)WarpMessageType.CHANGE_WARP);
                        mw.Write <bool>(ourRate.isPhysWarp);
                        mw.Write <int>(ourRate.rateIndex);
                        mw.Write <long>(ourRate.serverClock);
                        mw.Write <double>(ourRate.planetTime);
                        networkWorker.SendWarpMessage(mw.GetMessageBytes());
                    }
                }
            }

            if ((Client.realtimeSinceStartup - lastWarpSet) > WARP_SET_THROTTLE)
            {
                //Follow the warp master into warp if needed (MCW_FORCE/MCW_VOTE)
                if (warpMode == WarpMode.MCW_FORCE || warpMode == WarpMode.MCW_VOTE)
                {
                    if ((warpMaster != "") && (warpMaster != dmpSettings.playerName))
                    {
                        if (clientWarpList.ContainsKey(warpMaster))
                        {
                            //Get master warp rate
                            PlayerWarpRate masterWarpRate = clientWarpList[warpMaster];
                            SetTimeFromWarpEntry(masterWarpRate);
                            lastWarpSet = Client.realtimeSinceStartup;
                        }
                        else
                        {
                            TimeWarp.SetRate(0, true);
                        }
                    }
                }

                if (warpMode == WarpMode.MCW_LOWEST)
                {
                    if ((warpMaster != "") && clientWarpList.ContainsKey(warpMaster))
                    {
                        //Get master warp rate
                        PlayerWarpRate masterWarpRate = clientWarpList[warpMaster];
                        SetTimeFromWarpEntry(masterWarpRate);
                        lastWarpSet = Client.realtimeSinceStartup;
                    }
                }
            }

            //Report our timeSyncer skew
            if ((Client.realtimeSinceStartup - lastReportRate) > REPORT_SKEW_RATE_INTERVAL && timeSyncer.locked)
            {
                lastReportRate = Client.realtimeSinceStartup;
                using (MessageWriter mw = new MessageWriter())
                {
                    mw.Write <int>((int)WarpMessageType.REPORT_RATE);
                    mw.Write <float>(timeSyncer.requestedRate);
                    networkWorker.SendWarpMessage(mw.GetMessageBytes());
                }
            }

            //Handle warp keys
            HandleInput();
        }
예제 #2
0
        private void DrawContent(int windowID)
        {
            GUILayout.BeginVertical();
            GUI.DragWindow(moveRect);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUIStyle chatButtonStyle = buttonStyle;

            if (chatWorker.chatButtonHighlighted)
            {
                chatButtonStyle = highlightStyle;
            }
            chatWorker.display         = GUILayout.Toggle(chatWorker.display, "Chat", chatButtonStyle);
            craftLibraryWorker.display = GUILayout.Toggle(craftLibraryWorker.display, "Craft", buttonStyle);
            groupsWindow.display       = GUILayout.Toggle(groupsWindow.display, "Group", buttonStyle);
            permissionsWindow.display  = GUILayout.Toggle(permissionsWindow.display, "Permissions", buttonStyle);
            GUIStyle screenshotButtonStyle = buttonStyle;

            if (screenshotWorker.screenshotButtonHighlighted)
            {
                screenshotButtonStyle = highlightStyle;
            }
            screenshotWorker.display = GUILayout.Toggle(screenshotWorker.display, "Screenshot", screenshotButtonStyle);
            if (GUILayout.Button("-", buttonStyle))
            {
                minmized        = true;
                minWindowRect.x = windowRect.xMax - minWindowRect.width;
                minWindowRect.y = windowRect.y;
            }
            GUILayout.EndHorizontal();
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, scrollStyle);
            //Draw subspaces
            double ourTime     = timeSyncer.locked ? timeSyncer.GetUniverseTime() : Planetarium.GetUniversalTime();
            long   serverClock = timeSyncer.GetServerClock();

            foreach (SubspaceDisplayEntry currentEntry in subspaceDisplay)
            {
                double currentTime = 0;
                double diffTime    = 0;
                string diffState   = "Unknown";
                if (!currentEntry.isUs)
                {
                    if (!currentEntry.isWarping)
                    {
                        //Subspace entry
                        if (currentEntry.subspaceEntry != null)
                        {
                            long   serverClockDiff = serverClock - currentEntry.subspaceEntry.serverClock;
                            double secondsDiff     = serverClockDiff / 10000000d;
                            currentTime = currentEntry.subspaceEntry.planetTime + (currentEntry.subspaceEntry.subspaceSpeed * secondsDiff);
                            diffTime    = currentTime - ourTime;
                            diffState   = (diffTime > 0) ? SecondsToVeryShortString((int)diffTime) + " in the future" : SecondsToVeryShortString(-(int)diffTime) + " in the past";
                        }
                    }
                    else
                    {
                        //Warp entry
                        if (currentEntry.warpingEntry != null)
                        {
                            float[] warpRates = TimeWarp.fetch.warpRates;
                            if (currentEntry.warpingEntry.isPhysWarp)
                            {
                                warpRates = TimeWarp.fetch.physicsWarpRates;
                            }
                            long   serverClockDiff = serverClock - currentEntry.warpingEntry.serverClock;
                            double secondsDiff     = serverClockDiff / 10000000d;
                            currentTime = currentEntry.warpingEntry.planetTime + (warpRates[currentEntry.warpingEntry.rateIndex] * secondsDiff);
                            diffTime    = currentTime - ourTime;
                            diffState   = (diffTime > 0) ? SecondsToVeryShortString((int)diffTime) + " in the future" : SecondsToVeryShortString(-(int)diffTime) + " in the past";
                        }
                    }
                }
                else
                {
                    currentTime = ourTime;
                    diffState   = "NOW";
                }

                //Draw the subspace black bar.
                GUILayout.BeginHorizontal(subspaceStyle);
                GUILayout.Label("T+ " + SecondsToShortString((int)currentTime) + " - " + diffState);
                GUILayout.FlexibleSpace();
                //Draw the sync button if needed
#if !DEBUG
                if ((warpWorker.warpMode == WarpMode.SUBSPACE) && !currentEntry.isUs && !currentEntry.isWarping && (currentEntry.subspaceEntry != null) && (diffTime > 0))
#else
                if ((warpWorker.warpMode == WarpMode.SUBSPACE) && !currentEntry.isUs && !currentEntry.isWarping && (currentEntry.subspaceEntry != null))
#endif
                {
                    if (GUILayout.Button("Sync", buttonStyle))
                    {
                        timeSyncer.LockSubspace(currentEntry.subspaceID);
                    }
                }
                GUILayout.EndHorizontal();

                foreach (string currentPlayer in currentEntry.players)
                {
                    if (currentPlayer == dmpSettings.playerName)
                    {
                        DrawPlayerEntry(playerStatusWorker.myPlayerStatus, playerColorWorker.GetPlayerColor(currentPlayer));
                    }
                    else
                    {
                        DrawPlayerEntry(playerStatusWorker.GetPlayerStatus(currentPlayer), playerColorWorker.GetPlayerColor(currentPlayer));
                    }
                }
            }
            if (DateTime.Now.Day == 1 && DateTime.Now.Month == 4)
            {
                PlayerStatus easterEgg = new PlayerStatus();
                easterEgg.playerName = "Princess Luna";
                easterEgg.statusText = "Stranded on the Mün";
                easterEgg.vesselText = "";
                DrawPlayerEntry(easterEgg, new Color(0.251f, 0.275f, 0.502f));
            }
            GUILayout.EndScrollView();
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Disconnect", buttonStyle))
            {
                disconnectEventHandled = false;
            }
            optionsWindow.display = GUILayout.Toggle(optionsWindow.display, "Options", buttonStyle);
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }