public void Update(TicCmd[] cmds) { // do player reborns if needed for (var i = 0; i < Player.MaxPlayerCount; i++) { if (players[i].InGame && players[i].PlayerState == PlayerState.Reborn) { G_DoReborn(i); } } // do things to change the game state while (gameAction != GameAction.Nothing) { switch (gameAction) { case GameAction.LoadLevel: G_DoLoadLevel(); break; case GameAction.NewGame: G_DoNewGame(); break; case GameAction.LoadGame: //G_DoLoadGame(); break; case GameAction.SaveGame: //G_DoSaveGame(); break; case GameAction.PlayDemo: //G_DoPlayDemo(); break; case GameAction.Completed: G_DoCompleted(); break; case GameAction.Victory: //F_StartFinale(); break; case GameAction.WorldDone: G_DoWorldDone(); break; case GameAction.ScreenShot: //M_ScreenShot(); gameAction = GameAction.Nothing; break; case GameAction.Nothing: break; } } // get commands, check consistancy, // and build new consistancy check //buf = (gametic / ticdup) % BACKUPTICS; for (var i = 0; i < Player.MaxPlayerCount; i++) { if (players[i].InGame) { var cmd = players[i].Cmd; cmd.CopyFrom(cmds[i]); if (demoplayback) { //G_ReadDemoTiccmd(cmd); } if (demorecording) { //G_WriteDemoTiccmd(cmd); } // check for turbo cheats if (cmd.ForwardMove > GameConstants.TURBOTHRESHOLD.Data && (gametic & 31) == 0 && ((gametic >> 5) & 3) == i) { players[options.ConsolePlayer].Message = "%s is turbo!"; } /* * if (options.NetGame && !netdemo && !(gametic%ticdup) ) * { * if (gametic > BACKUPTICS * && consistancy[i][buf] != cmd->consistancy) * { * I_Error("consistency failure (%i should be %i)", * cmd->consistancy, consistancy[i][buf]); * * if (players[i].mo) * consistancy[i][buf] = players[i].mo->x; * else * consistancy[i][buf] = rndindex; * } * } */ } } // check for special buttons for (var i = 0; i < Player.MaxPlayerCount; i++) { if (players[i].InGame) { if ((players[i].Cmd.Buttons & TicCmdButtons.Special) != 0) { switch (players[i].Cmd.Buttons & TicCmdButtons.SpecialMask) { case TicCmdButtons.Pause: paused = !paused; if (paused) { //S_PauseSound(); } else { //S_ResumeSound(); } break; case TicCmdButtons.SaveGame: //if (!savedescription[0]) { //strcpy(savedescription, "NET GAME"); //savegameslot = // (players[i].cmd.buttons & BTS_SAVEMASK) >> BTS_SAVESHIFT; gameAction = GameAction.SaveGame; } break; } } } } // do main actions switch (gameState) { case GameState.Level: gameAction = world.Update(); //ST_Ticker(); //AM_Ticker(); //HU_Ticker(); break; case GameState.Intermission: var end = intermission.Update(); if (end) { G_WorldDone(); } break; case GameState.Finale: //F_Ticker(); break; case GameState.DemoScreen: //D_PageTicker(); break; } options.GameTic++; }
/// <summary> /// Advance the game one frame. /// </summary> public UpdateResult Update(TicCmd[] cmds) { // Do player reborns if needed. var players = options.Players; for (var i = 0; i < Player.MaxPlayerCount; i++) { if (players[i].InGame && players[i].PlayerState == PlayerState.Reborn) { DoReborn(i); } } // Do things to change the game state. while (gameAction != GameAction.Nothing) { switch (gameAction) { case GameAction.LoadLevel: DoLoadLevel(); break; case GameAction.NewGame: DoNewGame(); break; case GameAction.LoadGame: DoLoadGame(); break; case GameAction.SaveGame: DoSaveGame(); break; case GameAction.Completed: DoCompleted(); break; case GameAction.Victory: DoFinale(); break; case GameAction.WorldDone: DoWorldDone(); break; case GameAction.Nothing: break; } } for (var i = 0; i < Player.MaxPlayerCount; i++) { if (players[i].InGame) { var cmd = players[i].Cmd; cmd.CopyFrom(cmds[i]); /* * if (demorecording) * { * G_WriteDemoTiccmd(cmd); * } */ // Check for turbo cheats. if (cmd.ForwardMove > GameConst.TurboThreshold && (world.LevelTime & 31) == 0 && ((world.LevelTime >> 5) & 3) == i) { var player = players[options.ConsolePlayer]; player.SendMessage(players[i].Name + " is turbo!"); } } } // Check for special buttons. for (var i = 0; i < Player.MaxPlayerCount; i++) { if (players[i].InGame) { if ((players[i].Cmd.Buttons & TicCmdButtons.Special) != 0) { if ((players[i].Cmd.Buttons & TicCmdButtons.SpecialMask) == TicCmdButtons.Pause) { paused = !paused; if (paused) { options.Sound.Pause(); } else { options.Sound.Resume(); } } } } } // Do main actions. var result = UpdateResult.None; switch (gameState) { case GameState.Level: if (!paused || world.FirstTicIsNotYetDone) { result = world.Update(); if (result == UpdateResult.Completed) { gameAction = GameAction.Completed; } } break; case GameState.Intermission: result = intermission.Update(); if (result == UpdateResult.Completed) { gameAction = GameAction.WorldDone; if (world.SecretExit) { players[options.ConsolePlayer].DidSecret = true; } if (options.GameMode == GameMode.Commercial) { switch (options.Map) { case 6: case 11: case 20: case 30: DoFinale(); result = UpdateResult.NeedWipe; break; case 15: case 31: if (world.SecretExit) { DoFinale(); result = UpdateResult.NeedWipe; } break; } } } break; case GameState.Finale: result = finale.Update(); if (result == UpdateResult.Completed) { gameAction = GameAction.WorldDone; } break; } gameTic++; if (result == UpdateResult.NeedWipe) { return(UpdateResult.NeedWipe); } else { return(UpdateResult.None); } }