game.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. //
  65. // Initialize game data and set the flags to load the game resources.
  66. //
  67. PAL_InitGameData(gpGlobals->bCurrentSaveSlot);
  68. //
  69. // Run the main game loop.
  70. //
  71. dwTime = SDL_GetTicks();
  72. while (TRUE)
  73. {
  74. //
  75. // Do some initialization at game start.
  76. //
  77. if (gpGlobals->fGameStart)
  78. {
  79. PAL_GameStart();
  80. gpGlobals->fGameStart = FALSE;
  81. }
  82. //
  83. // Load the game resources if needed.
  84. //
  85. PAL_LoadResources();
  86. //
  87. // Clear the input state of previous frame.
  88. //
  89. PAL_ClearKeyState();
  90. //
  91. // Wait for the time of one frame. Accept input here.
  92. //
  93. PAL_DelayUntil(dwTime);
  94. //
  95. // Set the time of the next frame.
  96. //
  97. dwTime = SDL_GetTicks() + FRAME_TIME;
  98. //
  99. // Run the main frame routine.
  100. //
  101. PAL_StartFrame();
  102. }
  103. }