Curation round 2, wave B: ItemConfig, EntityConfig, mods, Manager and the KAGE platform on SDL3; boots to LuaEngine::Init

- item_config, entity_config and mod_manager take over their families as idiomatic classes (std containers,
  unique_ptr, bitset tear flags). Every big loader reads the imported JSON: entities2.xml gives 1349 entities.
- manager.h/.cpp take over Manager (g_manager) and IsaacStartup. Members are the curated subsystems by value.
- kage_graphics, kage_input and kage_sound take over KAGE's graphics (shaders, render targets, batches, PNG through
  stb_image), input (SDL3 keyboard, mouse, gamepads) and sound (SDL3 audio, wav and stb_vorbis ogg, pitch and volume).
- source_tree.py: classes inside a namespace block in src/ headers count as taken over, and a still-generated class's
  vtable slot keeps its stub unless src/ defines that exact method.
build/isaac opens the window, sets up GL 4.6, framebuffers and PulseAudio, logs the version, and stops at
LuaEngine::Init. 522 functions taken over, boot path 156/615.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-11-20 00:03:39 -05:00
1 parent 346dc95e13
commit 28e2e48842
105 files changed
+7008 -31418

No files matched your search

+55 -133
View File
@@ -1,7 +1,9 @@
#include "platform.h"
#include "classes.h"
#include "data.h"
#include "gl.h"
#include "kage_graphics.h"
#include "kage_input.h"
#include "kage_sound.h"
#include "options_config.h"
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_filesystem.h>
@@ -74,108 +76,6 @@ constexpr DefaultBinding KEYBOARD_DEFAULTS[] = {
// The standard buttons whose GLFW gamepad number differs.
constexpr DefaultBinding PLATFORM_BUTTONS[] = {{17, 7}, {18, 5}};
// A vertex attribute a built-in shader binds by name, and the slot of KAGE's vertex format it reads.
struct ShaderAttribute
{
const char* name;
int slot;
};
constexpr ShaderAttribute COLOR_ATTRIBUTES[] = {{"Position", 5}, {"Color", 6}, {"", 0}};
constexpr ShaderAttribute TEXTURE_ATTRIBUTES[] = {{"Position", 5}, {"Color", 6}, {"TexCoord", 7}, {"", 0}};
constexpr const char* COLOR_VERTEX = R"(
attribute vec3 Position;
attribute vec4 Color;
varying vec4 Color0;
uniform mat4 Transform;
void main( void )
{
Color0 = Color;
gl_Position = Transform * vec4( Position.xyz, 1.0 );
}
)";
constexpr const char* COLOR_FRAGMENT = R"(
#ifndef GL_ES
#define lowp
#endif
varying lowp vec4 Color0;
void main( void )
{
gl_FragColor = Color0;
if( gl_FragColor.a == 0.0 ) discard;
}
)";
constexpr const char* TEXTURE_VERTEX = R"(
attribute vec3 Position;
attribute vec4 Color;
attribute vec2 TexCoord;
varying vec4 Color0;
varying vec2 TexCoord0;
uniform mat4 Transform;
void main( void )
{
gl_Position = Transform * vec4( Position.xyz, 1.0 );
Color0 = Color;
TexCoord0 = TexCoord;
}
)";
constexpr const char* TEXTURE_FRAGMENT = R"(
#ifndef GL_ES
#define lowp
#define highp
#endif
varying lowp vec4 Color0;
varying highp vec2 TexCoord0;
uniform sampler2D Texture0;
void main( void )
{
gl_FragColor = texture2D( Texture0, TexCoord0 ) * Color0;
if( gl_FragColor.a == 0.0 ) discard;
}
)";
constexpr const char* INDEXED_TEXTURE_FRAGMENT = R"(
#ifndef GL_ES
#define lowp
#define highp
#endif
varying lowp vec4 Color0;
varying highp vec2 TexCoord0;
uniform sampler2D Texture0;
uniform sampler2D Texture1;
void main( void )
{
vec4 PaletteIndex = texture2D( Texture0, TexCoord0 );
vec4 OutputColor = texture2D( Texture1, PaletteIndex.xy ) * Color0;
if( OutputColor.w == 0.0 ) discard;
gl_FragColor = OutputColor;
}
)";
// One of the engine's built-in shaders.
struct ShaderSource
{
const char* name;
const ShaderAttribute* attributes;
const char* vertex;
const char* fragment;
};
constexpr ShaderSource SHADERS[] = {
{"KAGE_ColorShader", COLOR_ATTRIBUTES, COLOR_VERTEX, COLOR_FRAGMENT},
{"KAGE_ColorTextureShader", TEXTURE_ATTRIBUTES, TEXTURE_VERTEX, TEXTURE_FRAGMENT},
{"KAGE_IndexedTextureShader", TEXTURE_ATTRIBUTES, TEXTURE_VERTEX, INDEXED_TEXTURE_FRAGMENT},
};
Platform platform;
// The log file, which levels reach it, and whether the next message starts a line.
@@ -331,22 +231,40 @@ void Platform::bindings_load()
// stopping at the first that fails (the game carries on either way).
// 00a710a0 (merged) Steam, EOS, the custom heap, the packed archives' mount points (resources/ is read directly), the
// multiplayer threads and the Windows timer and power settings are left out: SDL keeps the display awake itself.
// The OpenAL Soft device hooks after the sound manager have no place on SDL audio.
// 00a8c430 The services manager that came last is left out: theoraplayer (no cutscene video yet), the Steam checks,
// the default profile icon and the user profile lock are all for video or online play.
void Platform::engine_init()
{
std::srand((unsigned int)(GetTimeNs() / SDL_NS_PER_MS));
if (isEngineInitialized) log_printf(LOG_ASSERT, "KAGE has already been initialized\n");
if (!graphics_init()) return;
if (!KAGE::Graphics::manager.Init()) return;
// The sound manager was a global object. The OpenAL Soft device hooks after it have no place on SDL audio.
(new KAGE::Sound::ManagerOpenAL())->FUN_00a649b0();
if (!FUN_00a21980() || !FUN_00a8c430()) return;
KAGE::Sound::manager.Init();
if (!KAGE::Input::manager.Init()) return;
isEngineInitialized = true;
}
// Opens the window, shows it, then builds the renderer's built-in shaders and starting state.
// This is Graphics::Manager::Init at 00a18e90, whose stub stays for the generated vtable.
bool Platform::graphics_init()
// 00a71770 Shuts KAGE down: input, sound and graphics, then the framebuffer and the window.
// Its EOS release, log closing, compressor, multiplayer threads, video manager and heaps have nothing here to free.
void Platform::engine_shutdown()
{
KAGE::Input::manager.Shutdown();
KAGE::Sound::manager.Shutdown();
KAGE::Graphics::manager.Shutdown();
gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
gl.DeleteFramebuffers(1, &framebuffer);
gl.DeleteRenderbuffers(1, &depthRenderbuffer);
SDL_GL_DestroyContext(context);
SDL_DestroyWindow(window);
context = nullptr;
window = nullptr;
isEngineInitialized = false;
}
// Opens the window at its default size with its GL context and shows it, as Graphics::Manager::Init began.
bool Platform::window_open()
{
if (!SDL_Init(SDL_INIT_VIDEO)) log_printf(LOG_ASSERT, "SDL failed to initialize: %s\n", SDL_GetError());
@@ -355,20 +273,15 @@ bool Platform::graphics_init()
if (!window_create()) return false;
SDL_ShowWindow(window);
SDL_RaiseWindow(window);
for (const ShaderSource& shader : SHADERS)
FUN_00a13fa0((uint8_t*)shader.name, (void*)shader.attributes, (void*)&shader);
state_reset();
KAGE_Graphics().SetRenderTarget(nullptr, 1);
// The renderer's vertex buffer (a GraphicsBufferObject the original keeps at DAT_00c7367c) and its black clear
// color come next, with the renderer.
new KAGE::Graphics::GraphicsBufferObject();
FUN_00a18460(0, 0, 0);
g_imageReleaseFn = (void*)&FUN_00a12240;
g_renderTargetReleaseFn = (void*)&FUN_00a12240;
return true;
}
// Shows the finished frame, as glfwSwapBuffers.
void Platform::window_swap()
{
SDL_GL_SwapWindow(window);
}
// 00a19df0 Creates the window hidden, with an OpenGL 2.0 compatibility context (1.0 if that fails), and the
// framebuffer the renderer draws the game into.
// The Win32 icon and the maximize box it removes have no SDL counterpart.
@@ -411,8 +324,8 @@ bool Platform::window_create()
return true;
}
// Puts back the GL state the renderer expects: the vsync setting, blending, depth testing toward the viewer from a
// cleared depth of -1000, and back faces culled (Graphics::Manager slot 30, 00a19b60).
// 00a19b60 (00a184e0) Puts back the GL state the renderer expects: the vsync setting, blending, depth testing toward
// the viewer from a cleared depth of -1000, and back faces culled.
void Platform::state_reset()
{
vsync_apply();
@@ -430,7 +343,7 @@ void Platform::vsync_apply()
SDL_GL_SetSwapInterval(isVsync ? 1 : 0);
}
// The window's drawable size in pixels (Graphics::Manager slots 12 and 13, 00a19340 and 00a193c0).
// (00a19340, 00a193c0) The window's drawable size in pixels.
Size Platform::framebuffer_size_get()
{
Size size;
@@ -440,12 +353,11 @@ Size Platform::framebuffer_size_get()
// 00a18750 Gives the framebuffer a depth renderbuffer at the powers of two at or above the drawing size, 8 at least,
// keeping the one it has while that is big enough.
// The drawing size falls back to the window's. A bound render target's would come first, once render targets exist.
// The drawing size falls back to the bound render target's, then the window's.
void Platform::depth_renderbuffer_update(RenderbufferMode mode)
{
Size drawable = framebuffer_size_get();
int width = drawingSize.width > 0 ? drawingSize.width : drawable.width;
int height = drawingSize.height > 0 ? drawingSize.height : drawable.height;
int width = drawingSize.width > 0 ? drawingSize.width : KAGE::Graphics::manager.target_width_get();
int height = drawingSize.height > 0 ? drawingSize.height : KAGE::Graphics::manager.target_height_get();
if (mode == RENDERBUFFER_KEEP && depthRenderbuffer != 0)
{
@@ -472,7 +384,7 @@ void Platform::depth_renderbuffer_update(RenderbufferMode mode)
gl.BindFramebuffer(GL_FRAMEBUFFER, previous);
}
// Sets the GL viewport to the game's viewport, at its offset when it has one.
// (00a19bc0, 00a186f0) Sets the GL viewport to the game's viewport, at its offset when it has one.
void Platform::viewport_reset()
{
SDL_FPoint offset = isViewportOffset ? viewportOffset : SDL_FPoint{};
@@ -521,13 +433,13 @@ void Platform::fullscreen_set(FullscreenMode mode)
SDL_GetWindowSize(window, &size.width, &size.height);
for (auto& listener : sizeListeners) listener(size);
viewport_reset();
KAGE_Graphics().update_projection();
KAGE::Graphics::manager.update_projection();
depth_renderbuffer_update(RENDERBUFFER_KEEP);
isFullscreen ? SDL_HideCursor() : SDL_ShowCursor();
}
// Takes the window's events as GLFW's callbacks did: closing asks the game to quit, and a new size (00a19bf0),
// position or focus goes to its listeners and resets what depends on it.
// Takes the window's events as GLFW's callbacks did: closing asks the game to quit, a new size (00a19bf0), position
// (00a19ca0) or focus (00a19d40) goes to its listeners and resets what depends on it, keys and gamepads go to input.
// Win32's topmost-while-focused fullscreen window has no SDL counterpart.
void Platform::events_poll()
{
@@ -547,7 +459,7 @@ void Platform::events_poll()
for (auto& listener : sizeListeners) listener(windowSize);
viewport_reset();
depth_renderbuffer_update(RENDERBUFFER_KEEP);
KAGE_Graphics().update_projection();
KAGE::Graphics::manager.update_projection();
break;
case SDL_EVENT_WINDOW_MOVED:
for (auto& listener : positionListeners) listener({event.window.data1, event.window.data2});
@@ -559,6 +471,16 @@ void Platform::events_poll()
case SDL_EVENT_WINDOW_FOCUS_LOST:
for (auto& listener : focusListeners) listener(event.type == SDL_EVENT_WINDOW_FOCUS_GAINED);
break;
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
KAGE::Input::manager.key_set(event.key.scancode, event.key.down);
break;
case SDL_EVENT_GAMEPAD_ADDED:
KAGE::Input::manager.gamepad_add(event.gdevice.which);
break;
case SDL_EVENT_GAMEPAD_REMOVED:
KAGE::Input::manager.gamepad_remove(event.gdevice.which);
break;
}
}
}