Curation round 2, wave A: anm2 (Anm2Ed JSON), text, config as idiomatic classes; SDL3 platform opens a window

- anm2.h/.cpp take over ANM2, AnimationState, LayerState, AnmCache and the frame data. They read Anm2Ed's JSON documents
  with simdjson and play them as the game does (interpolation baked at load). src/anm2/ and msvc.h are retired.
- font, formatted_text, string_table and rich_text take over the text classes. FormattedText::parse is still bit-exact
  against its assembly.
- options_config and challenge_params take over OptionsConfig, ChallengeParams and the .ini helpers. The tests include
  Save's exact bytes.
- platform.h/.cpp and main.cpp run IsaacMain on SDL3: the window and GL context open, and the run stops at the first
  built-in shader (FUN_00a13fa0).
- source_tree.py: a taken-over parent stays bytes, taken-over methods are not re-emitted as a namespace, and every
  address in a (a, b, c to d) list on a comment counts as taken over.
- log.h: reconstruction_missing() for a taken-over class's methods that are not written yet.
206 functions taken over, boot path 89/615. The full build waits for wave B: item_config, entity_config and mod_manager
still use the old APIs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-11-19 23:04:54 -05:00
1 parent d6e1ca7c6c
commit 780767f5e1
161 files changed
+8646 -21919

No files matched your search

