(SiLoader) Remove Replace directive recursion (#705)

This commit is contained in:
Christian Semmler 2025-09-04 09:36:26 -07:00 committed by GitHub
parent ace6b7fc7e
commit cbc51e8148
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 20 deletions

View File

@ -47,7 +47,7 @@ class SiLoader {
static bool LoadFile(const char* p_file); static bool LoadFile(const char* p_file);
static bool LoadDirective(const char* p_directive); static bool LoadDirective(const char* p_directive);
static MxStreamController* OpenStream(const char* p_file); static MxStreamController* OpenStream(const char* p_file);
static void ParseExtra(const MxAtomId& p_atom, si::Core* p_core, MxAtomId p_parentReplacedAtom = MxAtomId()); static void ParseExtra(const MxAtomId& p_atom, si::Core* p_core);
static bool IsWorld(const StreamObject& p_object); static bool IsWorld(const StreamObject& p_object);
}; };

View File

@ -316,11 +316,9 @@ MxStreamController* SiLoader::OpenStream(const char* p_file)
return controller; return controller;
} }
void SiLoader::ParseExtra(const MxAtomId& p_atom, si::Core* p_core, MxAtomId p_parentReplacedAtom) void SiLoader::ParseExtra(const MxAtomId& p_atom, si::Core* p_core)
{ {
for (si::Core* child : p_core->GetChildren()) { for (si::Core* child : p_core->GetChildren()) {
MxAtomId replacedAtom = p_parentReplacedAtom;
if (si::Object* object = dynamic_cast<si::Object*>(child)) { if (si::Object* object = dynamic_cast<si::Object*>(child)) {
if (object->type() != si::MxOb::Null) { if (object->type() != si::MxOb::Null) {
std::string extra(object->extra_.data(), object->extra_.size()); std::string extra(object->extra_.data(), object->extra_.size());
@ -346,21 +344,12 @@ void SiLoader::ParseExtra(const MxAtomId& p_atom, si::Core* p_core, MxAtomId p_p
} }
} }
if (p_parentReplacedAtom.GetInternal()) { if ((directive = SDL_strstr(extra.c_str(), "Replace:"))) {
replace.emplace_back( if (SDL_sscanf(directive, "Replace:%255[^:;]%*[:;]%u", atom, &id) == 2) {
StreamObject{p_parentReplacedAtom, object->id_}, replace.emplace_back(
StreamObject{p_atom, object->id_} StreamObject{MxAtomId{atom, e_lowerCase2}, id},
); StreamObject{p_atom, object->id_}
} );
else {
if ((directive = SDL_strstr(extra.c_str(), "Replace:"))) {
if (SDL_sscanf(directive, "Replace:%255[^:;]%*[:;]%u", atom, &id) == 2) {
replace.emplace_back(
StreamObject{MxAtomId{atom, e_lowerCase2}, id},
StreamObject{p_atom, object->id_}
);
replacedAtom = replace.back().first.first;
}
} }
} }
@ -383,7 +372,7 @@ void SiLoader::ParseExtra(const MxAtomId& p_atom, si::Core* p_core, MxAtomId p_p
} }
} }
ParseExtra(p_atom, child, replacedAtom); ParseExtra(p_atom, child);
} }
} }