Anatomy of a Game: Changing the Gamestate

Splorghley

Captain
41 Badges
Feb 10, 2012
405
865
The interface is only able to read the gamestate, and this is enforced by the code systems we have.

Out of curiosity, how do you enforce this? If another system wants to get data from the game state, can it just read that data directly? If so, assuming you're passing by reference, could the outside system then (inadvertently, perhaps) write directly into the game state?
 
  • 1
Reactions:

blackninja9939

Experienced Programmer - Crusader Kings 3
77 Badges
Aug 28, 2013
2.366
6.068
  • Crusader Kings III
  • Stellaris: Federations
  • Battle for Bosporus
  • Stellaris: Nemesis
  • Stellaris: Necroids
  • Europa Universalis IV
  • Crusader Kings III: Royal Edition
  • Europa Universalis 4: Emperor
  • Crusader Kings II
  • Crusader Kings II: Holy Fury
  • Imperator: Rome - Magna Graecia
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Old Gods
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Cradle of Civilization
  • Stellaris: Synthetic Dawn
  • Surviving Mars
  • BATTLETECH
  • Europa Universalis IV: Mandate of Heaven
  • Crusader Kings II: Monks and Mystics
  • Tyranny: Archon Edition
  • Europa Universalis IV: Rule Britannia
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: Colonel
  • Stellaris Sign-up
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Apocalypse
  • Stellaris: Lithoids
  • Stellaris: Distant Stars
  • Europa Universalis IV: Dharma
  • Shadowrun Returns
  • Imperator: Rome Deluxe Edition
  • Prison Architect
  • Imperator: Rome Sign Up
  • Stellaris: Ancient Relics
  • Age of Wonders: Planetfall
  • Crusader Kings II: Conclave
  • Crusader Kings II: The Republic
  • Victoria 2
  • Cities: Skylines
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Stellaris
  • Mount & Blade: Warband
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Legacy of Rome
Out of curiosity, how do you enforce this? If another system wants to get data from the game state, can it just read that data directly? If so, assuming you're passing by reference, could the outside system then (inadvertently, perhaps) write directly into the game state?
The function to get write access to the game state is not compiled into the interface module, so through using the "proper" functions you cannot get write access to data unless you start const casting things at which point all bets are off and you should feel bad anyway.
So its super hard to do accidental writes to the game state from the interface module.
 
  • 2
Reactions:

Splorghley

Captain
41 Badges
Feb 10, 2012
405
865
The function to get write access to the game state is not compiled into the interface module, so through using the "proper" functions you cannot get write access to data unless you start const casting things at which point all bets are off and you should feel bad anyway.
So its super hard to do accidental writes to the game state from the interface module.

Interesting! If the interface wants to fetch and display some state variable (e.g. character gold, or something), what's the official way to get it? Does the state module expose safe getter functions that return read-only versions of the various parts of the game state?
 

blackninja9939

Experienced Programmer - Crusader Kings 3
77 Badges
Aug 28, 2013
2.366
6.068
  • Crusader Kings III
  • Stellaris: Federations
  • Battle for Bosporus
  • Stellaris: Nemesis
  • Stellaris: Necroids
  • Europa Universalis IV
  • Crusader Kings III: Royal Edition
  • Europa Universalis 4: Emperor
  • Crusader Kings II
  • Crusader Kings II: Holy Fury
  • Imperator: Rome - Magna Graecia
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Old Gods
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Cradle of Civilization
  • Stellaris: Synthetic Dawn
  • Surviving Mars
  • BATTLETECH
  • Europa Universalis IV: Mandate of Heaven
  • Crusader Kings II: Monks and Mystics
  • Tyranny: Archon Edition
  • Europa Universalis IV: Rule Britannia
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: Colonel
  • Stellaris Sign-up
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Apocalypse
  • Stellaris: Lithoids
  • Stellaris: Distant Stars
  • Europa Universalis IV: Dharma
  • Shadowrun Returns
  • Imperator: Rome Deluxe Edition
  • Prison Architect
  • Imperator: Rome Sign Up
  • Stellaris: Ancient Relics
  • Age of Wonders: Planetfall
  • Crusader Kings II: Conclave
  • Crusader Kings II: The Republic
  • Victoria 2
  • Cities: Skylines
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Stellaris
  • Mount & Blade: Warband
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Legacy of Rome
Interesting! If the interface wants to fetch and display some state variable (e.g. character gold, or something), what's the official way to get it? Does the state module expose safe getter functions that return read-only versions of the various parts of the game state?
Yeah it uses the read only function to get a read only version of the game state so it can get read access to everything
 
  • 2
Reactions:

kdoole

Recruit
Aug 17, 2021
1
0
This is an amazing post!

I think I understand, but i think I have conflicts in my understanding.

1. There’s an initial phase during which all players are simultaneously deciding what to do for the next update, and it might include decisions which are made daily, monthly, yearly, whatever. This phase also includes updating UI. It’s a read-only phase.
2. The next phase allows actions that alter the game state to be carried out. Actions which are no longer valid are skipped.

During phase 1, if there’s an action that impacts game state that’s only visible to the one character, then it gets triggered immediately instead of getting added to the queue which is executed during phase 2. Do I have that right?

thanks again, really insightful post!