diff --git a/autogen/convert_structs.py b/autogen/convert_structs.py index 224535fe..3025ca0b 100644 --- a/autogen/convert_structs.py +++ b/autogen/convert_structs.py @@ -37,13 +37,7 @@ $[INCLUDES] $[BODY] struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key) { struct LuaObjectTable* ot = &sLuaObjectAutogenTable[lot - LOT_AUTOGEN_MIN - 1]; - // TODO: change this to binary search or hash table or something - for (int i = 0; i < ot->fieldCount; i++) { - if (!strcmp(ot->fields[i].key, key)) { - return &ot->fields[i]; - } - } - return NULL; + return smlua_get_object_field_from_ot(ot, key); } """ diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c index 4ba2ae42..c4f678f9 100644 --- a/src/pc/lua/smlua_cobject.c +++ b/src/pc/lua/smlua_cobject.c @@ -33,13 +33,7 @@ struct LuaObjectTable sLuaObjectTable[LOT_MAX] = { { LOT_VEC3F, sVec3fFields, LUA_VEC3F_FIELD_COUNT }, }; -struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key) { - if (lot > LOT_AUTOGEN_MIN) { - return smlua_get_object_field_autogen(lot, key); - } - - struct LuaObjectTable* ot = &sLuaObjectTable[lot]; - +struct LuaObjectField* smlua_get_object_field_from_ot(struct LuaObjectTable* ot, const char* key) { // binary search s32 min = 0; s32 max = ot->fieldCount - 1; @@ -64,6 +58,15 @@ struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key) { return NULL; } +struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key) { + if (lot > LOT_AUTOGEN_MIN) { + return smlua_get_object_field_autogen(lot, key); + } + + struct LuaObjectTable* ot = &sLuaObjectTable[lot]; + return smlua_get_object_field_from_ot(ot, key); +} + bool smlua_valid_lot(u16 lot) { if (lot > LOT_NONE && lot < LOT_MAX) { return true; } if (lot > LOT_AUTOGEN_MIN && lot < LOT_AUTOGEN_MAX) { return true; } diff --git a/src/pc/lua/smlua_cobject.h b/src/pc/lua/smlua_cobject.h index cf9acd7c..898c4320 100644 --- a/src/pc/lua/smlua_cobject.h +++ b/src/pc/lua/smlua_cobject.h @@ -60,6 +60,7 @@ struct LuaObjectTable { bool smlua_valid_lot(u16 lot); bool smlua_valid_lvt(u16 lvt); +struct LuaObjectField* smlua_get_object_field_from_ot(struct LuaObjectTable* ot, const char* key); struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key); struct LuaObjectField* smlua_get_custom_field(lua_State* L, u32 lot, int keyIndex); void smlua_cobject_init_globals(void); diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index c3ac4768..d7929493 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -1957,12 +1957,6 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN] struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key) { struct LuaObjectTable* ot = &sLuaObjectAutogenTable[lot - LOT_AUTOGEN_MIN - 1]; - // TODO: change this to binary search or hash table or something - for (int i = 0; i < ot->fieldCount; i++) { - if (!strcmp(ot->fields[i].key, key)) { - return &ot->fields[i]; - } - } - return NULL; + return smlua_get_object_field_from_ot(ot, key); } diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 2b3a4ea2..8c64ede2 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -9,9 +9,6 @@ #include "game/print.h" #include "gfx_dimensions.h" -extern u64 SDL_GetPerformanceCounter(void); -extern u64 SDL_GetPerformanceFrequency(void); - #define MAX_PROFILED_MODS 16 #define REFRESH_RATE 15