Files
darmanandClaude Opus 5.5 384f1ed1f2 feat: engine skeleton (Build Order step 1) and siege_tests
Engine:
- SdlContext and Window: RAII, throwing constructors, non-movable
- FrameClock (real time, clamped dt) and SimClock (fixed 1/60 s steps,
  speed 0 = planning phase, backlog capped per frame)
- Application owns them in lifetime order, exposes EngineContext, and
  runs the fixed-timestep loop; AppConfig::FromArgs parses --frames,
  --seed and --fullscreen
- Temporary window-surface fill so Wayland maps the window until
  RenderDevice lands in step 2

Build:
- Split into the siege_engine static lib and the siege_deck exe
- check_engine_deps fails the build if Engine/ includes Game/
- ctest smoke test: siege_deck --frames 30 on the offscreen driver
- siege_tests on Catch2 v3.15.3 (nixpkgs + CPM pin), with SimClock,
  FrameClock and AppConfig tests

Docs:
- Decision Log: error handling split, Catch2 for unit tests
- Build Order step 1 done; Engine Overview, Main Loop and Time and
  README updated to match
- AGENTS.md with build, conventions and gotchas for coding agents
- .gitignore: .mcp.json (local CLion MCP port) and Obsidian's
  workspace.json (tab/pane state), now untracked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 00:27:36 +02:00

62 lines
1.6 KiB
C++

//
// Created by darman on 9/24/26.
//
#include "Window.h"
#include <SDL3/SDL.h>
#include <spdlog/spdlog.h>
namespace SiegeDeck::Engine
{
Window::Window(const SdlContext& /*sdl*/, const WindowDesc& desc)
{
// No SDL_WINDOW_VULKAN etc.: SDL_ClaimWindowForGPUDevice picks the backend later.
SDL_WindowFlags flags = SDL_WINDOW_HIGH_PIXEL_DENSITY;
if (desc.Resizable)
flags |= SDL_WINDOW_RESIZABLE;
if (desc.Fullscreen)
flags |= SDL_WINDOW_FULLSCREEN;
handle.reset(SDL_CreateWindow(desc.Title.c_str(), desc.Width, desc.Height, flags));
if (!handle)
throw std::runtime_error(std::format("SDL_CreateWindow failed: {}", SDL_GetError()));
glm::ivec2 pixels = PixelSize();
spdlog::info("Window {}x{} ({}x{} px, scale {:.2f})", desc.Width, desc.Height, pixels.x, pixels.y,
DisplayScale());
}
SDL_WindowID Window::Id() const
{
return SDL_GetWindowID(handle.get());
}
glm::ivec2 Window::Size() const
{
glm::ivec2 size { 0 };
SDL_GetWindowSize(handle.get(), &size.x, &size.y);
return size;
}
glm::ivec2 Window::PixelSize() const
{
glm::ivec2 size { 0 };
SDL_GetWindowSizeInPixels(handle.get(), &size.x, &size.y);
return size;
}
float Window::DisplayScale() const
{
float scale = SDL_GetWindowDisplayScale(handle.get());
return scale > 0.0f ? scale : 1.0f; // 0 means SDL couldn't tell
}
void Window::SetTitle(const string& title)
{
SDL_SetWindowTitle(handle.get(), title.c_str());
}
}