This commit is contained in:
Asuro
2025-02-20 23:46:10 +01:00
parent e568363ca7
commit 43d7d2d012
7 changed files with 67 additions and 53 deletions

View File

@@ -63,8 +63,14 @@ struct PerfCounter
}
};
class SDL_Window;
union SDL_Event;
struct SharedWindowData
{
SDL_Window* SDLWindow = nullptr;
SDL_Event* SDLEvents{nullptr};
uint16_t SDLEventCount = 0;
void* Handle = nullptr;
int32_t WindowWidth = 1920;
int32_t WindowHeight = 1080;

View File

@@ -3,9 +3,7 @@
#include "Shared.h"
#include "Window.h"
#include <SDL3/SDL.h>
#include <backends/imgui_impl_sdl3.h>
#include <cstdio>
#include <imgui.h>
void EngineWindow::Startup(SharedWindowData& shared)
{
@@ -29,29 +27,28 @@ void EngineWindow::Startup(SharedWindowData& shared)
printf("Failed to get window pointer!\n");
return;
}
shared.SDLWindow = Window;
// SDL_SetWindowRelativeMouseMode(Window, true);
IMGUI_CHECKVERSION();
auto* imguiCtx = ImGui::CreateContext();
if (imguiCtx == nullptr)
{
printf("Failed to set up imgui context!\n");
return;
}
if (!ImGui_ImplSDL3_InitForVulkan(Window))
{
printf("Failed to set up imgui implementation!\n");
return;
}
}
void EngineWindow::Update(SharedWindowData& shared)
{
START_PERF();
shared.SDLEvents = &EventBuffer[0];
SDL_Event evt;
while (SDL_PollEvent(&evt))
{
ImGui_ImplSDL3_ProcessEvent(&evt);
if (shared.SDLEventCount < MaxEventBufferSize)
{
EventBuffer[shared.SDLEventCount] = evt;
++shared.SDLEventCount;
}
else
{
printf("Warning: Skipping SDL event!\n");
}
switch (evt.type)
{
case SDL_EVENT_WINDOW_RESIZED:

View File

@@ -4,9 +4,12 @@
class EngineWindow
{
static constexpr uint32_t MaxEventBufferSize = 16;
public:
SDL_Window* Window;
bool CloseRequested = false;
SDL_Event EventBuffer[MaxEventBufferSize];
public:
void Startup(SharedWindowData& Shared);