memory setup
This commit is contained in:
@@ -6,20 +6,19 @@
|
||||
#include <cstdio>
|
||||
#include <bx/string.h>
|
||||
|
||||
//#define VISUAL_STUDIO
|
||||
#include "Shared.h"
|
||||
#include "Window.h"
|
||||
|
||||
typedef void (*Startup)(void*);
|
||||
typedef void (*Update)();
|
||||
typedef void (*Shutdown)();
|
||||
//#define VISUAL_STUDIO
|
||||
|
||||
constexpr UINT WM_CUSTOM_DLL_CHANGE = WM_USER + 1;
|
||||
|
||||
#ifdef VISUAL_STUDIO
|
||||
constexpr char* DLLPath = "PuzGame.dll";
|
||||
constexpr wchar_t* DLLWatch = L"PuzGame2.dll";
|
||||
constexpr const char* DLLPath = "PuzGame.dll";
|
||||
constexpr const wchar_t* DLLWatch = L"PuzGame2.dll";
|
||||
#else
|
||||
constexpr char* DLLPath = "libPuzGame.dll";
|
||||
constexpr wchar_t* DLLWatch = L"libPuzGame2.dll";
|
||||
constexpr const char* DLLPath = "libPuzGame.dll";
|
||||
constexpr const wchar_t* DLLWatch = L"cmake-build\\libPuzGame2.dll";
|
||||
#endif
|
||||
|
||||
struct FileWatcherData
|
||||
@@ -35,9 +34,16 @@ struct DevelopmentData
|
||||
FileWatcherData FileWatcher;
|
||||
};
|
||||
|
||||
struct EngineData
|
||||
{
|
||||
EngineWindow Window;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
DevelopmentData DevData;
|
||||
EngineData Engine;
|
||||
SharedData Shared;
|
||||
Startup StartupFunc;
|
||||
Update UpdateFunc;
|
||||
Shutdown ShutdownFunc;
|
||||
@@ -56,7 +62,7 @@ unsigned long FileWatcherThread(void* data)
|
||||
while (true)
|
||||
{
|
||||
FILE_NOTIFY_INFORMATION* notifyData = reinterpret_cast<FILE_NOTIFY_INFORMATION*>(&DevData.FileChangeBuffer[offset]);
|
||||
wprintf(L"Change: %ls\n", notifyData->FileName);
|
||||
// wprintf(L"Change: %ls\n", notifyData->FileName);
|
||||
|
||||
if (notifyData->Action == FILE_ACTION_ADDED || notifyData->Action == FILE_ACTION_MODIFIED || notifyData->Action == FILE_ACTION_RENAMED_NEW_NAME)
|
||||
{
|
||||
@@ -107,7 +113,7 @@ bool ReloadDLL()
|
||||
#ifdef VISUAL_STUDIO
|
||||
Startup StartupReloaded = (Startup)GetProcAddress(DevData.GameLib, "?Setup@Game@@YAXPEAX@Z");
|
||||
#else
|
||||
Startup StartupReloaded = (Startup)GetProcAddress(DevData.GameLib, "_ZN4Game5SetupEPv");
|
||||
Startup StartupReloaded = (Startup)GetProcAddress(DevData.GameLib, "_ZN4Game5SetupER10SharedData");
|
||||
#endif
|
||||
if (StartupReloaded == NULL)
|
||||
{
|
||||
@@ -153,6 +159,13 @@ int main()
|
||||
|
||||
if (!ReloadDLL()) return 1;
|
||||
|
||||
Engine.Window.Startup(Shared.Window);
|
||||
if (Shared.Window.Handle == nullptr)
|
||||
{
|
||||
printf("Failed to set up window!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
DevData.hDevDir = CreateFile(".",
|
||||
FILE_LIST_DIRECTORY,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
@@ -163,16 +176,22 @@ int main()
|
||||
DWORD fileWatcherThreadId = 0;
|
||||
CreateThread(NULL, 0, FileWatcherThread, NULL, 0, &fileWatcherThreadId);
|
||||
|
||||
StartupFunc(nullptr);
|
||||
StartupFunc(Shared);
|
||||
|
||||
bool isRunning = true;
|
||||
while (isRunning)
|
||||
{
|
||||
Engine.Window.Update(Shared.Window);
|
||||
if (Engine.Window.CloseRequested)
|
||||
{
|
||||
isRunning = false;
|
||||
}
|
||||
if (DevData.FileWatcher.Change)
|
||||
{
|
||||
DevData.FileWatcher.Change = false;
|
||||
ShutdownFunc();
|
||||
ReloadDLL();
|
||||
StartupFunc(nullptr);
|
||||
StartupFunc(Shared);
|
||||
}
|
||||
|
||||
UpdateFunc();
|
||||
|
||||
Reference in New Issue
Block a user