#define PIKA_DECLARE_CONTAINER(x) info.push_back( pika::ContainerInformation(sizeof(x), #x, x::containerInfo()) ); #include "dllMain.h" #include #include #include "pikaImgui/pikaImgui.h" #include #include "containers/pikaGameplay.h" #include #include #include //todo use a global static array that can be accessed from other cpps and the macro will create an instance of a struct //that will push that container PIKA_API void getContainersInfo(std::vector &info) { info.clear(); PIKA_ALL_CONTAINERS() } #undef PIKA_DECLARE_CONTAINER //this should not allocate memory PIKA_API bool constructContainer(Container **c, pika::memory::MemoryArena *arena, const char *name) { *c = getContainer(name, arena); return *c != 0; } PIKA_API void destructContainer(Container **c, pika::memory::MemoryArena *arena) { //no need to call delete. (*c)->~Container(); } PIKA_API void bindAllocator(pika::memory::FreeListAllocator *arena) { pika::memory::setGlobalAllocator(arena); } PIKA_API void resetAllocator() { pika::memory::setGlobalAllocatorToStandard(); } PIKA_API void dissableAllocators() { pika::memory::dissableAllocators(); } void gl2dErrorFunc(const char *msg, void* userData) //todo { pika::LogManager *logManager = (pika::LogManager *)userData; pika::memory::pushCustomAllocatorsToStandard(); if (logManager) logManager->log(msg, pika::logError); pika::memory::popCustomAllocatorsToStandard(); } //used to initialize libraries PIKA_API void gameplayStart(pika::PikaContext &pikaContext, pika::LogManager &logs) { pika::pikaImgui::setImguiAllocator(pikaContext.imguiAllocator); pika::initShortcutApi(); //todo //todo user should have functions to specify this #pragma region init stuff #ifdef PIKA_DEVELOPMENT PIKA_PERMA_ASSERT(gladLoadGL(), "Problem initializing glad from dll"); pika::pikaImgui::setImguiContext(pikaContext); #endif gl2d::init(); gl2d::setUserDefinedData(&logs); gl2d::setErrorFuncCallback(gl2dErrorFunc); #pragma endregion } //this won't be ever called in production so we can remove the code PIKA_API void gameplayReload(pika::PikaContext &pikaContext, pika::LogManager &logs) { #ifdef PIKA_DEVELOPMENT pika::pikaImgui::setImguiAllocator(pikaContext.imguiAllocator); //todo check if really needed pika::initShortcutApi(); PIKA_PERMA_ASSERT(gladLoadGL(), "Problem initializing glad from dll"); pika::pikaImgui::setImguiContext(pikaContext); gl2d::init(); gl2d::setUserDefinedData(&logs); gl2d::setErrorFuncCallback(gl2dErrorFunc); #endif } #if PIKA_WINDOWS #ifdef PIKA_DEVELOPMENT #include //https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain BOOL WINAPI DllMain( HINSTANCE hinstDLL, // handle to DLL module DWORD fdwReason, // reason for calling function LPVOID lpvReserved) // reserved { // Perform actions based on the reason for calling. switch (fdwReason) { case DLL_PROCESS_ATTACH: // Initialize once for each new process. // Return FALSE to fail DLL load. break; case DLL_THREAD_ATTACH: // Do thread-specific initialization. break; case DLL_THREAD_DETACH: // Do thread-specific cleanup. break; case DLL_PROCESS_DETACH: if (lpvReserved != nullptr) { break; // do not do cleanup if process termination scenario } //if (old) //{ // std::cout.rdbuf(old); //} // Perform any necessary cleanup. break; } return TRUE; // Successful DLL_PROCESS_ATTACH. } #endif #endif