memory setup

This commit is contained in:
Asuro
2025-02-09 03:01:43 +01:00
parent fbed568fae
commit df752065af
12 changed files with 227 additions and 80 deletions

26
src/engine/Shared.h Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
#include <cstdint>
struct SharedWindowData
{
void* Handle = nullptr;
int32_t WindowWidth = 1920;
int32_t WindowHeight = 1080;
};
struct GameData
{
void* PermanentStorage = nullptr;
uint64_t PermanentStorageSize = 0;
};
struct SharedData
{
SharedWindowData Window;
GameData Game;
};
typedef void (*Startup)(SharedData& shared);
typedef void (*Update)();
typedef void (*Shutdown)();

53
src/engine/Window.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include "Window.h"
#include "SDL3/SDL_events.h"
#include "Shared.h"
#include <cstdio>
#include <SDL3/SDL.h>
void EngineWindow::Startup(SharedWindowData& shared)
{
if (!SDL_Init(SDL_INIT_VIDEO))
{
printf("Failed to init SDL!\n");
return;
}
Window = SDL_CreateWindow("SDL", shared.WindowWidth, shared.WindowHeight, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
if (Window == nullptr)
{
printf("Failed to init SDL Window!\n");
return;
}
auto props = SDL_GetWindowProperties(Window);
SDL_EnumerateProperties(props, [](void*, SDL_PropertiesID id, const char* name)
{
printf("Prop: %s\n", name);
}, nullptr);
shared.Handle = SDL_GetPointerProperty(props, "SDL.window.win32.hwnd", nullptr);
if (shared.Handle == nullptr)
{
printf("Failed to get window pointer!\n");
return;
}
}
void EngineWindow::Update(SharedWindowData& Shared)
{
SDL_Event evt;
while (SDL_PollEvent(&evt))
{
switch (evt.type)
{
case SDL_EVENT_WINDOW_RESIZED:
{
SDL_GetWindowSize(Window, &Shared.WindowWidth, &Shared.WindowHeight);
break;
}
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
{
CloseRequested = true;
break;
}
}
}
}

15
src/engine/Window.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "Shared.h"
#include <SDL3/SDL.h>
class EngineWindow
{
public:
SDL_Window* Window;
bool CloseRequested = false;
public:
void Startup(SharedWindowData& Shared);
void Update(SharedWindowData& Shared);
void Shutdown();
};

View File

@@ -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();