Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
prefab_service.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <functional>
7#include <map>
8#include <memory>
9#include <string>
10
11class Scene;
12
20using PrefabFactory = std::function<GameObject&(Scene&, const std::string&)>;
21
41 public:
42 PrefabService() = default;
43
44 PrefabService(const PrefabService&) = delete;
48
54 void register_prefab(const std::string& prefab_type_id,
55 const PrefabFactory& factory);
56
61 void unregister_prefab(const std::string& prefab_type_id);
62
68 [[nodiscard]] bool has_prefab(const std::string& prefab_type_id) const;
69
78 std::reference_wrapper<GameObject> instantiate(
79 const std::string& prefab_type_id, Scene& scene, const std::string& name);
80
84 [[nodiscard]] std::vector<std::string> get_registered_prefabs() const;
85
89 void clear_all();
90
91 private:
92 std::map<std::string, PrefabFactory> prefab_factories_;
93};
Concept to constrain types to be derived from Component.
Definition gameObject.h:33
Definition iEngineService.h:4
Global service for managing prefab factories and component creation.
Definition prefab_service.h:40
void clear_all()
Clear all registered prefabs.
PrefabService & operator=(const PrefabService &)=delete
PrefabService(const PrefabService &)=delete
void register_prefab(const std::string &prefab_type_id, const PrefabFactory &factory)
Register a prefab factory for a given type ID.
PrefabService(PrefabService &&)=delete
void unregister_prefab(const std::string &prefab_type_id)
Unregister a previously registered prefab factory.
std::vector< std::string > get_registered_prefabs() const
Get all registered prefab type IDs.
PrefabService & operator=(PrefabService &&)=delete
PrefabService()=default
bool has_prefab(const std::string &prefab_type_id) const
Check if a prefab type is registered.
std::reference_wrapper< GameObject > instantiate(const std::string &prefab_type_id, Scene &scene, const std::string &name)
Instantiate a GameObject from a registered prefab.
Represents a scene within the engine. A scene contains multiple GameObjects and manages their lifecyc...
Definition scene.h:19
std::function< GameObject &(Scene &, const std::string &)> PrefabFactory
A prefab factory function that creates a GameObject with predefined components.
Definition prefab_service.h:20