engine.d 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // quantumde1 developed software, licensed under MIT license.
  2. module graphics.engine;
  3. import raylib;
  4. //dlang imports
  5. import std.stdio;
  6. import std.string;
  7. import std.conv;
  8. //graphics
  9. import graphics.gamelogic;
  10. import ui.menu;
  11. //dialogs
  12. import dialogs.dialogbox;
  13. //scripting imports
  14. import scripts.lua;
  15. //engine internal functions
  16. import system.config;
  17. import system.abstraction;
  18. import variables;
  19. import system.cleanup;
  20. import std.algorithm;
  21. void engineLoader()
  22. {
  23. systemSettings = loadSettingsFromConfigFile("conf/settings.conf");
  24. baseWidth = systemSettings.defaultScreenWidth;
  25. baseHeight = systemSettings.defaultScreenHeight;
  26. int screenWidth = systemSettings.screenWidth;
  27. int screenHeight = systemSettings.screenHeight;
  28. scale = min(cast(float)(screenWidth/baseWidth), cast(float)(screenHeight/baseHeight));
  29. debugWriteln("scale: ", scale);
  30. // Initialization
  31. SetExitKey(0);
  32. Image icon = LoadImage(systemSettings.iconPath.toStringz());
  33. // Window and Audio Initialization
  34. InitWindow(screenWidth, screenHeight, systemSettings.windowTitle.toStringz());
  35. if (systemSettings.defaultFullscreen == true) {
  36. ToggleFullscreen();
  37. }
  38. SetWindowIcon(icon);
  39. UnloadImage(icon);
  40. //ToggleFullscreen();
  41. SetTargetFPS(60);
  42. //fallback font?
  43. textFont = LoadFont(systemSettings.fallbackFont.toStringz());
  44. // Fade In and Out Effects
  45. InitAudioDevice();
  46. helloScreen();
  47. ClearBackground(Colors.BLACK);
  48. EndDrawing();
  49. camera = Camera(
  50. Vector3(0.0f, 10.0f, 8.0f),
  51. Vector3(0.0f, 5.0f, 0.0f),
  52. Vector3(0.0, 1.0, 0.0),
  53. 45.0f,
  54. CameraProjection.CAMERA_PERSPECTIVE
  55. );
  56. while (true)
  57. {
  58. switch (currentGameState)
  59. {
  60. case GameState.MainMenu:
  61. debugWriteln("Showing menu.");
  62. showMainMenu();
  63. break;
  64. case GameState.InGame:
  65. gameInit();
  66. while (!WindowShouldClose())
  67. {
  68. if (luaReload) {
  69. resetAllScriptValues();
  70. int luaExecutionCode = luaInit(luaExec);
  71. if (luaExecutionCode != EngineExitCodes.EXIT_OK) {
  72. writeln("[ERROR] Engine stops Lua execution according to error code: ",
  73. luaExecutionCode.to!EngineExitCodes);
  74. currentGameState = GameState.Exit;
  75. break;
  76. }
  77. luaReload = false;
  78. }
  79. SetExitKey(0);
  80. if (IsKeyPressed(KeyboardKey.KEY_F11)) {
  81. ToggleFullscreen();
  82. }
  83. BeginDrawing();
  84. ClearBackground(Colors.BLACK);
  85. /* 2D part */
  86. // background display logic
  87. backgroundLogic();
  88. // character display logic
  89. characterLogic();
  90. // effects logic
  91. effectsLogic();
  92. //drawing dialogs
  93. dialogLogic();
  94. /* 3D part */
  95. BeginMode3D(camera);
  96. DrawGrid(10, 2);
  97. luaEventLoop();
  98. EndMode3D();
  99. EndDrawing();
  100. }
  101. break;
  102. case GameState.Exit:
  103. EndDrawing();
  104. unloadResourcesLogic();
  105. CloseAudioDevice();
  106. CloseWindow();
  107. return;
  108. default:
  109. break;
  110. }
  111. }
  112. }