mainloop.d 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. module system.mainloop;
  2. import variables;
  3. import ui.menu;
  4. import system.abstraction;
  5. import graphics.gamelogic;
  6. import raylib;
  7. import std.stdio;
  8. import std.conv;
  9. import scripts.lua.core;
  10. void mainLoop() {
  11. while (true)
  12. {
  13. switch (currentGameState)
  14. {
  15. case GameState.MainMenu:
  16. debugWriteln("Showing menu.");
  17. showMainMenu();
  18. break;
  19. case GameState.InGame:
  20. gameInit();
  21. while (!WindowShouldClose())
  22. {
  23. if (luaReload) {
  24. resetAllScriptValues();
  25. int luaExecutionCode = luaInit(luaExec);
  26. if (luaExecutionCode != EngineExitCodes.EXIT_OK) {
  27. writeln("[ERROR] Engine stops Lua execution according to error code: ",
  28. luaExecutionCode.to!EngineExitCodes);
  29. currentGameState = GameState.Exit;
  30. break;
  31. }
  32. luaReload = false;
  33. }
  34. SetExitKey(0);
  35. if (IsKeyPressed(KeyboardKey.KEY_F)) {
  36. ToggleFullscreen();
  37. }
  38. BeginDrawing();
  39. ClearBackground(Colors.BLACK);
  40. /* 3D part */
  41. luaEventLoopPre2D();
  42. BeginMode3D(camera);
  43. luaEventLoop3D();
  44. EndMode3D();
  45. luaEventLoopPost2D();
  46. /* 2D part */
  47. // background display logic
  48. backgroundLogic();
  49. // character display logic
  50. characterLogic();
  51. // effects logic
  52. effectsLogic();
  53. //drawing dialogs
  54. dialogLogic();
  55. EndDrawing();
  56. }
  57. break;
  58. case GameState.Exit:
  59. unloadResourcesOnExit();
  60. CloseAudioDevice();
  61. debugWriteln("closing window!");
  62. CloseWindow();
  63. return;
  64. default:
  65. break;
  66. }
  67. }
  68. }