1
0
forked from 0ad/0ad

Use Set instead of an Object with unused values in TechnologyManager.researchStarted.

Differential Revision: https://code.wildfiregames.com/D1129
Reviewed By: mimo
This was SVN commit r20611.
This commit is contained in:
elexis 2017-12-08 18:47:07 +00:00
parent a6f14f5631
commit dc72833040
4 changed files with 20 additions and 16 deletions

View File

@ -225,7 +225,7 @@ m.GameState.prototype.isResearched = function(template)
/** true if started or queued */
m.GameState.prototype.isResearching = function(template)
{
return this.playerData.researchStarted[template] !== undefined ||
return this.playerData.researchStarted.has(template) ||
this.playerData.researchQueued[template] !== undefined;
};
@ -241,7 +241,7 @@ m.GameState.prototype.canResearch = function(techTemplateName, noRequirementChec
// researching or already researched: NOO.
if (this.playerData.researchQueued[techTemplateName] ||
this.playerData.researchStarted[techTemplateName] ||
this.playerData.researchStarted.has(techTemplateName) ||
this.playerData.researchedTechs.has(techTemplateName))
return false;
@ -253,7 +253,7 @@ m.GameState.prototype.canResearch = function(techTemplateName, noRequirementChec
{
let other = template.pairedWith();
if (this.playerData.researchQueued[other] ||
this.playerData.researchStarted[other] ||
this.playerData.researchStarted.has(other) ||
this.playerData.researchedTechs.has(other))
return false;
}

View File

@ -704,7 +704,7 @@ GuiInterface.prototype.GetStartedResearch = function(player)
return {};
let ret = {};
for (let tech in cmpTechnologyManager.GetStartedTechs())
for (let tech of cmpTechnologyManager.GetStartedTechs())
{
ret[tech] = { "researcher": cmpTechnologyManager.GetResearcher(tech) };
let cmpProductionQueue = Engine.QueryInterface(ret[tech].researcher, IID_ProductionQueue);

View File

@ -24,7 +24,9 @@ TechnologyManager.prototype.Init = function()
this.researchedTechs = new Set();
this.researchQueued = {}; // technologies which are queued for research
this.researchStarted = {}; // technologies which are being researched currently (non-queued)
// technologies which are being researched currently (non-queued)
this.researchStarted = new Set();
// This stores the modifications to unit stats from researched technologies
// Example data: {"ResourceGatherer/Rates/food.grain": [
@ -101,7 +103,7 @@ TechnologyManager.prototype.IsTechnologyResearched = function(tech)
TechnologyManager.prototype.IsTechnologyStarted = function(tech)
{
return this.researchStarted[tech] !== undefined;
return this.researchStarted.has(tech);
};
// Checks the requirements for a technology to see if it can be researched at the current time
@ -400,7 +402,7 @@ TechnologyManager.prototype.QueuedResearch = function(tech, researcher)
// Marks a technology as actively being researched
TechnologyManager.prototype.StartedResearch = function(tech, notification)
{
this.researchStarted[tech] = true;
this.researchStarted.add(tech);
if (notification && tech.startsWith("phase"))
{
@ -418,7 +420,7 @@ TechnologyManager.prototype.StartedResearch = function(tech, notification)
// Marks a technology as not being currently researched
TechnologyManager.prototype.StoppedResearch = function(tech, notification)
{
if (notification && tech.startsWith("phase") && this.researchStarted[tech])
if (notification && tech.startsWith("phase") && this.researchStarted.has(tech))
{
let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
@ -431,7 +433,7 @@ TechnologyManager.prototype.StoppedResearch = function(tech, notification)
}
delete this.researchQueued[tech];
delete this.researchStarted[tech];
this.researchStarted.delete(tech);
};
// Checks whether a technology is set to be researched
@ -443,7 +445,9 @@ TechnologyManager.prototype.IsInProgress = function(tech)
return false;
};
// Get all techs that are currently being researched
/**
* Returns the names of technologies that are currently being researched (non-queued).
*/
TechnologyManager.prototype.GetStartedTechs = function()
{
return this.researchStarted;

View File

@ -126,7 +126,7 @@ AddMock(100, IID_EntityLimits, {
AddMock(100, IID_TechnologyManager, {
IsTechnologyResearched: function(tech) { if (tech == "phase_village") return true; else return false; },
GetQueuedResearch: function() { return {}; },
GetStartedTechs: function() { return {}; },
GetStartedTechs: function() { return new Set(); },
GetResearchedTechs: function() { return {}; },
GetClassCounts: function() { return {}; },
GetTypeCountsByClass: function() { return {}; },
@ -212,7 +212,7 @@ AddMock(101, IID_EntityLimits, {
AddMock(101, IID_TechnologyManager, {
IsTechnologyResearched: function(tech) { if (tech == "phase_village") return true; else return false; },
GetQueuedResearch: function() { return {}; },
GetStartedTechs: function() { return {}; },
GetStartedTechs: function() { return new Set(); },
GetResearchedTechs: function() { return {}; },
GetClassCounts: function() { return {}; },
GetTypeCountsByClass: function() { return {}; },
@ -296,7 +296,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
entityCounts: {"Foo": 5},
entityLimitChangers: {"Foo": {}},
researchQueued: {},
researchStarted: {},
researchStarted: new Set(),
researchedTechs: new Set(),
classCounts: {},
typeCountsByClass: {},
@ -345,7 +345,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
entityCounts: {"Bar": 0},
entityLimitChangers: {"Bar": {}},
researchQueued: {},
researchStarted: {},
researchStarted: new Set(),
researchedTechs: new Set(),
classCounts: {},
typeCountsByClass: {},
@ -403,7 +403,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
"entityCounts": {"Foo": 5},
"entityLimitChangers": {"Foo": {}},
"researchQueued": {},
"researchStarted": {},
"researchStarted": new Set(),
"researchedTechs": new Set(),
"classCounts": {},
"typeCountsByClass": {},
@ -475,7 +475,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
"entityCounts": {"Bar": 0},
"entityLimitChangers": {"Bar": {}},
"researchQueued": {},
"researchStarted": {},
"researchStarted": new Set(),
"researchedTechs": new Set(),
"classCounts": {},
"typeCountsByClass": {},