pikaMain.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <filesystem>
  4. #include <glad/glad.h>
  5. #include <windowSystemm/window.h>
  6. #include "logs/assert.h"
  7. #include "dllLoader/dllLoader.h"
  8. #include "pikaImgui/pikaImgui.h"
  9. #include <memoryArena/memoryArena.h>
  10. #include <runtimeContainer/runtimeContainer.h>
  11. #include <logs/log.h>
  12. #include <logs/logWindow.h>
  13. #include <editor/editor.h>
  14. #include <shortcutApi/shortcutApi.h>
  15. #include <globalAllocator/globalAllocator.h>
  16. #include <containerManager/containerManager.h>
  17. #include <staticVector.h>
  18. static bool shouldClose = false;
  19. #if defined(PIKA_WINDOWS)
  20. #include <Windows.h>
  21. BOOL WINAPI customConsoleHandlerRoutine(
  22. _In_ DWORD dwCtrlType
  23. )
  24. {
  25. if (dwCtrlType == CTRL_CLOSE_EVENT)
  26. {
  27. shouldClose = true;
  28. return true;
  29. }
  30. return false;
  31. }
  32. #endif
  33. int main()
  34. {
  35. #pragma region Console
  36. #if !(PIKA_SHOULD_REMOVE_EDITOR)
  37. //internal console
  38. {
  39. //std::streambuf *old = std::cout.rdbuf(consoleBuffer.rdbuf());
  40. //std::cout << "Bla" << std::endl;
  41. //printf("test\n");
  42. //std::cout.sync_with_stdio();
  43. //std::string text = buffer.str();
  44. }
  45. #else
  46. //normal console if enabeled
  47. #if defined(PIKA_WINDOWS)
  48. #ifdef PIKA_PRODUCTION
  49. #if PIKA_ENABLE_CONSOLE_IN_PRODUCTION
  50. {
  51. AllocConsole();
  52. (void)freopen("conin$", "r", stdin);
  53. (void)freopen("conout$", "w", stdout);
  54. (void)freopen("conout$", "w", stderr);
  55. std::cout.sync_with_stdio();
  56. //HWND hwnd = GetConsoleWindow(); //dissable console x button
  57. //HMENU hmenu = GetSystemMenu(hwnd, FALSE);
  58. //EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED);
  59. SetConsoleCtrlHandler(0, true); //dissable ctrl+c shortcut in console
  60. SetConsoleCtrlHandler(customConsoleHandlerRoutine, true); //custom exti function on clicking x button on console
  61. }
  62. #endif
  63. #endif
  64. #endif
  65. #endif
  66. #pragma endregion
  67. #pragma region init global variables stuff
  68. pika::initShortcutApi();
  69. #pragma endregion
  70. #pragma region log
  71. pika::LogManager logs;
  72. logs.init(pika::LogManager::DefaultLogFile);
  73. #pragma endregion
  74. //todo (in the future) increment id if it wasn't possible to copy the file
  75. #pragma region load dll
  76. std::filesystem::path currentPath = std::filesystem::current_path();
  77. pika::LoadedDll loadedDll;
  78. PIKA_PERMA_ASSERT(loadedDll.tryToloadDllUntillPossible(0, logs, std::chrono::seconds(5)),
  79. "Couldn't load dll");
  80. #pragma endregion
  81. #pragma region pika imgui id manager
  82. pika::pikaImgui::ImGuiIdsManager imguiIdsManager;
  83. #pragma endregion
  84. #pragma region push notification manager
  85. #if !(PIKA_SHOULD_REMOVE_PUSH_NOTIFICATIONS)
  86. pika::PushNotificationManager pushNotificationManager;
  87. pushNotificationManager.init();
  88. logs.pushNotificationManager = &pushNotificationManager;
  89. #endif
  90. #pragma endregion
  91. #pragma region init window opengl imgui and context
  92. PIKA_PERMA_ASSERT(glfwInit(), "Problem initializing glfw");
  93. //glfwSetErrorCallback(error_callback); todo
  94. pika::PikaWindow window = {};
  95. window.create();
  96. PIKA_PERMA_ASSERT(gladLoadGL(), "Problem initializing glad");
  97. pika::pikaImgui::initImgui(window.context);
  98. window.context.glfwMakeContextCurrentPtr = glfwMakeContextCurrent;
  99. #pragma endregion
  100. #pragma region container manager
  101. pika::ContainerManager containerManager;
  102. containerManager.init();
  103. #pragma endregion
  104. #pragma region init dll reaml
  105. loadedDll.gameplayStart_(window.context);
  106. #pragma endregion
  107. #pragma region shortcuts
  108. pika::ShortcutManager shortcutManager;
  109. #pragma endregion
  110. #pragma region editor
  111. #if !PIKA_SHOULD_REMOVE_EDITOR
  112. pika::Editor editor;
  113. editor.init(shortcutManager, imguiIdsManager);
  114. #endif
  115. #pragma endregion
  116. auto container = containerManager.createContainer
  117. (loadedDll.containerInfo[0], loadedDll, logs, imguiIdsManager);
  118. while (!shouldClose)
  119. {
  120. if (window.shouldClose())
  121. {
  122. shouldClose = true;
  123. break;
  124. }
  125. #pragma region start imgui
  126. pika::pikaImgui::imguiStartFrame(window.context);
  127. #pragma endregion
  128. #pragma region clear screen
  129. #if PIKA_PRODUCTION
  130. #if PIKA_CLEAR_SCREEN_BY_ENGINE_IN_PRODUCTION && PIKA_CLEAR_DEPTH_BY_ENGINE _IN_PRODUCTION
  131. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  132. #elif PIKA_CLEAR_SCREEN_BY_ENGINE_IN_PRODUCTION
  133. glClear(GL_COLOR_BUFFER_BIT);
  134. #elif PIKA_CLEAR_DEPTH_BY_ENGINE_IN_PRODUCTION
  135. glClear(GL_DEPTH_BUFFER_BIT);
  136. #endif
  137. #else
  138. glClear(GL_COLOR_BUFFER_BIT);
  139. #endif
  140. #pragma endregion
  141. #pragma region editor stuff
  142. #if !PIKA_SHOULD_REMOVE_EDITOR
  143. editor.update(window.input, shortcutManager, logs,
  144. pushNotificationManager, loadedDll, containerManager, imguiIdsManager);
  145. #endif
  146. #pragma endregion
  147. #pragma region container manager
  148. #if !(PIKA_SHOULD_REMOVE_EDITOR)
  149. if (editor.shouldReloadDll)
  150. {
  151. editor.shouldReloadDll = false;
  152. containerManager.reloadDll(loadedDll, window, logs);
  153. }
  154. #endif
  155. containerManager.update(loadedDll, window, logs, imguiIdsManager);
  156. #pragma endregion
  157. #pragma region push notification
  158. #if !(PIKA_SHOULD_REMOVE_PUSH_NOTIFICATIONS)
  159. static bool pushNoticicationOpen = true;
  160. pushNotificationManager.update(pushNoticicationOpen);
  161. #endif
  162. #pragma endregion
  163. #pragma region end imgui frame
  164. pika::pikaImgui::imguiEndFrame(window.context);
  165. #pragma endregion
  166. #pragma region window update
  167. window.update();
  168. #pragma endregion
  169. #pragma region shortcut manager update
  170. shortcutManager.update(window.input);
  171. #pragma endregion
  172. #if !PIKA_SHOULD_REMOVE_EDITOR
  173. editor.saveFlagsData();
  174. #endif
  175. window.saveWindowPositions();
  176. }
  177. #if !PIKA_SHOULD_REMOVE_EDITOR
  178. editor.saveFlagsData();
  179. #endif
  180. //todo flag?
  181. window.saveWindowPositions();
  182. containerManager.destroyAllContainers(loadedDll, logs);
  183. //terminate();
  184. return 0;
  185. }