+336 -21
View File
@@ -1,54 +1,369 @@
#pragma once
// The most layers, nulls and layer tracks an .anm2 can hold, and the size of AnimationData::_layerMap.
constexpr int ANM2_LAYER_LIMIT = 64;
#include "classes.h"
#include <array>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
// ANM2::_bitflags and LayerState::_bitflags, ORed together when a layer renders.
// REPENTOGON's AnimRenderFlags, plus the two bits a layer named with a leading '*' gets.
// The most layers and nulls an .anm2 holds, and the size of AnimationData::layerMap.
constexpr int ANM2_LAYER_LIMIT = 64;
constexpr int ANM2_EVENT_LIMIT = 16;
constexpr int ANM2_TRIGGER_LIMIT = 128;
constexpr int ANM2_FRAME_LIMIT = 5000;
constexpr float ANIMATION_FRAME_UNSET = -1;
constexpr int NO_SHADOW_LAYER = -1;
constexpr ColorMod COLOR_DEFAULT = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0}};
constexpr ColorMod CHAMPION_COLOR_DEFAULT = {{1, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0}};
// ANM2::bitflags and LayerState::bitflags, ORed together when a layer renders.
// REPENTOGON's AnimRenderFlags, with names for the bits it leaves out.
enum AnimRenderFlag : unsigned int
{
ANIM_RENDER_UNTINTED = 1 << 0,
ANIM_RENDER_GLITCH = 1 << 1,
ANIM_RENDER_LIGHT_PASS_ONLY = 1 << 2,
ANIM_RENDER_SIZE_WITH_SPRITE = 1 << 3,
ANIM_RENDER_COLOROFFSET_CHAMPION = 1 << 4,
ANIM_RENDER_STATIC = 1 << 5,
ANIM_RENDER_IGNORE_GAME_TIME = 1 << 6,
ANIM_RENDER_GOLDEN = 1 << 7,
ANIM_RENDER_SHADER_KEPT = 1 << 9,
ANIM_RENDER_ENABLE_LAYER_LIGHTING = 1 << 10,
ANIM_RENDER_ENABLE_NULL_LAYER_LIGHTING = 1 << 11
};
// The five ints of LayerState::_blendMode, in REPENTOGON's BlendMode order.
// The parts of LayerState::blendMode, in REPENTOGON's BlendMode order.
enum BlendModePart : int
{
BLEND_EQUATION,
BLEND_RGB_SOURCE,
BLEND_RGB_DEST,
BLEND_ALPHA_SOURCE,
BLEND_ALPHA_DEST
BLEND_ALPHA_DEST,
BLEND_PART_COUNT
};
// REPENTOGON's BlendEquation.
enum BlendEquation : int
{
BLEND_EQUATION_ADD = 0,
BLEND_EQUATION_SUBTRACT = 1,
BLEND_EQUATION_REVERSE_SUBTRACT = 2,
BLEND_EQUATION_MIN = 3,
BLEND_EQUATION_MAX = 4
BLEND_EQUATION_ADD,
BLEND_EQUATION_SUBTRACT,
BLEND_EQUATION_REVERSE_SUBTRACT,
BLEND_EQUATION_MIN,
BLEND_EQUATION_MAX
};
// REPENTOGON's BlendFactor, the ones the game supports.
enum BlendFactor : int
{
BLEND_FACTOR_ZERO = 0,
BLEND_FACTOR_ONE = 1,
BLEND_FACTOR_SRC_COLOR = 2,
BLEND_FACTOR_ONE_MINUS_SRC_COLOR = 3,
BLEND_FACTOR_DST_COLOR = 4,
BLEND_FACTOR_ONE_MINUS_DST_COLOR = 5,
BLEND_FACTOR_SRC_ALPHA = 6,
BLEND_FACTOR_ONE_MINUS_SRC_ALPHA = 7,
BLEND_FACTOR_DST_ALPHA = 8,
BLEND_FACTOR_ONE_MINUS_DST_ALPHA = 9
BLEND_FACTOR_ZERO,
BLEND_FACTOR_ONE,
BLEND_FACTOR_SRC_COLOR,
BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
BLEND_FACTOR_DST_COLOR,
BLEND_FACTOR_ONE_MINUS_DST_COLOR,
BLEND_FACTOR_SRC_ALPHA,
BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
BLEND_FACTOR_DST_ALPHA,
BLEND_FACTOR_ONE_MINUS_DST_ALPHA
};
// Whether Play restarts the animation already shown.
enum PlayMode
{
PLAY_UNFORCED,
PLAY_FORCED
};
// What SetAnimation keeps of the animation it replaces.
enum AnimationSwitch
{
SWITCH_RESET,
SWITCH_KEEP_FRAME
};
// Whether Load loads the spritesheets right away or leaves them to LoadGraphics.
enum GraphicsLoad
{
GRAPHICS_DEFER,
GRAPHICS_LOAD
};
// Vector declares a constructor it does not define yet, so values are built member by member.
inline Vector vector_make(float x, float y)
{
Vector vector;
vector.x = x;
vector.y = y;
return vector;
}
// A null or root keyframe after loading: interpolation baked into one-tick frames and the root multiplied in.
// startFrame and endFrame bound the ticks it shows on, end excluded.
struct NullFrame
{
ColorMod color = COLOR_DEFAULT;
Vector pos{};
Vector scale = vector_make(1, 1);
float rotation = 0;
int duration = 1;
int endFrame = 0;
int startFrame = 0;
bool isInterpolated = false;
bool isVisible = true;
};
// A layer keyframe: a null keyframe with the spritesheet rectangle it shows and the pivot it turns about.
struct AnimationFrame : NullFrame
{
Vector crop{};
Vector pivot{};
float height = 0;
float width = 0;
};
// Where a sprite draws, and how many pixels each layer loses from its top left and bottom right.
struct SpriteDraw
{
Vector position{};
Vector topLeftClamp{};
Vector bottomRightClamp{};
};
struct ANM2;
struct LayerState;
// 0040c1e0 One layer's track in an animation, its keyframes in time order.
struct AnimationLayer
{
std::vector<AnimationFrame> frames;
int layerId = -1;
bool isVisible = true;
void RenderFrame(const SpriteDraw& draw, int frameIndex, const ANM2& animation) const;
static SourceQuad GetSourceQuad(const AnimationFrame& frame, const LayerState& layer, const SpriteDraw& draw,
const ANM2& animation);
static DestinationQuad GetDestQuad(const AnimationFrame& frame, const LayerState& layer, const SpriteDraw& draw,
const ANM2& animation);
};
// One null's track in an animation.
struct AnimationNullLayer
{
std::vector<NullFrame> frames;
int nullLayerId = 0;
bool isVisible = true;
};
// An event an animation fires on one of its frames.
struct AnimationData_EventTrigger
{
int animationFrame = 0;
uint32_t eventId = 0;
};
// An animation as the game plays it. layerMap gives each layer id its track in animLayers, or -1.
struct AnimationData
{
std::array<int, ANM2_LAYER_LIMIT> layerMap;
std::string name;
std::vector<AnimationLayer> animLayers;
std::vector<AnimationNullLayer> nullLayers;
std::vector<AnimationData_EventTrigger> eventTriggers;
int index = 0;
int length = 1;
bool isLooping = true;
AnimationData() { layerMap.fill(-1); }
};
// A layer of an .anm2 file, with its spritesheet's path relative to resources/.
struct LayerData
{
std::string name;
std::string spriteSheetPath;
int id = 0;
int spriteSheetId = 0;
};
// A parsed .anm2, shared by every sprite that loads it.
struct AnmFileData
{
std::string defaultAnimation;
std::vector<AnimationData> animations;
std::vector<LayerData> layers;
std::vector<std::string> eventNames;
std::vector<std::string> nullLayerNames;
};
// 004086e0, 004087a0 Copies and destruction are the defaults.
// Plays one animation of a sprite's file: the frame, each track's keyframe and the events fired.
// currentlyTriggeredEvents holds the events of the last step, previouslyTriggeredEvents every event since the start.
struct AnimationState
{
const AnimationData* animData = nullptr;
const AnmFileData* file = nullptr;
std::vector<int> layerFrames;
std::vector<int> nullLayerFrames;
float animFrame = ANIMATION_FRAME_UNSET;
uint32_t currentlyTriggeredEvents = 0;
uint32_t previouslyTriggeredEvents = 0;
bool isPlaying = false;
void SetAnimationData(const AnimationData* data);
void ChangeAnimationKeepFrame(const AnimationData* data);
void AdvanceLayerPosition(int layerId, float targetFrame);
void AdvanceNullLayerPosition(int nullLayerId, float targetFrame);
void FireTriggersAtCurrentFrame();
void AdvancePosition(int targetFrame);
void SetFrameFloat(float frame);
void SetLayerFrame(int layerId, int frame);
int GetLayerFrameIdx(int layerId) const;
void SetNullLayerFrame(int nullLayerId, int frame);
void Update(float playbackSpeed);
void Rewind();
void Render(const SpriteDraw& draw, const ANM2& animation) const;
void RenderLayer(int layerId, const SpriteDraw& draw, const ANM2& animation) const;
const AnimationFrame* GetLayerFrame(int layerId) const;
const NullFrame* GetNullFrameById(int nullLayerId) const;
const NullFrame* GetNullFrame(std::string_view nullLayerName) const;
bool IsEventTriggered(std::string_view eventName) const;
bool WasEventTriggered(std::string_view eventName) const;
int NextEventTrigger(std::string_view eventName) const;
const std::string& GetAnimation() const;
int GetAnimationIndex() const;
int GetAnimationLength() const;
bool IsLoopingAnimation() const;
bool is_playing(std::string_view name) const;
bool is_finished(std::string_view name) const;
};
// 00407a60 Destruction is the default.
// How a sprite shows one layer: its spritesheet, transform, colour, blending and filtering.
struct LayerState
{
ColorMod color = COLOR_DEFAULT;
Vector cropOffset{};
Vector pos{};
Vector size = vector_make(1, 1);
std::array<int, BLEND_PART_COUNT> blendMode{};
std::shared_ptr<KAGE::Graphics::ImageBase> spriteSheet;
std::string spriteSheetPath;
const LayerData* layerData = nullptr;
float rotation = 0;
unsigned int bitflags = 0;
unsigned int magFilterMode = 0;
unsigned int minFilterMode = 0;
unsigned int wrapSMode = 0;
unsigned int wrapTMode = 0;
bool isFlipX = false;
bool isFlipY = false;
bool isSpriteSheetLoaded = false;
bool isUnknown31 = false;
bool isVisible = true;
LayerState();
void Init(const LayerData* data);
};
// What a sprite holds. ANM2 copies it member by member.
struct ANM2Base
{
AnimationState animState;
AnimationState overlayAnimState;
ColorMod championColor = CHAMPION_COLOR_DEFAULT;
ColorMod color = COLOR_DEFAULT;
Vector offset{};
Vector scale = vector_make(1, 1);
std::shared_ptr<const AnmFileData> file;
std::string filename;
std::vector<LayerState> layerStates;
float playbackSpeed = 1;
float rotation = 0;
int shadowLayerIndex = NO_SHADOW_LAYER;
unsigned int bitflags = 0;
bool isFlipX = false;
bool isFlipY = false;
bool isLoaded = false;
bool isOverlayRenderFirst = false;
bool isUnknown108 = false;
};
// 004074c0, 00408170 Construction and destruction are the defaults.
// Sprite's field accessors (004073d0, 00407410, 00407420, 00407430, 00417200, 00417210, 00420160, 00420170, 00431300,
// 00435c60, 0043ee80, 00440e40, 00456340, 00456360, 0049cb40) are the public fields.
// A sprite (Lua's Sprite): an .anm2 from the cache with a main and an overlay animation playing on it.
struct ANM2 : ANM2Base
{
ANM2() = default;
ANM2(const ANM2& other);
ANM2& operator=(const ANM2& other);
void Reset();
void Load(std::string_view path, GraphicsLoad graphics);
void Reload();
void LoadGraphics();
bool ReplaceSpritesheet(int layerId, std::string_view path);
static void LoadDeliriumForm(ANM2& sprite, int type, int variant, bool isReloadAnm2);
void Update();
void Render(const SpriteDraw& draw) const;
void RenderLayer(int layerId, const SpriteDraw& draw) const;
void Play(std::string_view name, PlayMode mode = PLAY_UNFORCED);
void PlayRandom(uint32_t seed);
void PlayIndex(int index);
bool SetAnimation(std::string_view name, AnimationSwitch mode = SWITCH_RESET);
void SetFrame(std::string_view name, int frame);
void SetFrame(float frame);
void SetLastFrame();
int GetFrame() const;
void Stop();
bool IsPlaying(std::string_view name = {}) const;
bool IsFinished(std::string_view name = {}) const;
const std::string& GetAnimation() const;
const std::string& GetDefaultAnimationName() const;
const AnimationData* GetAnimationData(std::string_view name) const;
void PlayOverlay(std::string_view name, PlayMode mode = PLAY_UNFORCED);
bool SetOverlayAnimation(std::string_view name, AnimationSwitch mode = SWITCH_RESET);
void SetOverlayFrame(std::string_view name, int frame);
void SetOverlayFrame(int frame);
int GetOverlayFrame() const;
void StopOverlay();
void RemoveOverlay();
bool IsOverlayPlaying(std::string_view name = {}) const;
bool IsOverlayFinished(std::string_view name = {}) const;
const std::string& GetOverlayAnimation() const;
bool IsEventTriggered(std::string_view eventName) const;
bool WasEventTriggered(std::string_view eventName) const;
LayerState* GetLayer(int layerId);
LayerState* GetLayer(std::string_view name);
void SetLayerFrame(int layerId, int frame);
void SetLayerFrame(std::string_view layerName, int frame);
int GetLayerFrameIdx(int layerId) const;
const NullFrame* GetNullFrame(std::string_view nullLayerName) const;
const NullFrame* GetNullFrame(std::string_view animName, std::string_view nullLayerName, int frame) const;
const NullFrame* GetNullFrameById(int nullLayerId) const;
const std::string& GetNullLayerName(int nullLayerId) const;
int null_index_get(std::string_view name) const;
void animation_copy(ANM2& dest) const;
void appear_update();
};
// The parsed-file cache: every .anm2 read so far, by resource path, kept while a sprite holds it or until Clear.
struct AnmCache
{
static void Load(ANM2& sprite);
static void Preload(std::string_view path);
static void Clear();
static void LogMemoryUsage();
};