mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-28 23:13:02 +00:00
Binary search Lua struct fields
This commit is contained in:
parent
1269eef048
commit
3274fca929
2 changed files with 19 additions and 5 deletions
|
@ -46,8 +46,6 @@ struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
override_field_names = {
|
override_field_names = {
|
||||||
"Animation": { "unk02": "animYTransDivisor", "unk04": "startFrame", "unk06": "loopStart", "unk08": "loopEnd", "unk0A": "unusedBoneCount" },
|
|
||||||
"GraphNodeObject": { "unk38": "animInfo" },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override_field_types = {
|
override_field_types = {
|
||||||
|
|
|
@ -33,12 +33,28 @@ static struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LuaObjectTable* ot = &sLuaObjectTable[lot];
|
struct LuaObjectTable* ot = &sLuaObjectTable[lot];
|
||||||
// TODO: change this to binary search or hash table or something
|
|
||||||
for (int i = 0; i < ot->fieldCount; i++) {
|
// binary search
|
||||||
if (!strcmp(ot->fields[i].key, key)) {
|
int min = 0;
|
||||||
|
int max = ot->fieldCount - 1;
|
||||||
|
int i = (min + max) / 2;
|
||||||
|
while (true) {
|
||||||
|
int rc = strcmp(key, ot->fields[i].key);
|
||||||
|
if (rc == 0) {
|
||||||
return &ot->fields[i];
|
return &ot->fields[i];
|
||||||
|
} else if (rc < 0) {
|
||||||
|
max = i - 1;
|
||||||
|
i = (min + max) / 2;
|
||||||
|
} else if (rc > 0) {
|
||||||
|
min = i + 1;
|
||||||
|
i = (min + max) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (min > max || max < min) {
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue