Opened 5 years ago

Last modified 8 months ago

#2826 new task

Refactor the state machine in input.js

Reported by: Rolf Sievers Owned by:
Priority: Should Have Milestone: Backlog
Component: UI – In-game Keywords:
Cc: Patch:

Description (last modified by Imarok)

In the binaries/data/mods/public/gui/session/input.js file, there is a comment which reads:

// TODO: it'd probably be nice to have a better state-machine system, with guaranteed
// entry/exit functions, since this is a bit broken now

What is there

A rather basic implementation of one concrete state machine. (no abstraction) On closer inspection, it turns out those are actually a bunch of smaller state machines glued together along their entry and exit paths to a „default state.“ There is a second state machine as well, for postGui event processing.

Proposed change

A lightweight abstract system which does not know a lot about it's content. It has a state (Bandboxing, Building, Tribute), such a state describes the mechanics of a „smaller state machine“ from the current code. The outer wrapper is not a state machine (no transitions) as it does not posses any interesting feature. The inner state is not forced to be a state machine, it's internal structure is not inspected by the outer wrapper. As most of the „smaller state machines“ have just a single state, that prevents unnecessary abstraction.

This untangles all the different features contained in that one function.

Furthermore the central code of preEngine event handling and postEngine event handling can be unified.

Interface of a „state“

Without specifying any particular structure yet, a state must allow the following:

  • Initializing it (The state receives a quitCallback to terminate itself)
  • Processing an event (returns whether it was eaten or not)
  • Terminating it

Obvious solutions would be:

  • pass three parameters
  • pass an object

Change History (6)

comment:1 Changed 5 years ago by Rolf Sievers

Description: modified (diff)

comment:2 Changed 5 years ago by Rolf Sievers

Description: modified (diff)

comment:3 Changed 5 years ago by Rolf Sievers

Description: modified (diff)

comment:4 Changed 5 years ago by Itms

Description: modified (diff)
Milestone: Alpha 18Backlog
Owner: Rolf Sievers deleted
Summary: Refactor the state machine in binaries/data/mods/public/gui/session/input.jsRefactor the state machine in input.js

Backlogging this due to stopped activity.

comment:5 Changed 8 months ago by Imarok

Description: modified (diff)
Priority: If Time PermitsShould Have

Pretty relevant, as input.js is really clogged and error-prone.

Last edited 8 months ago by Imarok (previous) (diff)

comment:6 Changed 8 months ago by Imarok

Component: UI & SimulationIn-game UI

Move tickets to In-game UI as UI & Simulation got some sub components.

Note: See TracTickets for help on using tickets.