pikaMain.cpp 6.2 KB

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