21 int stop_event_listener_id_;
22 const std::string name_;
29 std::vector<std::unique_ptr<GameObject>> game_objects_;
33 using listener_function_t = std::function<void(
Scene&)>;
34 std::vector<listener_function_t> run_listeners_;
35 std::vector<listener_function_t> stop_listeners_;
36 std::vector<listener_function_t> destroy_listeners_;
38 void execute_listeners(
const std::vector<listener_function_t>& listeners);
52 void on_run(listener_function_t&& listener);
58 void on_stop(listener_function_t&& listener);
102 [[nodiscard]] const std::
string&
name() const;
118 const std::
string&
id) const;
131 [[nodiscard]] std::vector<std::reference_wrapper<
GameObject>>
141 template <typename T, typename... Args>
143 static_assert(std::is_base_of_v<GameObject, T>,
144 "T must be derived from GameObject");
146 auto game_object = std::make_unique<T>(std::forward<Args>(args)...);
147 game_objects_.emplace_back(std::move(game_object));
149 return static_cast<T&
>(*game_objects_.back());
198 [[nodiscard]] std::optional<std::reference_wrapper<Camera>>
main_camera()
Concept to constrain types to be derived from Component.
Definition gameObject.h:33
Represents a scene within the engine. A scene contains multiple GameObjects and manages their lifecyc...
Definition scene.h:19
void on_stop(listener_function_t &&listener)
Registers a listener function to be called when the scene stops.
bool remove_game_object(GameObject &game_object)
Removes a GameObject from the scene and deletes it.
bool marked_for_stopping() const
Checks if the scene is marked for stopping.
void on_run(listener_function_t &&listener)
Registers a listener function to be called when the scene starts running.
std::reference_wrapper< GameObject > get_game_object(const std::string &id) const
Retrieves a GameObject by its unique identifier.
float time_scale() const
Retrieves the current time scale modifier for the scene.
bool is_running() const
Checks if the scene is currently running.
std::vector< std::reference_wrapper< GameObject > > game_objects() const
Retrieves all GameObjects in the scene.
void on_destroy(listener_function_t &&listener)
Registers a listener function to be called when the scene is destroyed.
GameObject & add_game_object(const std::string &name)
Adds a new GameObject with the given name to the scene.
Scene & add_game_object(std::unique_ptr< GameObject > game_object)
Adds an existing GameObject to the scene.
Scene & add_game_objects(std::vector< std::unique_ptr< GameObject > > game_objects)
Adds multiple existing GameObjects to the scene.
T & add_game_object(Args &&... args)
Adds a new GameObject of type T to the scene.
Definition scene.h:142
std::unique_ptr< GameObject > extract_game_object(GameObject &game_object)
Extracts a GameObject from the scene without deleting it.
void cleanup_destroyed_game_objects()
Cleans up and deletes all GameObjects that are marked for deletion.
void stop()
marks the scene to be stopped.
const std::string & name() const
Retrieves the name of the scene.
std::optional< std::reference_wrapper< Camera > > main_camera() const
Retrieves the main camera of the scene.
std::vector< std::reference_wrapper< GameObject > > active_game_objects() const
Retrieves all active GameObjects in the scene.
void mark_for_stopping() noexcept
Marks the scene to be stopped.
Service responsible for managing scenes within the engine. This service allows for adding,...
Definition scene_service.h:22