mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 13:23:56 -07:00
allow the ai to run without loading all templates at startup (not yet enabled).
This was SVN commit r20480.
This commit is contained in:
parent
1af6ccbd41
commit
3b6c612975
3 changed files with 10 additions and 23 deletions
|
|
@ -153,10 +153,10 @@ m.GameState.prototype.getTemplate = function(type)
|
|||
if (this.techTemplates[type] !== undefined)
|
||||
return new m.Technology(this.techTemplates, type);
|
||||
|
||||
if (!this.templates[type])
|
||||
return null;
|
||||
if (this.templates[type] === undefined)
|
||||
this.sharedScript.GetTemplate(type);
|
||||
|
||||
return new m.Template(this.sharedScript, type, this.templates[type]);
|
||||
return this.templates[type] ? new m.Template(this.sharedScript, type, this.templates[type]) : null;
|
||||
};
|
||||
|
||||
/** Return the template of the structure built from this foundation */
|
||||
|
|
@ -886,6 +886,8 @@ m.GameState.prototype.getEntityCounts = function()
|
|||
|
||||
m.GameState.prototype.isTemplateAvailable = function(templateName)
|
||||
{
|
||||
if (this.templates[templateName] === undefined)
|
||||
this.sharedScript.GetTemplate(templateName);
|
||||
return this.templates[templateName] && !this.isTemplateDisabled(templateName);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ m.SharedScript = function(settings)
|
|||
|
||||
this._players = Object.keys(settings.players).map(key => settings.players[key]); // TODO SM55 Object.values(settings.players)
|
||||
this._templates = settings.templates;
|
||||
this._derivedTemplates = {};
|
||||
this._techTemplates = settings.techTemplates;
|
||||
|
||||
this._entityMetadata = {};
|
||||
|
|
@ -49,28 +48,16 @@ m.SharedScript.prototype.Deserialize = function(data)
|
|||
this._templatesModifications = data.templatesModifications;
|
||||
this._entitiesModifications = data.entitiesModifications;
|
||||
this._entityMetadata = data.metadata;
|
||||
this._derivedTemplates = {};
|
||||
|
||||
this.isDeserialized = true;
|
||||
};
|
||||
|
||||
m.SharedScript.prototype.GetTemplate = function(name)
|
||||
{
|
||||
if (this._templates[name])
|
||||
return this._templates[name];
|
||||
if (this._templates[name] === undefined)
|
||||
this._templates[name] = Engine.GetTemplate(name) || null
|
||||
|
||||
if (this._derivedTemplates[name])
|
||||
return this._derivedTemplates[name];
|
||||
|
||||
let template = Engine.GetTemplate(name);
|
||||
if (template)
|
||||
{
|
||||
this._derivedTemplates[name] = template;
|
||||
return template;
|
||||
}
|
||||
|
||||
error("Tried to retrieve invalid template '"+name+"'");
|
||||
return null;
|
||||
return this._templates[name];
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -337,6 +337,8 @@ public:
|
|||
|
||||
CParamNode GetTemplate(const std::string& name)
|
||||
{
|
||||
if (!m_TemplateLoader.TemplateExists(name))
|
||||
return NULL;
|
||||
return m_TemplateLoader.GetTemplateFileData(name).GetChild("Entity");
|
||||
}
|
||||
|
||||
|
|
@ -641,10 +643,6 @@ public:
|
|||
templates[i].second->ToJSVal(cx, false, &val);
|
||||
m_ScriptInterface->SetProperty(m_EntityTemplates, templates[i].first.c_str(), val, true);
|
||||
}
|
||||
|
||||
// Since the template data is shared between AI players, freeze it
|
||||
// to stop any of them changing it and confusing the other players
|
||||
m_ScriptInterface->FreezeObject(m_EntityTemplates, true);
|
||||
}
|
||||
|
||||
void Serialize(std::ostream& stream, bool isDebug)
|
||||
|
|
|
|||
Loading…
Reference in a new issue