From 13626410c4d6db7fdc15ded5ee7865fcdbf0b88a Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Thu, 15 Jan 2026 22:05:38 +0100 Subject: 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. --- patrol_order.go | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'patrol_order.go') 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} } -- cgit v1.3