Curation round 3: Lua engine, Manager, sound, menus, cutscenes, rooms, item pools, saves; boots past LuaEngine::Init
Seven agents took over LuaEngine (the mod API registration deferred), the rest of Manager (LoadConfigs, fonts, render surfaces, Update/Render), MusicManager/SFXManager, MenuManager with the title/save/game menus, Cutscene/NightmareScene/ Backdrop, RoomConfig (src/rooms ported and retired) with ItemPool, and PersistentGameData (the original binary save format) with InfoDisplay. An integration pass moved call sites to the new APIs, declared the taken-over free functions, fixed two data.cpp crashes (an empty children array, null attribute strings), and made the generator keep a header's own name where a prototype names another address. Clean build (0 warnings with -Wall -Wextra). build/isaac runs the game's Lua scripts (without the mod API yet) and stops at reload_resource_paths. 901 functions taken over, boot path 204/615. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a7061306fa
commit
ddf913f304
137 files changed
+12684
-50687
No files matched your search
@@ -0,0 +1,158 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
struct Entity;
|
||||
struct Entity_Bomb;
|
||||
struct Entity_Familiar;
|
||||
struct Entity_Knife;
|
||||
struct Entity_NPC;
|
||||
struct Entity_Pickup;
|
||||
struct Entity_Player;
|
||||
struct Entity_Projectile;
|
||||
struct Entity_Tear;
|
||||
struct RNG;
|
||||
struct lua_State;
|
||||
|
||||
constexpr int LUA_CALLBACK_COUNT = 74;
|
||||
constexpr int LUA_GC_HISTORY_SIZE = 10;
|
||||
constexpr int LUA_GC_STEP_MIN = 50;
|
||||
constexpr int LUA_MEMORY_HISTORY_SIZE = 128;
|
||||
// Lua's LUA_NOREF: a registry reference to nothing.
|
||||
constexpr int LUA_REF_NONE = -2;
|
||||
|
||||
// The built-in callbacks the game runs mods' functions for, by their ModCallbacks ids in enums.lua.
|
||||
enum LuaCallback
|
||||
{
|
||||
MC_POST_RENDER = 2,
|
||||
MC_USE_ITEM = 3,
|
||||
MC_EVALUATE_CACHE = 8,
|
||||
MC_POST_PLAYER_INIT = 9,
|
||||
MC_USE_PILL = 10,
|
||||
MC_POST_GAME_STARTED = 15,
|
||||
MC_PRE_FAMILIAR_COLLISION = 26,
|
||||
MC_PRE_NPC_COLLISION = 30,
|
||||
MC_PRE_PLAYER_COLLISION = 33,
|
||||
MC_PRE_PICKUP_COLLISION = 38,
|
||||
MC_PRE_TEAR_COLLISION = 42,
|
||||
MC_PRE_PROJECTILE_COLLISION = 46,
|
||||
MC_POST_KNIFE_INIT = 50,
|
||||
MC_PRE_KNIFE_COLLISION = 53,
|
||||
MC_PRE_BOMB_COLLISION = 60,
|
||||
MC_GET_PILL_EFFECT = 65,
|
||||
MC_POST_ENTITY_KILL = 68
|
||||
};
|
||||
|
||||
// The game classes callbacks hand objects of to Lua, each with the registry key of the metatable the API gives it.
|
||||
enum LuaClass
|
||||
{
|
||||
LUA_CLASS_ENTITY,
|
||||
LUA_CLASS_BOMB,
|
||||
LUA_CLASS_FAMILIAR,
|
||||
LUA_CLASS_KNIFE,
|
||||
LUA_CLASS_NPC,
|
||||
LUA_CLASS_PICKUP,
|
||||
LUA_CLASS_PLAYER,
|
||||
LUA_CLASS_PROJECTILE,
|
||||
LUA_CLASS_RNG,
|
||||
LUA_CLASS_TEAR,
|
||||
LUA_CLASS_COUNT
|
||||
};
|
||||
|
||||
// Whether Lua runs sandboxed, or with every library, require searching resources/scripts/ and _LUADEBUG set.
|
||||
enum LuaMode
|
||||
{
|
||||
LUA_MODE_NORMAL,
|
||||
LUA_MODE_DEBUG
|
||||
};
|
||||
|
||||
// What a callback returned that can be true, false or nothing, as the game's Pre*Collision checks read it.
|
||||
enum LuaResult
|
||||
{
|
||||
LUA_RESULT_FALSE = -1,
|
||||
LUA_RESULT_NIL,
|
||||
LUA_RESULT_TRUE
|
||||
};
|
||||
|
||||
// A mod a script registered with RegisterMod, kept until that script runs again or Lua resets.
|
||||
struct LuaMod
|
||||
{
|
||||
std::string directory;
|
||||
std::string name;
|
||||
std::string scriptPath;
|
||||
int apiVersion = 0;
|
||||
int tableRef = LUA_REF_NONE;
|
||||
};
|
||||
|
||||
// An active item's use as MC_USE_ITEM sees it. A table result sets isDischarge and isRemove when it has their keys.
|
||||
struct LuaItemUse
|
||||
{
|
||||
Entity_Player* player = nullptr;
|
||||
RNG* rng = nullptr;
|
||||
int activeSlot = 0;
|
||||
int collectibleType = 0;
|
||||
int customVarData = 0;
|
||||
unsigned int useFlags = 0;
|
||||
bool isDischarge = false;
|
||||
bool isRemove = false;
|
||||
};
|
||||
|
||||
// The mod scripting host: the Lua 5.3 state, the game's scripts in resources/scripts/, the mods scripts register, and
|
||||
// the entry points that run mods' callbacks. A callback runs only while enabledCallbacks has its id, which the API's
|
||||
// SetBuiltInCallbackState sets once a mod adds a function for it. Lua errors are logged, never fatal.
|
||||
// Construction is inlined in IsaacStartup, and the original never destroys the engine.
|
||||
struct LuaEngine
|
||||
{
|
||||
std::array<int, LUA_MEMORY_HISTORY_SIZE> memoryHistory{};
|
||||
std::array<int, LUA_GC_HISTORY_SIZE> gcGrowth{};
|
||||
std::bitset<LUA_CALLBACK_COUNT> enabledCallbacks;
|
||||
std::list<LuaMod> mods;
|
||||
std::string scriptPath;
|
||||
lua_State* state = nullptr;
|
||||
LuaMode mode = LUA_MODE_NORMAL;
|
||||
int gcCooldown = 0;
|
||||
int gcFrame = 0;
|
||||
int gcLastMemory = -1;
|
||||
int gcStepSize = LUA_GC_STEP_MIN;
|
||||
int memoryHistoryCount = 0;
|
||||
int memoryHistoryIndex = 0;
|
||||
int memoryHistoryTimer = 0;
|
||||
int runCallbackRef = LUA_REF_NONE;
|
||||
int scriptApiVersion = -1;
|
||||
int unloadModRef = LUA_REF_NONE;
|
||||
uint32_t pointerMask = 0;
|
||||
|
||||
void Init(LuaMode luaMode);
|
||||
void RegisterAPI();
|
||||
void destroy();
|
||||
bool RunScript(std::string_view path);
|
||||
bool LuamodCMD(std::string_view modName);
|
||||
void gc_update();
|
||||
static int Isaac_GetItemIdByName(std::string_view name);
|
||||
|
||||
LuaResult PreBombCollision(Entity_Bomb* bomb, Entity* collider, bool isLow);
|
||||
LuaResult PreFamiliarCollision(Entity_Familiar* familiar, Entity* collider, bool isLow);
|
||||
LuaResult PreKnifeCollision(Entity_Knife* knife, Entity* collider, bool isLow);
|
||||
LuaResult PreNPCCollision(Entity_NPC* npc, Entity* collider, bool isLow);
|
||||
LuaResult PrePickupCollision(Entity_Pickup* pickup, Entity* collider, bool isLow);
|
||||
LuaResult PrePlayerCollide(Entity_Player* player, Entity* collider, bool isLow);
|
||||
LuaResult PreProjectileCollision(Entity_Projectile* projectile, Entity* collider, bool isLow);
|
||||
LuaResult PreTearCollision(Entity_Tear* tear, Entity* collider, bool isLow);
|
||||
|
||||
void EvaluateItems(Entity_Player* player, int cacheFlag);
|
||||
int GetPillEffect(int pillEffect, int pillColor);
|
||||
void PostEntityKill(Entity* entity);
|
||||
void PostGameStart(bool isContinued);
|
||||
void PostKnifeInit(Entity_Knife* knife);
|
||||
void PostPlayerInit(Entity_Player* player);
|
||||
void PostRender();
|
||||
bool UseItem(LuaItemUse& use);
|
||||
void UsePill(int pillEffect, Entity_Player* player, unsigned int useFlags);
|
||||
};
|
||||
|
||||
const void* lua_class_key(LuaClass luaClass);
|
||||
Reference in new issue
Block a user