Skip to main content

RandomDirectionInitializer.ixx File

Initializer that configures spawned entities with random direction. 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...

namespaceinitializers

Concrete SpawnInitializer implementations. More...

Classes Index

classRandomDirectionInitializer

Initializer that configures spawned entities with random direction. More...

Description

Initializer that configures spawned entities with random direction.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file RandomDirectionInitializer.ixx
3 * @brief Initializer that configures spawned entities with random direction.
4 */
5module;
6
7export module helios.engine.runtime.spawn.behavior.initializers.RandomDirectionInitializer;
8
9import helios.engine.runtime.spawn.behavior.SpawnInitializer;
10import helios.engine.runtime.spawn.SpawnPlanCursor;
11import helios.engine.runtime.spawn.SpawnContext;
12import helios.engine.ecs.GameObject;
13import helios.engine.modules.physics.motion.components.Move2DComponent;
14import helios.engine.modules.physics.motion.components.DirectionComponent;
15import helios.math;
16import helios.util.Random;
17
19
20 /**
21 * @brief Initializer that configures spawned entities with random direction.
22 *
23 * @details RandomDirectionInitializer generates a random 2D direction and
24 * applies it to the entity's DirectionComponent and Move2DComponent. This is
25 * useful for spawning enemies that should move in unpredictable directions.
26 *
27 * Components affected:
28 * - **DirectionComponent:** Sets random normalized direction
29 * - **Move2DComponent:** Sets move intent in the random direction
30 *
31 * @note Uses a static Random generator with a fixed seed for reproducibility.
32 *
33 * @see SpawnInitializer
34 */
36
37 public:
38
39 /**
40 * @brief Initializes entity with a random direction.
41 *
42 * @param gameObject The entity to initialize.
43 * @param cursor The current position within the spawn batch (unused).
44 * @param spawnContext Context data (unused).
45 */
48 const SpawnPlanCursor& cursor,
49 const SpawnContext& spawnContext
50 ) override {
51
52 static auto rGen = helios::util::Random(12345);
53
56
57 auto dir = helios::math::vec2f{
58 rGen.randomFloat(-1.0f, 1.0f),
59 rGen.randomFloat(-1.0f, 1.0f)
60 };
61
62 dc->setDirection(dir.normalize().toVec3());
63 mc->move(dc->direction(), 1.0f);
64 }
65
66 };
67
68}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.