HomeWildfire Games

Split tasks from ProductionQueue.
AuditedrP26000

Description

Split tasks from ProductionQueue.

The task of the production queue should first and foremost be that; a queue for production items.
Hence, the specifics of training/researching are delegated to specific components.

As a side effect, this improves the test coverage and fixes:

  • Resource not refunding when hitting the entity limit. Introduced in r25753 / rP25753.
  • Autoqueue changing when unable to spawn. Introduced in r25779 / rP25779.

Modders can change their templates using https://code.wildfiregames.com/P256.

Differential revision: https://code.wildfiregames.com/D4333
Fixes: #6363
Comments by: @Silier
Refs. #6364

Event Timeline

Silier added inline comments.Nov 17 2021, 3:58 PM
/ps/trunk/binaries/data/mods/public/simulation/components/ProductionQueue.js
49

this should be inlined

65

if this is -1 ?

158

so here you are saying it is or technology or entity while else in the code it looks like it can be both at the same time. which case it is?

314

this and below can be more generic and branches can be removed

317

if it is or technology or unit at the same time, why dont pass interface ID to item on creation and make both interfaces implementing same functions so they can be called without branching.
Also that would make it possible to remove this.entity and this.technology and have just this.item or something

/ps/trunk/binaries/data/mods/public/simulation/components/Researcher.js
224

why not inlined

Silier added inline comments.Nov 17 2021, 4:01 PM
/ps/trunk/binaries/data/mods/public/simulation/components/ProductionQueue.js
314

ok, wrong comment, but still can be merged into one here and checked in item

Freagarach marked 7 inline comments as done.Nov 18 2021, 7:02 PM
Freagarach added inline comments.
/ps/trunk/binaries/data/mods/public/simulation/components/ProductionQueue.js
158

I didn't want to modify the GUI (too much) in this patch. Hence I assumed here (and at the addition stage) only one of the two is possible. But the rest is flexible enough for it to be implemented some day.

317

Because e.g. the Researcher don't need the count, so their interfaces are different.
Also, someone might want to implement queuing both at the same time.

/ps/trunk/binaries/data/mods/public/simulation/components/Researcher.js
224

Since this was a (almost straight) copy-pasta.

Silier raised a concern with this commit.Nov 28 2021, 7:54 AM

See comments on diff

This commit now has outstanding concerns.Nov 28 2021, 7:54 AM
/ps/trunk/binaries/data/mods/public/simulation/helpers/Cheat.js
80

you wanted call Init probably instead

Freagarach marked 4 inline comments as done.Dec 13 2021, 8:39 AM
Freagarach requested verification of this commit.Dec 17 2021, 4:35 PM
This commit now requires verification by auditors.Dec 17 2021, 4:35 PM
nwtour raised a concern with this commit.Dec 21 2021, 1:23 AM
nwtour added a subscriber: nwtour.

by the name of the files the error of this commit
After loading from the save file:

ERROR: JavaScript error: simulation/components/GuiInterface.js line 703
research is undefined
  GuiInterface.prototype.GetStartedResearch@simulation/components/GuiInterface.js:703:4
  GuiInterface.prototype.ScriptCall@simulation/components/GuiInterface.js:2155:20
  updateResearchProgress@gui/session/ResearchProgress.js:30:32
  onSimulationUpdate@gui/session/session.js:675:3
  resetTemplates@gui/session/session.js:448:2
  onSelectionChange@gui/session/top_panel/PlayerViewControl.js:119:4
  selectViewPlayer@gui/session/top_panel/PlayerViewControl.js:81:3
  onPlayersInit@gui/session/top_panel/PlayerViewControl.js:60:8
  init@gui/session/session.js:319:3
  reallyStartGame@gui/loading/loading.js:22:9
ERROR: Error calling component script function ScriptCall
WARNING: GetPlayerByID: no player defined for id 'undefined'
  PlayerManager.prototype.GetPlayerByID@simulation/components/PlayerManager.js:98:14
  QueryPlayerIDInterface@simulation/helpers/Player.js:244:35
  Researcher.prototype.Item.prototype.Start@simulation/components/Researcher.js:95:53
  Researcher.prototype.Item.prototype.Progress@simulation/components/Researcher.js:118:8
  Researcher.prototype.Progress@simulation/components/Researcher.js:430:24
  ProductionQueue.prototype.Item.prototype.Progress@simulation/components/ProductionQueue.js:136:34
  ProductionQueue.prototype.ProgressTimeout@simulation/components/ProductionQueue.js:424:16
  Timer.prototype.OnUpdate@simulation/components/Timer.js:139:44
ERROR: Error in timer on entity 150, IID80, function ProgressTimeout: TypeError: cmpTechnologyManager is null
  Researcher.prototype.Item.prototype.Start@simulation/components/Researcher.js:96:2
  Researcher.prototype.Item.prototype.Progress@simulation/components/Researcher.js:118:8
  Researcher.prototype.Progress@simulation/components/Researcher.js:430:24
  ProductionQueue.prototype.Item.prototype.Progress@simulation/components/ProductionQueue.js:136:34
  ProductionQueue.prototype.ProgressTimeout@simulation/components/ProductionQueue.js:424:16
  Timer.prototype.OnUpdate@simulation/components/Timer.js:139:44

