Skip to main content

ColumnSpawnPlacer.ixx File

Spawn placer that arranges entities in a vertical column. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespaceruntime

Runtime infrastructure for game execution and lifecycle orchestration. More...

namespacespawn

Entity spawning infrastructure for the helios engine. More...

namespacebehavior

Spawn behavior strategies for positioning and initializing entities. More...

namespaceplacements

Concrete SpawnPlacer implementations. More...

Classes Index

classColumnSpawnPlacer

Places spawned entities in a vertical column formation. More...

Description

Spawn placer that arranges entities in a vertical column.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ColumnSpawnPlacer.ixx
3 * @brief Spawn placer that arranges entities in a vertical column.
4 */
5module;
6
7#include <cmath>
8
9export module helios.engine.runtime.spawn.behavior.placements.ColumnSpawnPlacer;
10
11import helios.engine.runtime.spawn.SpawnPlanCursor;
12import helios.engine.runtime.spawn.SpawnContext;
13import helios.engine.runtime.spawn.behavior.SpawnPlacer;
14import helios.util.Random;
15import helios.math;
16import helios.engine.ecs.EntityHandle;
17
18import helios.engine.runtime.world.UpdateContext;
19
20
22
23 /**
24 * @brief Places spawned entities in a vertical column formation.
25 *
26 * Distributes entities evenly along the Y-axis within the environment
27 * bounds. Entities are positioned at the left edge (min X) of the
28 * environment and spaced vertically based on the spawn count.
29 *
30 * For single spawns, a random Y position is chosen within bounds.
31 * For multiple spawns, entities are evenly distributed from top to bottom.
32 *
33 * Example layout for 4 entities:
34 * ```
35 * ┌─────────────────────┐
36 * │ ○ │ <- position 1
37 * │ │
38 * │ ○ │ <- position 2
39 * │ │
40 * │ ○ │ <- position 3
41 * │ │
42 * │ ○ │ <- position 4
43 * └─────────────────────┘
44 * ```
45 */
46 class ColumnSpawnPlacer final : public SpawnPlacer {
47
48 public:
49
50 /**
51 * @brief Calculates spawn position for a vertical column layout.
52 *
53 * @param entityHandle The handle of the entity being spawned.
54 * @param gameObjectBounds The AABB of the entity to spawn.
55 * @param environmentBounds The AABB of the spawn environment (arena).
56 * @param cursor Current position in the spawn batch.
57 * @param spawnContext Additional context for spawn decisions.
58 *
59 * @return World position for the entity (left edge, vertically distributed).
60 */
62 const helios::engine::ecs::EntityHandle& entityHandle,
63 const helios::math::aabbf& gameObjectBounds,
64 const helios::math::aabbf& environmentBounds,
65 const SpawnPlanCursor& cursor,
66 const SpawnContext& spawnContext
67 ) override {
68
69 const float top = environmentBounds.max()[1];
70 const float bottom = environmentBounds.min()[1];
71 const float height = std::abs(top - bottom);
72
73 const float objectHeight = gameObjectBounds.size()[1];
74
75 size_t position = cursor.position;
76
77 float dist;
78 if (cursor.spawnCount == 1) {
79 dist = helios::util::Random(12345).randomFloat(0, height - objectHeight);
80 position = 1;
81 } else {
82 dist = height / static_cast<float>(cursor.spawnCount);
83 }
84
85 const float x = environmentBounds.min()[0];
86 const float y = top - (static_cast<float>(position) * dist) - (objectHeight / 2.0f);
87
88 return helios::math::vec3f{x, y, 0.0f};
89
90 }
91
92
93 };
94
95}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.