コード例 #1
0
ファイル: Menu.cs プロジェクト: JordanFisher/WAL
 public void RequestUnpause()
 {
     Networking.ToServer(new Message(MessageType.RequestUnpause));
 }
コード例 #2
0
        public void Draw()
        {
            ProcessInbox();

            DrawCount++;
            Render.StandardRenderSetup();

            double PreviousSecondsSinceLastUpdate = SecondsSinceLastUpdate;

            if (!DesyncPause)
            {
                CheckIfShouldPause();
                CheckIfShouldShowWaiting();
            }

            if (GameClass.GameActive && !ServerPaused && !DesyncPause)
            {
                if (NotPaused_SimulationUpdate)
                {
                    double Elapsed = GameClass.DeltaT; //GameClass.ElapsedSeconds;

                    if (SimStep + SecondsSinceLastUpdate / DelayBetweenUpdates < ServerSimStep - .25f)
                    {
                        Elapsed *= 1.15f;
                        if (Log.SpeedMods)
                        {
                            Console.WriteLine("            -- Speed up please, Elasped = {3}  # {0}/{1} :{2}", Elapsed, SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }
                    }

                    SecondsSinceLastUpdate += Elapsed;
                    T += (float)Elapsed;
                }
                else
                {
                    DataGroup.PausedSimulationUpdate();

                    if (MapEditorActive)
                    {
                        SecondsSinceLastUpdate += DelayBetweenUpdates;
                        T += (float)DelayBetweenUpdates;
                    }
                }

                if (GameClass.HasFocus)
                {
                    switch (CurUserMode)
                    {
                    case UserMode.PlaceBuilding:
                        if (UnselectAll)
                        {
                            SelectionUpdate(SelectSize);
                            UnselectAll = false;
                        }

                        Update_BuildingPlacing();
                        break;

                    case UserMode.Painting:
                        if (UnselectAll || MapEditorActive)
                        {
                            SelectionUpdate(SelectSize);
                            UnselectAll = false;
                        }

                        Update_Painting();
                        break;

                    case UserMode.Select:
                        SelectionUpdate(SelectSize, LineSelect: LineSelect);
                        break;

                    case UserMode.CastSpell:
                        if (LeftMousePressed && MyPlayerInfo != null)
                        {
                            if (!MyPlayerInfo.DragonLordAlive)
                            {
                                Message_NoDragonLordMagic();
                            }
                            else if (MyPlayerInfo.CanAffordSpell(CurSpell))
                            {
                                CastSpell(CurSpell);
                            }
                            else
                            {
                                Message_InsufficientJade();
                            }
                        }

                        break;
                    }
                }

                SkipNextSelectionUpdate = false;

                if (Program.Server)
                {
                    if (SecondsSinceLastUpdate / DelayBetweenUpdates > .75f && SimStep == ServerSimStep && !SentBookend)
                    {
                        if (Log.UpdateSim)
                        {
                            Console.WriteLine("Ready for bookend. {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }

                        SentBookend = true;

                        AckSimStep = ServerSimStep + 2;
                        Networking.ToClients(new MessageBookend(ServerSimStep + 1));
                    }
                }

                // Check if post-upate calculation still need to be done
                if (!PostUpdateFinished)
                {
                    PostSimulationUpdate();
                }

                // Check if we need to do a simulation update
                //if (true)
                //Console.WriteLine(ServerSimStep);
                if (GameClass.UnlimitedSpeed || SecondsSinceLastUpdate > DelayBetweenUpdates || SimStep + 2 < ServerSimStep)
                {
                    if (SimStep < ServerSimStep && !(Program.Server && MinClientSimStep + 2 < ServerSimStep))
                    {
                        WaitingTime = 0;

                        if (!PostUpdateFinished)
                        {
                            PostSimulationUpdate(); // If we are behind do another post-sim update to help catchup.
                        }
                        else
                        {
                            SecondsSinceLastUpdate -= DelayBetweenUpdates;
                            if (SecondsSinceLastUpdate < 0)
                            {
                                SecondsSinceLastUpdate = 0;
                            }

                            HashCheck();

                            DeququeActions(SimStep + 1);

                            HashCheck();

                            SimulationUpdate();

                            if (!Program.Spectate || Program.Spectate && SimStep % 15 == 0)
                            {
                                HashCheck(Send: true);
                            }

                            SentBookend = false;
                            Networking.ToServer(new MessageStartingStep(SimStep));

                            if (Log.UpdateSim)
                            {
                                Console.WriteLine("Just updated sim # {0}/{1} : {2}      min={3}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates, MinClientSimStep);
                            }
                        }
                    }
                    else
                    {
                        WaitingTime += GameClass.ElapsedSeconds;

                        if (Log.Delays)
                        {
                            Console.WriteLine("-Reverting from # {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }
                        SecondsSinceLastUpdate = DelayBetweenUpdates;
                        T -= (float)GameClass.ElapsedSeconds;
                        if (Log.Delays)
                        {
                            Console.WriteLine("-Reverting to # {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }
                    }
                }
                else
                {
                    if (Program.Server)
                    {
                        if (Log.Draws)
                        {
                            Console.WriteLine("Draw step {0},  {1}", DrawCount, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }
                    }
                }
            }

            BenchmarkTests.Run(DataGroup.CurrentData, DataGroup.PreviousData);

            if (!Program.Headless)
            {
                try
                {
                    DrawWorld();
                }
                catch (Exception e)
                {
                }
            }
            else
            {
                GridHelper.GraphicsDevice.SetRenderTarget(null);
            }
        }
コード例 #3
0
        public void SelectionUpdate(vec2 Size, bool EffectSelection = true, bool LineSelect = true)
        {
            if (!GameClass.HasFocus)
            {
                return;
            }
            if (SkipNextSelectionUpdate)
            {
                return;
            }

            vec2 WorldCoord     = ScreenToWorldCoord(Input.CurMousePos);
            vec2 WorldCoordPrev = ScreenToWorldCoord(Input.PrevMousePos);

            bool Deselect =
                (LineSelect && LeftMouseDown || !LineSelect && Input.LeftMouseReleased) &&
                !Keys.LeftShift.Down() && !Keys.RightShift.Down() ||
                CurUserMode != UserMode.Select ||
                Keys.Back.Down() || Keys.Escape.Down();
            bool Selecting =
                (LineSelect && LeftMouseDown || !LineSelect && Input.LeftMouseReleased) &&
                (CurUserMode == UserMode.Select || CurUserMode == UserMode.CastSpell || CurUserMode == UserMode.Painting);

            if (SkipDeselect)
            {
                Deselect     = false;
                SkipDeselect = false;
            }

            if (SkipSelect)
            {
                Selecting = false;
                if (CurUserMode != UserMode.Select || !LeftMouseDown)
                {
                    SkipSelect = false;
                }
            }

            if (LineSelect)
            {
                bool DoSelect = false;
                if (MapEditorActive && CurUserMode == UserMode.Painting)
                {
                    // Continuous selection
                    DoSelect = LeftMouseDown && Selecting && EffectSelection;
                }
                else
                {
                    // Discrete selection
                    DoSelect = LeftMousePressed && Selecting && EffectSelection;
                }

                if (DoSelect)
                {
                    Networking.ToServer(new MessageSelectAlongLine(Size, Deselect, WorldCoord, WorldCoordPrev));
                }
            }
            else
            {
                if (Selecting && EffectSelection && BoxSelecting)
                {
                    BoxSelecting = false;
                    vec2 bl = floor(min(BoxSelectGridStart, BoxSelectGridEnd) - vec(1f, 1f));
                    vec2 tr = ceiling(max(BoxSelectGridStart, BoxSelectGridEnd));

                    Networking.ToServer(new MessageSelectInBox(Deselect, bl, tr));
                }
            }

            if (MapEditorActive && !GameClass.Game.ShowChat)
            {
                if (Keys.D5.Pressed())
                {
                    FinalizeGeodesics();
                }

                if (Keys.OemOpenBrackets.Pressed())
                {
                    MakeMapSymmetric(SymmetryType.Octo, true);
                }

                if (Keys.O.Pressed())
                {
                    MakeMapSymmetric(SymmetryType.Quad, false);
                }

                if (Keys.Delete.Down() || Keys.Back.Down())
                {
                    DeleteUnits();
                }
            }

            if (CurUserMode != UserMode.Select)
            {
                return;
            }

            if (NotPaused_UnitOrders)
            {
                if (Input.RightMousePressed)
                {
                    AttackMove();
                }

                if (Deselect)
                {
                    CurSelectionFilter = SelectionFilter.All;
                }

                if (Keys.Tab.Pressed())
                {
                    // Cycle through and find the next selection filter that results in something different than the current filter.
                    // Skip filters that result in nothing selected.
                    // Keep the same filter if no other valid filter can be found.
                    float  PrevSelectionFilter     = CurSelectionFilter;
                    bool[] PreviousFilteredSummary = FilteredSummary(PrevSelectionFilter);

                    do
                    {
                        ChangeSelectionFilter();
                    }while ((PreviousFilteredSummary.SequenceEqual(FilteredSummary(CurSelectionFilter)) || !FilteredSummary(CurSelectionFilter).Contains(true)) &&
                            CurSelectionFilter != PrevSelectionFilter);
                }
            }
        }
コード例 #4
0
        public void ProcessInbox()
        {
            Message message;

            while (Networking.Inbox.TryDequeue(out message))
            {
                if (Log.Processing)
                {
                    Console.WriteLine("  -In Game Processing {0}", message);
                }

                if (Program.Server)
                {
                    if (message.Type == MessageType.PlayerAction)
                    {
                        var ack = new MessagePlayerActionAck(AckSimStep, message);

                        var chat = message.Innermost as MessageChat;
                        if (null != chat)
                        {
                            if (chat.Global)
                            {
                                Networking.ToClients(ack);
                            }
                            else
                            {
                                var chat_team = message.Source.Team;
                                if (chat_team < 0)
                                {
                                    continue;
                                }

                                foreach (var client in Server.Clients)
                                {
                                    if (client.Team == chat_team)
                                    {
                                        Networking.ToClient(client, ack);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (message.Source.Index > 4)
                            {
                                Console.WriteLine("Warning! Action message from spectator, possibly malicious.");
                                continue;
                            }

                            Networking.ToClients(ack);
                        }
                    }

                    if (message.Type == MessageType.LeaveGame)
                    {
                        message.Source.HasLeft = true;
                    }

                    if (message.Type == MessageType.RequestPause)
                    {
                        message.Source.RequestingPause = true;
                    }

                    if (message.Type == MessageType.RequestUnpause)
                    {
                        message.Source.RequestingPause = false;

                        // Cancel everyone's pause request.
                        foreach (var client in Server.Clients)
                        {
                            client.RequestingPause = false;
                        }
                    }
                }

                // Messages from players
                if (message != null)
                {
                    if (message.Type == MessageType.StartingStep ||
                        message.Type == MessageType.Hash ||
                        message.Type == MessageType.StringHash)
                    {
                        message.Innermost.Do();
                    }
                }

                // Messages from the server
                if (message.Source.IsServer)
                {
                    if (message.Type == MessageType.Bookend)
                    {
                        message.Innermost.Do();
                    }

                    if (message.Type == MessageType.PlayerActionAck)
                    {
                        message.Inner.Do();
                    }

                    if (message.Type == MessageType.Pause)
                    {
                        if (!ServerPaused)
                        {
                            ServerPaused = true;
                            GameClass.Game.Send("setScreen", "game-paused", new { canUnpause = true });
                        }
                    }

                    if (message.Type == MessageType.Unpause)
                    {
                        if (ServerPaused)
                        {
                            ServerPaused = false;
                            GameClass.Game.Send("back");
                        }
                    }

                    if (message.Type == MessageType.ServerLeft)
                    {
                        if (!Program.Server && !GameOver)
                        {
                            GameClass.Game.Send("setScreen", "disconnected", new { message = "The server has quit. Tell them they suck." });
                        }
                    }

                    if (message.Type == MessageType.NetworkDesync)
                    {
                        DesyncPause = true;
                        if (!Program.Server)
                        {
                            // The server has already put up its desync UI,
                            // so only do this for clients.
                            GameClass.Game.Send("setScreen", "desync");
                        }
                    }

                    if (message.Type == MessageType.GameState)
                    {
                        message.Innermost.Do();
                    }
                }
            }
        }
コード例 #5
0
ファイル: GameLogic.cs プロジェクト: JordanFisher/WAL
        void GameLogic(GameTime gameTime)
        {
            //Send("setMode", "in-game");
            //Send("setScreen", "in-game-ui");

            switch (State)
            {
            case GameState.ToEditor:
                NewWorldEditor();
                State = GameState.Game;

                Send("setMode", "in-game");
                Send("setScreen", "editor-ui");

                break;

            case GameState.ToMap:
                Render.StandardRenderSetup();
                DrawFullScreen(Assets.ScreenLoading);

                if (Program.StartupMap == null)
                {
                    Program.StartupMap = "Beset.m3n";
                }
                SetScenarioToLoad(Program.StartupMap);

                break;

            case GameState.TitleScreen:
                StartMenuMusicIfNeeded();
                AmbientSounds.EndAll();

                // No mouse input to web browser.
                SteamWrapper.SteamHtml.AllowMouseEvents = false;

                Render.StandardRenderSetup();

                DrawFullScreen(Assets.ScreenTitle);

                if (gameTime.TotalGameTime.Seconds < .005f)
                {
                    break;
                }

                if (MouseMovedSome)
                {
                    World.DrawArrowCursor();
                }
                else
                {
                    if (Input.DeltaMousPos.Length() > 40)
                    {
                        MouseMovedSome = true;
                    }
                }

                if (InputHelper.SomethingPressed())
                {
                    State = GameState.MainMenu;
                    Send("setMode", "main-menu");
                    Send("setScreen", "game-menu");
                }

                break;

            case GameState.MainMenu:
                StartMenuMusicIfNeeded();
                AmbientSounds.EndAll();

                if (!InputHelper.SomethingDown())
                {
                    SteamWrapper.SteamHtml.AllowMouseEvents = true;
                }

                if (_MapLoading != MapLoading)
                {
                    _MapLoading = MapLoading;
                    SetMapLoading();
                }

                if (MapLoading && NewMap != null)
                {
                    World      = NewMap;
                    MapLoading = false;

                    SetMapLoading();
                }

                Render.StandardRenderSetup();
                if (DrawMapPreview && World != null && World.DataGroup != null)
                {
                    Render.UnsetDevice();
                    try
                    {
                        World.DataGroup.UpdateGradient_ToPlayers();
                        World.DataGroup.UpdateGradient_ToBuildings();
                        World.DataGroup.UpdateGradient_ToPlayers();
                        World.DataGroup.UpdateGradient_ToBuildings();
                    }
                    catch
                    {
                    }

                    World.UpdateMinimap();

                    GridHelper.GraphicsDevice.SetRenderTarget(null);
                }

                Render.StandardRenderSetup();
                DrawFullScreen(Assets.ScreenDark);
                DrawWebView();

                if (DrawMapPreview && World != null && World.DataGroup != null)
                {
                    MapPreviewPos  = new vec2(0.76f, 0.32f);
                    MapPreviewSize = new vec2(.4f, .4f);

                    bool UseSolidColor = MapLoading || World == BlankWorld;
                    World.DrawMinimap(MapPreviewPos, MapPreviewSize, ShowCameraBox: false, SolidColor: UseSolidColor);
                }

                World.DrawArrowCursor();

                break;

            case GameState.Loading:
                FadeOutMenuMusicIfNeeded();

                PreGame();

                Render.StandardRenderSetup();
                DrawFullScreen(Assets.ScreenLoading);

                if (ScenarioToLoad != null)
                {
                    Send("setMode", "in-game");
                    Send("setScreen", "in-game-ui");

                    World = new World(
                        GameParams: Program.StartupGameParams,
                        RemoveComputerDragonLords: Program.RemoveComputerDragonLords);

                    TimeLoading          = 0;
                    World.LoadPlayerInfo = false;
                    World.Load(Path.Combine(MapDirectory, ScenarioToLoad));

                    Program.WorldLoaded = true;
                    Networking.ToServer(new Message(MessageType.DoneLoading));

                    ScenarioToLoad = null;
                    TimeSinceLoad  = 0;
                    DrawFullScreen(Assets.ScreenLoading);

                    GetNames();


                    //World.SaveCurrentStateInBuffer();
                    ////var m = new MessageGameState(World.SimStep, World.WorldBytes);
                    //var m = new Message(MessageType.DoneLoading);
                    //var s = m.Encode();

                    //Networking.SendString(new SteamPlayer(SteamCore.PlayerId()), s);
                    //var t = Networking.ReceiveString();
                    //var _s = t.Item2;

                    //Console.WriteLine("!");
                }

                if (Program.GameStarted)
                {
                    if (Program.Spectate)
                    {
                        State = GameState.Game;
                    }
                }
                else
                {
                    TimeLoading += DeltaT;

                    if (TimeLoading > 25)
                    {
                        OnFailedToJoinGame();
                    }

                    TimeSinceLoad = 0;
                    break;
                }

                FadeOutLoading();

                break;

            case GameState.Game:
                StartGameMusicIfNeeded();

                CalculateMouseDownOverUi();

                DrawGame(gameTime);

                if (Program.Spectate && ShouldDrawFading())
                {
                    Render.StandardRenderSetup();
                    DrawFullScreen(Assets.ScreenLoading);

                    FadeOutLoading();
                }
                else
                {
                    DrawWebView();

                    World.DrawUi();

                    if (TimeSinceLoad < 1.5f)
                    {
                        BlackOverlay(1f - (float)(TimeSinceLoad - 1.3f) / .2f);
                    }
                }

                break;
            }
        }