Thrive
Table of Contents
1. Stage
Top-level scene management.
Base classes are under the directory src/general/base_stage
classStageBaseNodeworld: The World Godot nodeNode: This is the Godot node that sprites are added.PauseMenupauseMenuControlhudrootboolgameoverGameWorldGameWorldvirtual voidSetupStage(): call virtual void OnGameStartedvoid_Process(double delta): load stage if not loaded, andGameWorld.Process((float)delta)
classCreatureStageBase<TPlsyer, TSimulation> : StageBaseTSimulationWorldSimulationoverride void_Process(double delta): pass to StageBase, handle respawn and extinction
1.1. MicrobeStage
Under the directory src/microbe_stage
classMicrobeStage: CreatureStageBase<Entity,>override void_Ready(): Setup HUD, fluid current, and SetupStageoverride voidSetupStage(): initializes system and cloud, and call OnGameStarted via base.SetupStageoverride voidOnGameStarted(): call SpawnPlayeroverride voidSpawnPlayer()spawn using SpawnMicrobeWithoutFinalizing and attach player specific componentsoverride void_Process(double delta): call base.Process, and run ProcessAll
2. GameWorld
The global informations of the world, in contrast to the information about the world that we can see: World.
classGameWorldDictionary<uint, Species>worldSpeciesTimedWorldOperationsTimedEffectsSpeciesPlayerSpeciesPatchMapMapMicrobeSpeciesCreatePlayerSpecies()DayNightCycleLightCyclevoidProcess(float delta):LightCycle.Process(delta)- GameWorld
(WroldGenerationSettings settings, Species? startingSpecies = null): add effects to the game, create the player cell,
3. Physical World
Under the directory src/engine/physics,
which uses the library in src/native/ which is compiled against third_party/JoltPhysics/.
classPhysicalWorld- ProcessPhysics
3.0.1. NativePhysicsBody
It contains the IntPtr called nativeInstance, which is used in the physical world.
4. WorldSimulation
Base under src/general/base_stage
abstract classWorldSimulationprotected readonly Worldentites:Arch.Core.Worldfrom the Arch ECSWorldEntitySystem: wrapper for the readonly variable entities.World EntitySystem => entities;meansWorld EntitySystem { get { return entities; } }
Vector3PlayerPositionfloatWorldTimeScale: default to 1bool(float delta): runProcessLogic(delta)andProcessFrameLogic(delta)virtual boolProcessLogic(float delta): runOnProcesFixedLogic(accumulatedLogicTime), andOnProcessPhysics(accumulatedLogicTime)- Not overrided by MicrobeWorldSimulation
voidProcessFrameLogic(float delta): runOnProcessFrameLogic(delta)virtual voidOnProcessPhysics(float delta): runWaitForStartedPhysicsRun()andOnStartPhysicsRunIfTime(delta)- Not overrided by MicrobeWroldSimulation
- above call back functions are defined as
abstractmethods here
abstract voidOnProcessFixedLogic(float delta)
classWorldSimulationWithPhysics: WorldSimulationPhysicalWorldPhysicalWorld (equal to "physics")List<NativePhysicsBody>createdBodiesoverride voidWaitForStartedPhysicsRun(): runphysics.WaitUntilPhysicsRunEnds()override voidOnStartPhysicsRunIfTime(float delta): runphysics.ProcessPhysics(delta)
class partialMicrobeWorldSimulation: WorldSimulationWithPhysicsoverride voidOnProcessFixedLogic(float delta): call either OnProcessFixedWithThreads or OnProcessFixedWithoutThreads defined in the separte .generated fileoverride voidOnProcessFrameLogic(float delta): call OnProcessFrameLogicGenerated defined in .generated file
5. Components
Defined in the Components namespace
5.1. Common Components
5.1.1. SpatialInstance
The Godot node container
classSpatialInstanceNode3D?GraphicalInstance: the Godot node
5.1.2. Physics
5.1.3. WorldPosition
classWorldPosition: IArchivableComponentVector3PositionQuaternionRotation
6. Systems
Defined in the Systems namespace.
In src/engine/common_systems
PhysicsBodyCreationSystemcreate Jolt physics body if there is nonePhysicsCollisionManagementSystemmanagesCollisionManagementcomponent and progapages the collision events to other systems.PhysicsUpdateAndPositionSystemread physical position and rotation and store them into entity'sworldPosition
6.1. Common Systems
6.1.1. SpatialAttachSystem
classSpatialAttachSystem: AComponentSystem<float, SpatialInstance>NodegodotWorldRoot: it is the visualsParent, that is, rootOfDynamicallySpawned.Dictionary<Node3D, AttachedInfo>attachedSpatialInstancesoverride voidUpdate(float state, Span<SpatialInstance components)attach only not attached components, such as microbes and minerals, to the godotWorldRoot
6.1.2. SpatialPositionSystem
Transform the graphicalInstance based on the WorldPosition of the entity
classSpatialPositionSystem
6.1.3. Physical World to Screen
classPhysicsUpdateAndPositionSystem- Update the WorldPosition (includes position and rotation) to the physical world position.
classSpatialPositionSystem- Transform the Godot node into the WorldPosition.
6.1.4. PhysicsBodyControlSystem
This is a fallback mechanism when we don't use physical world for the motion, or we don't use it altogether.
The velocity of Physics component is applied to the body in the physical world when VelocityApplied is set to false.
6.2. Microbe Systems
Microbe under src/microbe_stage
classMicrobeWorldSimulation: WorldSimulationWithPhysicsNode: the Godot nodes where entities are attachedvoidInit(Node visualDisplayRoot, CompoundCloudSystem cloudSystem, IMicrobeSpawnEnvironment spawnEnvironment)Set the rootOfDynamicallySpawned to the visualsParent, set up various systems that controls game mechanics.- various systems that control each aspect of the game mechanism
override voidOnProcessFixedLogic(float delta): either runOnProcessFixedWithThreads(delta)orOnProcessFixedWithoutThreads(delta), which are generated in separate file.override voidOnProcessFrameLogic(float delta): runOnProcessFrameLogicGenerated(delta)which is generated in separate file.- the generated file is suffixed with
.generated.cs, and the methods are included using partial class. generated methods call theUpdate(delta)on each system.
6.2.1. MicrobeAI
Make decision about movement and change the MicrobeControl accordingly.
6.2.2. MicrobeMovementSystem
Motion is applied to the body in physical world, based on the current WorldPosition and MicrobeControl.
The control is modified in order to generate motion.
6.2.3. MicrobeVisualsSystem
Generate the membrane into the graphicalInstance
7. UI
7.1. MainMenu
Scene: src/general/MainMenu.tscn
7.2. HUD
classCreatureStageHUDBase<TStage>TStage?stagevoidInit(TStage containedInStage): set stage
7.3. Input
7.3.1. Microbe
classPlayerMicrobeInput: NodeWithInput- Set the control LookAtPoint of the player to the cursor position.
8. Third Party Library
8.1. ECS
- Entity-Component System
8.1.1. Arch
Arch.Core namespace contains the library.
World contains all entities.
Create,Destroy,Query
Entity is a single column in the World that represent
an independent object in the game.
Has<T>,Add<T>,Set<T>,Get<T>,Remove<T>
Entities are grouped in 16 KB of array called chunk, and chunks with same structure are grouped in archetype. This internal structure is employed for cache optimization.
8.1.2. DefaultEcs
The ECS library used in the past
9. References
- GitHub - Revolutionary-Games/Thrive: The main repository for the development …
- GitHub - genaray/Arch: A high-performance C# based Archetype & Chunks Entity …
- Why Arch? | Arch-ECS
- GitHub - Doraku/DefaultEcs: Entity Component System framework aiming for synt…
- GitHub - jslee02/awesome-entity-component-system: :sunglasses: A curated list…