pikaMain.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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(gladLoadGLLoader((GLADloadproc)glfwGetProcAddress), "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, logs);
  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_PRODUCTION == 1
  136. for (auto &c : loadedDll.containerInfo)
  137. {
  138. if (c.containerStaticInfo.openOnApplicationStartup)
  139. {
  140. #if !PIKA_SHOULD_REMOVE_EDITOR
  141. auto container = containerManager.createContainer
  142. (c, loadedDll, logs, imguiIdsManager, &editor.consoleWindow, std::string());
  143. #else
  144. auto container = containerManager.createContainer
  145. (c, loadedDll, logs, imguiIdsManager, nullptr, std::string());
  146. #endif
  147. }
  148. }
  149. #endif
  150. while (!shouldClose)
  151. {
  152. if (window.shouldClose())
  153. {
  154. shouldClose = true;
  155. break;
  156. }
  157. #pragma region start imgui
  158. pika::pikaImgui::imguiStartFrame(window.context);
  159. #pragma endregion
  160. #pragma region clear screen
  161. #if PIKA_PRODUCTION
  162. //#if PIKA_CLEAR_SCREEN_BY_ENGINE_IN_PRODUCTION && PIKA_CLEAR_DEPTH_BY_ENGINE _IN_PRODUCTION
  163. // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  164. //#elif PIKA_CLEAR_SCREEN_BY_ENGINE_IN_PRODUCTION
  165. // glClear(GL_COLOR_BUFFER_BIT);
  166. //#elif PIKA_CLEAR_DEPTH_BY_ENGINE_IN_PRODUCTION
  167. // glClear(GL_DEPTH_BUFFER_BIT);
  168. //#endif
  169. #else
  170. glClear(GL_COLOR_BUFFER_BIT);
  171. #endif
  172. #pragma endregion
  173. #pragma region editor stuff
  174. #if !PIKA_SHOULD_REMOVE_EDITOR
  175. editor.update(window.input, shortcutManager, logs,
  176. pushNotificationManager, loadedDll, containerManager, imguiIdsManager);
  177. #endif
  178. #pragma endregion
  179. #pragma region container manager
  180. #if !(PIKA_SHOULD_REMOVE_EDITOR)
  181. if (editor.shouldReloadDll)
  182. {
  183. editor.shouldReloadDll = false;
  184. containerManager.reloadDll(loadedDll, window, logs);
  185. }
  186. containerManager.update(loadedDll, window, logs, imguiIdsManager, &editor.consoleWindow);
  187. #else
  188. containerManager.update(loadedDll, window, logs, imguiIdsManager, nullptr);
  189. #endif
  190. //close engine if no more containers are open
  191. #if PIKA_PRODUCTION == 1
  192. if (containerManager.runningContainers.empty())
  193. {
  194. shouldClose = true;
  195. }
  196. #endif
  197. #pragma endregion
  198. #pragma region push notification
  199. #if !(PIKA_SHOULD_REMOVE_PUSH_NOTIFICATIONS)
  200. static bool pushNoticicationOpen = true;
  201. pushNotificationManager.update(pushNoticicationOpen);
  202. #endif
  203. #pragma endregion
  204. #pragma region end imgui frame
  205. pika::pikaImgui::imguiEndFrame(window.context);
  206. #pragma endregion
  207. #pragma region window update
  208. window.update();
  209. #pragma endregion
  210. #pragma region shortcut manager update
  211. shortcutManager.update(window.input);
  212. #pragma endregion
  213. #if !PIKA_SHOULD_REMOVE_EDITOR
  214. editor.saveFlagsData();
  215. #endif
  216. window.saveWindowPositions();
  217. }
  218. #if !PIKA_SHOULD_REMOVE_EDITOR
  219. editor.saveFlagsData();
  220. #endif
  221. //todo flag?
  222. window.saveWindowPositions();
  223. containerManager.destroyAllContainers(loadedDll, logs);
  224. //terminate();
  225. return 0;
  226. }