forked from Mirrors/openclonk
Add DefinitionPriority property to control call order of Definition()-callbacks.
parent
c4dfd5e276
commit
397dbd867a
|
@ -33,6 +33,11 @@
|
|||
<col>Parameter</col>
|
||||
<col>Description</col>
|
||||
</rowh>
|
||||
<row id="Initialize">
|
||||
<literal_col>Definition</literal_col>
|
||||
<col></col>
|
||||
<col>Called in definition context after all definitions have been loaded and before definition properties are frozen. Use this callback to initialize complex definition properties such as EditorProps or dependencies between definitions. Definition() callbacks are performed in descending order of the DefinitionPriority property or 0 if that property is not defined.</col>
|
||||
</row>
|
||||
<row id="Initialize">
|
||||
<literal_col>Initialize</literal_col>
|
||||
<col></col>
|
||||
|
|
|
@ -453,6 +453,32 @@ void C4DefList::ResetIncludeDependencies()
|
|||
it->second->ResetIncludeDependencies();
|
||||
}
|
||||
|
||||
void C4DefList::SortByPriority()
|
||||
{
|
||||
// Sort all definitions by DefinitionPriority property (descending)
|
||||
// Build vector of definitions
|
||||
int32_t n = GetDefCount();
|
||||
if (!n) return;
|
||||
std::vector<C4Def *> def_vec;
|
||||
def_vec.reserve(n);
|
||||
for (C4Def *def = FirstDef; def; def = def->Next)
|
||||
def_vec.push_back(def);
|
||||
// Sort it
|
||||
std::stable_sort(def_vec.begin(), def_vec.end(), [](C4Def *a, C4Def *b) {
|
||||
return b->GetPropertyInt(P_DefinitionPriority) < a->GetPropertyInt(P_DefinitionPriority);
|
||||
});
|
||||
// Restore linked list in new definition order
|
||||
C4Def *prev_def = nullptr;
|
||||
for (C4Def *def : def_vec)
|
||||
{
|
||||
if (prev_def)
|
||||
prev_def->Next = def;
|
||||
else
|
||||
FirstDef = def;
|
||||
prev_def = def;
|
||||
}
|
||||
}
|
||||
|
||||
void C4DefList::CallEveryDefinition()
|
||||
{
|
||||
for (C4Def *def = FirstDef; def; def = def->Next)
|
||||
|
@ -465,6 +491,7 @@ void C4DefList::CallEveryDefinition()
|
|||
strncpy(sz, def->id.ToString(), 32+1);
|
||||
AddDbgRec(RCT_Definition, sz, 32);
|
||||
}
|
||||
LogF(def->GetName());
|
||||
C4AulParSet Pars(def);
|
||||
def->Call(PSF_Definition, &Pars);
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
void BuildTable();
|
||||
void ResetIncludeDependencies(); // resets all pointers into foreign definitions caused by include chains
|
||||
void CallEveryDefinition();
|
||||
void SortByPriority();
|
||||
void Synchronize();
|
||||
void AppendAndIncludeSkeletons();
|
||||
StdMeshSkeletonLoader& GetSkeletonLoader();
|
||||
|
|
|
@ -157,7 +157,10 @@ void C4AulScriptEngine::Link(C4DefList *rDefs)
|
|||
s->Parse();
|
||||
|
||||
if (rDefs)
|
||||
{
|
||||
rDefs->SortByPriority();
|
||||
rDefs->CallEveryDefinition();
|
||||
}
|
||||
|
||||
// Done modifying the proplists now
|
||||
for (C4ScriptHost *s = Child0; s; s = s->Next)
|
||||
|
|
|
@ -268,6 +268,7 @@ C4StringTable::C4StringTable()
|
|||
P[P_CopyDefault] = "CopyDefault";
|
||||
P[P_Display] = "Display";
|
||||
P[P_DefaultValue] = "DefaultValue";
|
||||
P[P_DefinitionPriority] = "DefinitionPriority";
|
||||
P[DFA_WALK] = "WALK";
|
||||
P[DFA_FLIGHT] = "FLIGHT";
|
||||
P[DFA_KNEEL] = "KNEEL";
|
||||
|
|
|
@ -492,6 +492,7 @@ enum C4PropertyName
|
|||
P_CopyDefault,
|
||||
P_Display,
|
||||
P_DefaultValue,
|
||||
P_DefinitionPriority,
|
||||
// Default Action Procedures
|
||||
DFA_WALK,
|
||||
DFA_FLIGHT,
|
||||
|
|
Loading…
Reference in New Issue