game.c 2.5 KB

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