dllMain.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include "dllMain.h"
  2. #include <gl2d/gl2d.h>
  3. #include <imgui.h>
  4. #include "pikaImgui/pikaImgui.h"
  5. #include <logs/assert.h>
  6. #include "containers/pikaGameplay.h"
  7. #include <containers.h>
  8. #include <memoryArena/memoryArena.h>
  9. #include <globalAllocator/globalAllocator.h>
  10. //todo use a global static array that can be accessed from other cpps and the macro will create an instance of a struct
  11. //that will push that container
  12. #define PIKA_MAKE_CONTAINER_INFO(x) pika::ContainerInformation(sizeof(x), #x, x::containerInfo())
  13. PIKA_API void getContainersInfo(std::vector<pika::ContainerInformation> &info)
  14. {
  15. info.clear();
  16. info.push_back(PIKA_MAKE_CONTAINER_INFO(Gameplay));
  17. info.push_back(PIKA_MAKE_CONTAINER_INFO(ImmageViewer));
  18. }
  19. //this should not allocate memory
  20. PIKA_API bool constructContainer(Container **c, pika::memory::MemoryArena *arena, const char *name)
  21. {
  22. *c = getContainer(name, arena);
  23. return *c != 0;
  24. }
  25. PIKA_API void destructContainer(Container **c, pika::memory::MemoryArena *arena)
  26. {
  27. //no need to call delete.
  28. (*c)->~Container();
  29. }
  30. PIKA_API void bindAllocator(pika::memory::FreeListAllocator *arena)
  31. {
  32. pika::memory::setGlobalAllocator(arena);
  33. }
  34. PIKA_API void resetAllocator()
  35. {
  36. pika::memory::setGlobalAllocatorToStandard();
  37. }
  38. PIKA_API void dissableAllocators()
  39. {
  40. pika::memory::dissableAllocators();
  41. }
  42. //used to initialize libraries
  43. PIKA_API void gameplayStart(pika::PikaContext &pikaContext)
  44. {
  45. pika::pikaImgui::setImguiAllocator(pikaContext.imguiAllocator);
  46. //pika::initShortcutApi(); //todo
  47. //todo user should have functions to specify this
  48. #pragma region init stuff
  49. #ifdef PIKA_DEVELOPMENT
  50. PIKA_PERMA_ASSERT(gladLoadGL(), "Problem initializing glad from dll");
  51. pika::pikaImgui::setImguiContext(pikaContext);
  52. #endif
  53. gl2d::init();
  54. #pragma endregion
  55. }
  56. //this won't be ever called in production so we can remove the code
  57. PIKA_API void gameplayReload(pika::PikaContext &pikaContext)
  58. {
  59. #ifdef PIKA_DEVELOPMENT
  60. pika::pikaImgui::setImguiAllocator(pikaContext.imguiAllocator); //todo check if really needed
  61. //pika::initShortcutApi();
  62. PIKA_PERMA_ASSERT(gladLoadGL(), "Problem initializing glad from dll");
  63. pika::pikaImgui::setImguiContext(pikaContext);
  64. gl2d::init();
  65. #endif
  66. }
  67. #if PIKA_WINDOWS
  68. #ifdef PIKA_DEVELOPMENT
  69. #include <Windows.h>
  70. //https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain
  71. BOOL WINAPI DllMain(
  72. HINSTANCE hinstDLL, // handle to DLL module
  73. DWORD fdwReason, // reason for calling function
  74. LPVOID lpvReserved) // reserved
  75. {
  76. // Perform actions based on the reason for calling.
  77. switch (fdwReason)
  78. {
  79. case DLL_PROCESS_ATTACH:
  80. // Initialize once for each new process.
  81. // Return FALSE to fail DLL load.
  82. break;
  83. case DLL_THREAD_ATTACH:
  84. // Do thread-specific initialization.
  85. break;
  86. case DLL_THREAD_DETACH:
  87. // Do thread-specific cleanup.
  88. break;
  89. case DLL_PROCESS_DETACH:
  90. if (lpvReserved != nullptr)
  91. {
  92. break; // do not do cleanup if process termination scenario
  93. }
  94. //if (old)
  95. //{
  96. // std::cout.rdbuf(old);
  97. //}
  98. // Perform any necessary cleanup.
  99. break;
  100. }
  101. return TRUE; // Successful DLL_PROCESS_ATTACH.
  102. }
  103. #endif
  104. #endif