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

View File

@@ -1,9 +1,7 @@
#include "Setup.h"
#include "Log.h"
#include "SDL3/SDL_video.h"
#include "rendering/Rendering.h"
#include <cstdint>
#include <SDL3/SDL.h>
#include "Global.h"
namespace Game
{
@@ -11,59 +9,37 @@ namespace Game
{
public:
GameRendering Rendering;
int32_t FrameCounter = 0;
};
namespace
{
GameSetup Instance;
GameSetup SetupInstance;
}
void Setup(void* window)
void Setup(SharedData& shared)
{
Log("Game Setup Start!");
if (!SDL_Init(SDL_INIT_VIDEO))
GameInstance& instance = *reinterpret_cast<GameInstance*>(&shared.Game.PermanentStorage);
if (sizeof(GameInstance) != instance.Size)
{
Log("Failed to init SDL!");
return;
Log("Game instance size changed, resetting!");
instance = {};
}
SDL_Window* sdlWindow = SDL_CreateWindow("SDL", 1920, 1080, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
if (sdlWindow == nullptr)
{
Log("Failed to init SDL Window!");
return;
}
auto props = SDL_GetWindowProperties(sdlWindow);
SDL_EnumerateProperties(props, [](void*, SDL_PropertiesID id, const char* name)
{
Log("Prop: %s", name);
}, nullptr);
void* hwnd = SDL_GetPointerProperty(props, "SDL.window.win32.hwnd", nullptr);
if (hwnd == nullptr)
{
Log("Failed to get window pointer!");
return;
}
Instance.Rendering.Setup(hwnd);
SetShared(shared);
SetInstance(instance);
SetupInstance.Rendering.Setup();
}
void Update()
{
SDL_Event evt;
while (SDL_PollEvent(&evt)) {}
++Instance.FrameCounter;
if (Instance.FrameCounter % 100 == 0)
{
Log("Frame!");
}
Instance.Rendering.Update();
++GetInstance().FrameCounter;
SetupInstance.Rendering.Update();
}
void Shutdown()
{
Log("Shutdown");
Instance.Rendering.Shutdown();
SetupInstance.Rendering.Shutdown();
}
}