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>
78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
//
|
|
// Created by darman on 9/24/26.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include "Engine/Platform/SdlContext.h"
|
|
#include "Engine/Platform/Window.h"
|
|
#include "Engine/Time/FrameClock.h"
|
|
#include "Engine/Time/SimClock.h"
|
|
|
|
#include <expected>
|
|
|
|
namespace SiegeDeck::Engine
|
|
{
|
|
class Application;
|
|
|
|
struct AppConfig
|
|
{
|
|
string Title = "Siege Deck";
|
|
string Version = "0.1.0";
|
|
int32 Width = 1280;
|
|
int32 Height = 720;
|
|
bool Fullscreen = false;
|
|
bool Vsync = false;
|
|
uint64 Seed = 0;
|
|
Optional<uint64> MaxFrames = None;
|
|
|
|
// Bad arguments are reported, not thrown: main prints them and exits with a usage error.
|
|
static std::expected<AppConfig, string> FromArgs(int argc, char* argv[]);
|
|
};
|
|
|
|
struct EngineContext
|
|
{
|
|
Application& App;
|
|
Window& MainWindow;
|
|
const FrameClock& Frame; // real time: UI, card hand, camera
|
|
SimClock& Sim; // sim time: SetSpeed(0) is the planning phase
|
|
};
|
|
|
|
class Application
|
|
{
|
|
public:
|
|
explicit Application(AppConfig appConfig);
|
|
~Application();
|
|
|
|
Application(const Application&) = delete;
|
|
Application& operator=(const Application&) = delete;
|
|
Application(Application&&) = delete;
|
|
Application& operator=(Application&&) = delete;
|
|
|
|
int Run();
|
|
void Quit() { running = false; };
|
|
|
|
EngineContext& GetContext() { return context; }
|
|
|
|
private:
|
|
void HandleEvents();
|
|
void DrawFrame(double alpha);
|
|
|
|
static constexpr double kSimDt = 1.0 / 60.0;
|
|
static constexpr int32 kMaxStepsPerFrame = 8;
|
|
|
|
AppConfig config;
|
|
|
|
// Members are constructed in declaration order and destroyed in reverse,
|
|
// so anything that depends on another subsystem is declared after it.
|
|
SdlContext sdl;
|
|
Window window;
|
|
FrameClock frameClock;
|
|
SimClock simClock { kSimDt, kMaxStepsPerFrame };
|
|
|
|
EngineContext context;
|
|
bool running = true;
|
|
};
|
|
|
|
}
|