ERROR: JavaScript error: simulation/components/GuiInterface.js line 703
research is undefined
  GuiInterface.prototype.GetStartedResearch@simulation/components/GuiInterface.js:703:4
  GuiInterface.prototype.ScriptCall@simulation/components/GuiInterface.js:2155:20
  updateResearchProgress@gui/session/ResearchProgress.js:30:32
  onSimulationUpdate@gui/session/session.js:675:3
  __eventhandler10 (SimulationUpdate)@session SimulationUpdate:1:1
ERROR: Error calling component script function ScriptCall
WARNING: GetPlayerByID: no player defined for id 'undefined'
  PlayerManager.prototype.GetPlayerByID@simulation/components/PlayerManager.js:98:14
  QueryPlayerIDInterface@simulation/helpers/Player.js:244:35
  Researcher.prototype.Item.prototype.Start@simulation/components/Researcher.js:95:53
  Researcher.prototype.Item.prototype.Progress@simulation/components/Researcher.js:118:8
  Researcher.prototype.Progress@simulation/components/Researcher.js:430:24
  ProductionQueue.prototype.Item.prototype.Progress@simulation/components/ProductionQueue.js:136:34
  ProductionQueue.prototype.ProgressTimeout@simulation/components/ProductionQueue.js:424:16
  Timer.prototype.OnUpdate@simulation/components/Timer.js:139:44
ERROR: Error in timer on entity 2038, IID80, function ProgressTimeout: TypeError: cmpTechnologyManager is null
  Researcher.prototype.Item.prototype.Start@simulation/components/Researcher.js:96:2
  Researcher.prototype.Item.prototype.Progress@simulation/components/Researcher.js:118:8
  Researcher.prototype.Progress@simulation/components/Researcher.js:430:24
  ProductionQueue.prototype.Item.prototype.Progress@simulation/components/ProductionQueue.js:136:34
  ProductionQueue.prototype.ProgressTimeout@simulation/components/ProductionQueue.js:424:16
  Timer.prototype.OnUpdate@simulation/components/Timer.js:139:44

WARNING: GetPlayerByID: no player defined for id 'undefined'
  PlayerManager.prototype.GetPlayerByID@simulation/components/PlayerManager.js:98:14
  QueryPlayerIDInterface@simulation/helpers/Player.js:244:35
  Researcher.prototype.Item.prototype.Start@simulation/components/Researcher.js:95:53
  Researcher.prototype.Item.prototype.Progress@simulation/components/Researcher.js:118:8
  Researcher.prototype.Progress@simulation/components/Researcher.js:430:24
  ProductionQueue.prototype.Item.prototype.Progress@simulation/components/ProductionQueue.js:136:34
  ProductionQueue.prototype.ProgressTimeout@simulation/components/ProductionQueue.js:424:16
  Timer.prototype.OnUpdate@simulation/components/Timer.js:139:44
ERROR: Error in timer on entity 2051, IID80, function ProgressTimeout: TypeError: cmpTechnologyManager is null
  Researcher.prototype.Item.prototype.Start@simulation/components/Researcher.js:96:2
  Researcher.prototype.Item.prototype.Progress@simulation/components/Researcher.js:118:8
  Researcher.prototype.Progress@simulation/components/Researcher.js:430:24
  ProductionQueue.prototype.Item.prototype.Progress@simulation/components/ProductionQueue.js:136:34
  ProductionQueue.prototype.ProgressTimeout@simulation/components/ProductionQueue.js:424:16
  Timer.prototype.OnUpdate@simulation/components/Timer.js:139:44

ERROR: JavaScript error: simulation/components/GuiInterface.js line 703
research is undefined
  GuiInterface.prototype.GetStartedResearch@simulation/components/GuiInterface.js:703:4
  GuiInterface.prototype.ScriptCall@simulation/components/GuiInterface.js:2155:20
  updateResearchProgress@gui/session/ResearchProgress.js:30:32
  onSimulationUpdate@gui/session/session.js:675:3
  __eventhandler10 (SimulationUpdate)@session SimulationUpdate:1:1
ERROR: Error calling component script function ScriptCall
This commit now has outstanding concerns.Dec 21 2021, 1:23 AM

That error is introduced in rP26084.

Freagarach requested verification of this commit.Dec 24 2021, 9:18 AM
This commit now requires verification by auditors.Dec 24 2021, 9:18 AM
nwtour accepted this commit.Dec 24 2021, 10:00 AM
Silier accepted this commit.Dec 24 2021, 12:34 PM
All concerns with this commit have now been addressed.Dec 24 2021, 12:34 PM
ValihrAnt raised a concern with this commit.Dec 25 2021, 11:16 AM
ValihrAnt added a subscriber: ValihrAnt.

Getting errors when selecting Maurya Palace on r26109

This commit now has outstanding concerns.Dec 25 2021, 11:16 AM
All concerns with this commit have now been addressed.Jan 1 2022, 8:33 PM
Freagarach added inline comments.Jan 12 2022, 7:53 AM
/ps/trunk/binaries/data/mods/public/gui/session/input.js
1406

undefined != -1 #6415