Skip to main content

DistributedSpawnPlacer.ixx File

Spawn placer that distributes entities across predefined locations. 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

classDistributedSpawnPlacer<N>

Spawn placer that assigns entities to predefined spawn points. More...

Description

Spawn placer that distributes entities across predefined locations.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file DistributedSpawnPlacer.ixx
3 * @brief Spawn placer that distributes entities across predefined locations.
4 */
5module;
6
7#include <cassert>
8#include <cmath>
9#include <algorithm>
10
11export module helios.engine.runtime.spawn.behavior.placements.DistributedSpawnPlacer;
12
13import helios.engine.runtime.spawn.SpawnPlanCursor;
14import helios.engine.runtime.spawn.SpawnContext;
15import helios.engine.runtime.spawn.behavior.SpawnPlacer;
16import helios.util.Random;
17import helios.math;
18import helios.engine.ecs.EntityHandle;
19
20import helios.engine.runtime.world.UpdateContext;
21
22
24
25 /**
26 * @brief Spawn placer that assigns entities to predefined spawn points.
27 *
28 * @details DistributedSpawnPlacer uses a fixed-size array of locations
29 * to distribute spawned entities. Entities are assigned to locations
30 * based on their cursor position within the spawn batch, dividing
31 * the batch evenly across all available spawn points.
32 *
33 * ## Distribution Algorithm
34 *
35 * Entities are mapped to locations using: `bin = N * (position / spawnCount)`
36 *
37 * This ensures even distribution when spawn count exceeds location count,
38 * and direct mapping when spawn count equals location count.
39 *
40 * ## Use Cases
41 *
42 * - **Fixed spawn points:** Enemies spawning at predefined positions
43 * - **Formation patterns:** Entities placed in specific arrangements
44 * - **Level design:** Designer-defined spawn locations
45 *
46 * ## Usage
47 *
48 * ```cpp
49 * // Create placer with 3 fixed spawn points
50 * auto placer = std::make_unique<DistributedSpawnPlacer<3>>(
51 * helios::math::vec3f{-50.0f, 100.0f, 0.0f},
52 * helios::math::vec3f{ 0.0f, 100.0f, 0.0f},
53 * helios::math::vec3f{ 50.0f, 100.0f, 0.0f}
54 * );
55 *
56 * // 3 entities spawn at the 3 locations
57 * // 6 entities: 2 per location
58 * ```
59 *
60 * @tparam N Number of spawn locations.
61 *
62 * @see SpawnPlacer
63 * @see AxisSpawnPlacer
64 */
65 template<std::size_t N>
66 class DistributedSpawnPlacer final : public SpawnPlacer {
67
68 /**
69 * @brief Fixed array of spawn point locations.
70 */
71 std::array<helios::math::vec3f, N> locations_{};
72
73 public:
74
75 /**
76 * @brief Constructs a DistributedSpawnPlacer with N spawn locations.
77 *
78 * @tparam Args Types of location arguments (must be vec3f).
79 *
80 * @param args Exactly N spawn point locations.
81 *
82 * @note The number of arguments must match template parameter N.
83 */
84 template<typename... Args>
85 requires(sizeof...(Args) == N)
86 explicit DistributedSpawnPlacer(Args&& ...args) : locations_({std::forward<Args>(args)... }) {}
87
88 /**
89 * @brief Returns the spawn location for the current entity.
90 *
91 * @details Maps the cursor position to one of the predefined locations
92 * by dividing the spawn batch evenly across available spawn points.
93 *
94 * @param guid Unique identifier of the entity (unused).
95 * @param gameObjectBounds Bounding box of the entity (unused).
96 * @param environmentBounds Bounding box of the environment (unused).
97 * @param cursor Current spawn batch cursor with position and count.
98 * @param spawnContext Context for the spawn operation (unused).
99 *
100 * @return World position from the locations array.
101 */
103 const helios::engine::ecs::EntityHandle& entityHandle,
104 const helios::math::aabbf& gameObjectBounds,
105 const helios::math::aabbf& environmentBounds,
106 const SpawnPlanCursor& cursor,
107 const SpawnContext& spawnContext
108 ) override {
109
110 const size_t bin = N * (cursor.position/static_cast<float>(cursor.spawnCount));
111
112 return locations_[bin];
113 }
114
115
116 };
117
118}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.