@@ -33,6 +33,7 @@ static std::map<PID, PID> sTypeDeclarations{};
3333static bool sIsInitialized {false };
3434static std::map<ID , pThingMakerTemplate_t> sThingMakers {};
3535static std::map<ID , int > sTypePriorities {};
36+ static std::map<ID , std::unordered_set<PID >> sTypeAncestors {};
3637static Tree<PID > sTypes {};
3738
3839bool ThingFactory::Init ()
@@ -117,6 +118,7 @@ Error ThingFactory::AddThing(pThingMakerTemplate_t inPtr,
117118 }
118119 sTypePriorities [inType] = inPriority;
119120 sThingMakers [inType] = inPtr;
121+ sTypeAncestors [inType] = sTypes .get_ancestors (inType);
120122 if (Console::GetVariable (" ThingFactory.debug_register_msgs" ).int_value )
121123 {
122124 if (inType == ThingType::Thing.name ())
@@ -160,7 +162,7 @@ PID ThingFactory::BaseOf(FPID inType) noexcept
160162{ return sTypes .get_node (inType).parent ; }
161163
162164bool ThingFactory::IsThing (FPID inTypeID)
163- { return sTypes . has_node (inTypeID) or sTypeDeclarations .contains (inTypeID); }
165+ { return sTypeAncestors . contains (inTypeID) or sTypeDeclarations .contains (inTypeID); }
164166
165167bool ThingFactory::IsThinker (FPID inTypeID)
166168{ return IsDerivedFrom (inTypeID, ThingType::Thinker); }
@@ -169,4 +171,7 @@ bool ThingFactory::IsResource(FPID inTypeID)
169171{ return IsDerivedFrom (inTypeID, ThingType::Resource); }
170172
171173bool ThingFactory::IsDerivedFrom (FPID inTypeID1, FPID inTypeID2)
172- { return inTypeID1 == inTypeID2 or sTypes .get_descendants (inTypeID2).contains (inTypeID1); }
174+ {
175+ return inTypeID1 == inTypeID2
176+ or (sTypeAncestors .contains (inTypeID1) and sTypeAncestors .at (inTypeID1).contains (inTypeID2));
177+ }
0 commit comments