Skip to main content

RandomSpawnPlacer.ixx File

Placer that spawns entities at random positions within bounds. 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

classRandomSpawnPlacer

Placer that spawns entities at random positions within bounds. More...

Description

Placer that spawns entities at random positions within bounds.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file RandomSpawnPlacer.ixx
3 * @brief Placer that spawns entities at random positions within bounds.
4 */
5module;
6
7export module helios.engine.runtime.spawn.behavior.placements.RandomSpawnPlacer;
8
9import helios.engine.runtime.spawn.SpawnPlanCursor;
10import helios.engine.runtime.spawn.SpawnContext;
11import helios.engine.runtime.spawn.behavior.SpawnPlacer;
12import helios.util.Random;
13import helios.math;
14import helios.engine.ecs.EntityHandle;
15
17
18 /**
19 * @brief Placer that spawns entities at random positions within bounds.
20 *
21 * @details RandomSpawnPlacer generates random X and Y coordinates within
22 * the provided level bounds. The Z coordinate is set to 0, making this
23 * suitable for 2D games.
24 *
25 * @note Uses a static Random generator with a fixed seed for reproducibility.
26 *
27 * @see SpawnPlacer
28 */
29 class RandomSpawnPlacer final : public SpawnPlacer {
30
31 public:
32
33 /**
34 * @brief Returns a random position within the level bounds.
35 *
36 * @param entityHandle The handle of the entity being spawned (unused).
37 * @param gameObjectBounds The bounding box of the entity to spawn (unused).
38 * @param environmentBounds The level bounds to spawn within.
39 * @param cursor The current position within the spawn batch (unused).
40 * @param spawnContext Context data (unused).
41 *
42 * @return A random vec3f with Z = 0
43 */
45 const helios::engine::ecs::EntityHandle& entityHandle,
46 const helios::math::aabbf& gameObjectBounds,
47 const helios::math::aabbf& environmentBounds,
48 const SpawnPlanCursor& cursor,
49 const SpawnContext& spawnContext
50 ) override {
51
52 static auto rGen = helios::util::Random(12345);
53
54 float xPos = rGen.randomFloat(environmentBounds.min()[0], environmentBounds.max()[0]);
55 float yPos = rGen.randomFloat(environmentBounds.min()[1], environmentBounds.max()[1]);
56
57 return helios::math::vec3f{xPos, yPos, 0.0f};
58 }
59
60
61 };
62
63}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.