aboutsummaryrefslogtreecommitdiff
path: root/patrol_order.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-01-15 22:05:38 +0100
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-01-15 22:05:46 +0100
commit13626410c4d6db7fdc15ded5ee7865fcdbf0b88a (patch)
treea549d918804acb7682c857e742f1af189692cf62 /patrol_order.go
parentcf85fc095bc9b6ab4b49e4f88a5f04d7ac2fe74b (diff)
refactor: transition to struct-of-arrays ECS architecture
- Replace individual Entity structs with centralized component slices in Game struct (SoA layout). - Implement bitmask-based component lookup (CM_Position, CM_Move, etc.). - Convert logic from object-oriented Update() methods to standalone Systems (UpdateMoveSystem, UpdateGatherSystem, UpdateSpawnSystem). - Update rendering, selection, and input handling to iterate over component arrays.
Diffstat (limited to 'patrol_order.go')
-rw-r--r--patrol_order.go39
1 files changed, 25 insertions, 14 deletions
diff --git a/patrol_order.go b/patrol_order.go
index a5b8d83..e921e5b 100644
--- a/patrol_order.go
+++ b/patrol_order.go
@@ -12,24 +12,35 @@ type PatrolOrder struct {
destination physics.Point
}
-func (o *PatrolOrder) Update(e *Entity, g *Game) {
- if e.Position.IsEnabled && e.Move.IsEnabled {
- if !e.Move.Value.IsActive {
- moveMap := g.getMoveMap()
- if e.Position.Value == o.destination {
- physics.StartMove(&e.Move, e.Position, o.origin, moveMap)
- } else {
- physics.StartMove(&e.Move, e.Position, o.destination, moveMap)
+func UpdatePatrolSystem(moveMap physics.MoveMap, masks []ecs.Mask, orders []OrderKind, patrols []PatrolOrder, positions []physics.Point, moves []physics.Move) {
+ required := ecs.CM_Position | ecs.CM_Move | ecs.CM_Order | ecs.CM_PatrolOrder
+ for i, mask := range masks {
+ if mask&required == required {
+ order := orders[i]
+ patrol := patrols[i]
+ position := positions[i]
+ move := &moves[i]
+ if order == OrderKindPatrol && !move.IsActive {
+ if position == patrol.destination {
+ *move = physics.NewMove(position, patrol.origin, moveMap)
+ } else {
+ *move = physics.NewMove(position, patrol.destination, moveMap)
+ }
}
}
}
}
-func Patrol(position ecs.Component[physics.Point], move ecs.Component[physics.Move], order *ecs.Component[Order], destination physics.Point) {
- if !position.IsEnabled || !move.IsEnabled || !order.IsEnabled {
- return
+func StartPatrolSystem(destination physics.Point, masks []ecs.Mask, positions []physics.Point, moves []physics.Move, orders []OrderKind, patrols []PatrolOrder) {
+ required := ecs.CM_Position | ecs.CM_Order | ecs.CM_PatrolOrder
+ for i, mask := range masks {
+ if mask&required == required {
+ position := positions[i]
+ order := &orders[i]
+ patrol := &patrols[i]
+ slog.Info("patrolling between", slog.String("origin", position.String()), slog.String("destination", destination.String()))
+ *patrol = PatrolOrder{origin: position, destination: destination}
+ *order = OrderKindPatrol
+ }
}
- origin := position.Value
- slog.Info("patrolling between", slog.String("origin", origin.String()), slog.String("destination", destination.String()))
- order.Value = &PatrolOrder{origin: origin, destination: destination}
}