game.c 2.5 KB

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