Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
scene_service.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <map>
7#include <memory>
8#include <set>
9
22class SceneService final : public IEngineService {
23 private:
24 std::map<const std::string, std::unique_ptr<Scene>> scenes_;
25 void move_dont_destroy_on_load_objects(Scene& next_scene) const;
26
27 std::optional<std::reference_wrapper<Scene>> current_scene_;
28 std::optional<std::string> next_scene_name_;
29 std::string fallback_scene_name_ = DEFAULT_SCENE_NAME;
30 bool is_running_;
31
32 public:
33 static constexpr auto DEFAULT_SCENE_NAME = "DefaultScene";
34
36 explicit SceneService(const std::string& initial_scene_name);
37 SceneService(const SceneService&) = delete;
39 ~SceneService() override;
40
59 bool is_running() const;
63 void stop();
64
70 Scene& add_scene(const std::string& name);
71
78 SceneService& load_scene(const std::string& name);
79
87 SceneService& add_scene_and_load(const std::string& name);
88
94 SceneService& remove_scene(const std::string& name);
95
101 [[nodiscard]] std::set<std::string> contained_scene_names() const;
102
108 [[nodiscard]] Scene& current_scene() const;
109
116 SceneService& set_fallback_scene(const std::string& name);
117
122 [[nodiscard]] const std::string& fallback_scene() const;
123};
Definition iEngineService.h:4
Represents a scene within the engine. A scene contains multiple GameObjects and manages their lifecyc...
Definition scene.h:19
Service responsible for managing scenes within the engine. This service allows for adding,...
Definition scene_service.h:22
bool is_running() const
Shows if the SceneService is currently running scenes.
Scene & add_scene(const std::string &name)
Adds a new scene with the given name.
std::set< std::string > contained_scene_names() const
Checks if a scene with the given name exists.
~SceneService() override
const std::string & fallback_scene() const
Gets the fallback scene name.
Scene & current_scene() const
Gets the current active scene.
static constexpr auto DEFAULT_SCENE_NAME
Definition scene_service.h:33
SceneService(const std::string &initial_scene_name)
SceneService & remove_scene(const std::string &name)
Removes the scene with the given name.
SceneService & add_scene_and_load(const std::string &name)
Adds a new scene with the given name and sets it as the next scene to load. The scene will be loaded ...
SceneService(const SceneService &)=delete
SceneService & operator=(const SceneService &)=delete
SceneService & set_fallback_scene(const std::string &name)
Sets the fallback scene name. The fallback scene is loaded if the requested scene to load does not ex...
void stop()
Stops the SceneService and the current scene.
void run_current()
This method runs the current scene its game loop directly.
SceneService & load_scene(const std::string &name)
set the scene with the given name as the next scene to load. The scene will be loaded at the end of t...