game.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009-2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // Copyright (c) 2011-2017, SDLPAL development team.
  5. // All rights reserved.
  6. //
  7. // This file is part of SDLPAL.
  8. //
  9. // SDLPAL is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. #include "main.h"
  23. static VOID
  24. PAL_GameStart(
  25. VOID
  26. )
  27. /*++
  28. Purpose:
  29. Do some initialization work when game starts (new game or load game).
  30. Parameters:
  31. None.
  32. Return value:
  33. None.
  34. --*/
  35. {
  36. PAL_SetLoadFlags(kLoadScene | kLoadPlayerSprite);
  37. if (!gpGlobals->fEnteringScene)
  38. {
  39. //
  40. // Fade in music if the player has loaded an old game.
  41. //
  42. AUDIO_PlayMusic(gpGlobals->wNumMusic, TRUE, 1);
  43. }
  44. gpGlobals->fNeedToFadeIn = TRUE;
  45. gpGlobals->dwFrameNum = 0;
  46. }
  47. VOID
  48. PAL_GameMain(
  49. VOID
  50. )
  51. /*++
  52. Purpose:
  53. The game entry routine.
  54. Parameters:
  55. None.
  56. Return value:
  57. None.
  58. --*/
  59. {
  60. DWORD dwTime;
  61. //
  62. // Show the opening menu.
  63. //
  64. gpGlobals->bCurrentSaveSlot = (BYTE)PAL_OpeningMenu();
  65. gpGlobals->fInMainGame = TRUE;
  66. //
  67. // Initialize game data and set the flags to load the game resources.
  68. //
  69. PAL_InitGameData(gpGlobals->bCurrentSaveSlot);
  70. //
  71. // Run the main game loop.
  72. //
  73. dwTime = SDL_GetTicks();
  74. while (TRUE)
  75. {
  76. //
  77. // Do some initialization at game start.
  78. //
  79. if (gpGlobals->fGameStart)
  80. {
  81. PAL_GameStart();
  82. gpGlobals->fGameStart = FALSE;
  83. }
  84. //
  85. // Load the game resources if needed.
  86. //
  87. PAL_LoadResources();
  88. //
  89. // Clear the input state of previous frame.
  90. //
  91. PAL_ClearKeyState();
  92. //
  93. // Wait for the time of one frame. Accept input here.
  94. //
  95. PAL_DelayUntil(dwTime);
  96. //
  97. // Set the time of the next frame.
  98. //
  99. dwTime = SDL_GetTicks() + FRAME_TIME;
  100. //
  101. // Run the main frame routine.
  102. //
  103. PAL_StartFrame();
  104. }
  105. }