#pragma once #include "log.h" #include #include #include #include #include #include struct SDL_GLContextState; struct SDL_Window; constexpr int BINDING_SLOTS = 4; // The game's frame, 60 Hz, in seconds. constexpr double FRAME_TIME = 1.0 / 60; // A width and a height in pixels. struct Size { int width = 0; int height = 0; bool operator==(const Size&) const = default; }; // The buttons or keys one input action is bound to, -1 in an empty slot. using ActionBinding = std::array; // The default bindings of every input action, by action: GLFW gamepad buttons and GLFW keys. struct InputBindings { std::vector controller; std::vector keyboard; int controllerCount = 0; }; // How the window fills the screen. enum FullscreenMode { FULLSCREEN_OFF, FULLSCREEN_BORDERLESS, FULLSCREEN_EXCLUSIVE }; // Whether the depth renderbuffer is rebuilt even when the one it has is big enough. enum RenderbufferMode { RENDERBUFFER_KEEP, RENDERBUFFER_REBUILD }; // The engine's platform layer on SDL3: KAGE's System, the window half of its Graphics::Manager and the GLFW calls // under them, with the folders the game saves into and the 60 Hz frame pacing. // Listeners get the window's new size, position or focus, as the game registers them in IsaacStartup, and each // character typed while text input is on, as GLFW's char callback did. class Platform { public: InputBindings bindings; std::string modsDirectory; std::string modsSaveDirectory; std::string userDataDirectory; std::vector> focusListeners; std::vector> positionListeners; std::vector> sizeListeners; std::vector> textListeners; SDL_FPoint viewportOffset = {}; SDL_Point windowPosition = {}; Size drawingSize = {-1, -1}; Size viewportSize; Size windowSize; SDL_GLContextState* context = nullptr; SDL_Window* window = nullptr; unsigned int depthRenderbuffer = 0; unsigned int framebuffer = 0; bool isEngineInitialized = false; bool isFullscreen = false; bool isQuitRequested = false; bool isViewportOffset = false; bool isVsync = true; void directories_load(); void bindings_load(); void engine_init(); void engine_shutdown(); bool window_open(); void window_swap(); void events_poll(); double time_get(); int frame_begin(); void frame_wait(); void window_size_set(Size size); void window_position_set(SDL_Point position); void fullscreen_set(FullscreenMode mode); void vsync_apply(); void depth_renderbuffer_update(RenderbufferMode mode); Size framebuffer_size_get(); void state_reset(); void viewport_reset(); private: double frameStart = 0; int fullFrameCount = 0; int shortFrameCount = 0; bool isPacingForced = false; bool window_create(); }; extern Platform platform; uint64_t GetTimeNs(); void log_open(const std::string& path); void log_printf(LogLevel level, const char* format, ...) __attribute__((format(printf, 2, 3)));