aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-11-06 09:52:05 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-11-06 09:52:05 +0100
commitf4083c161a1176c900629ba61d96843645fc7be5 (patch)
tree0c136c9af142a4f7018a7441ec879b3b41da02c0 /src/crepe
parentbf4c172f2709adf5a6f210bae60e16972e8decad (diff)
parent6ce2c14077e3e6dd01398d582b42dc50e9141f54 (diff)
Merge remote-tracking branch 'origin/master' into max/scenes
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/Component.cpp1
-rw-r--r--src/crepe/Component.h2
-rw-r--r--src/crepe/ComponentManager.hpp3
-rw-r--r--src/crepe/Metadata.cpp5
-rw-r--r--src/crepe/Metadata.h6
-rw-r--r--src/crepe/api/GameObject.cpp21
-rw-r--r--src/crepe/api/GameObject.h5
-rw-r--r--src/crepe/api/Transform.cpp3
-rw-r--r--src/crepe/api/Transform.h4
9 files changed, 24 insertions, 26 deletions
diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp
index 78b47fa..41e7273 100644
--- a/src/crepe/Component.cpp
+++ b/src/crepe/Component.cpp
@@ -4,4 +4,3 @@ using namespace crepe;
Component::Component(uint32_t id) : game_object_id(id), active(true) {}
-int Component::get_instances_max() const { return -1; }
diff --git a/src/crepe/Component.h b/src/crepe/Component.h
index 039836e..8db9b2a 100644
--- a/src/crepe/Component.h
+++ b/src/crepe/Component.h
@@ -13,7 +13,7 @@ protected:
public:
virtual ~Component() = default;
- virtual int get_instances_max() const;
+ virtual int get_instances_max() const { return -1; }
public:
uint32_t game_object_id;
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp
index f469d12..e74f2e9 100644
--- a/src/crepe/ComponentManager.hpp
+++ b/src/crepe/ComponentManager.hpp
@@ -36,12 +36,13 @@ T & ComponentManager::add_component(uint32_t id, Args &&... args) {
// Check if the vector size is not greater than get_instances_max
if (instance->get_instances_max() != -1
&& components[type][id].size() >= instance->get_instances_max()) {
+ // TODO: Exception
throw std::runtime_error(
"Exceeded maximum number of instances for this component type");
}
// store its unique_ptr in the vector<>
- components[type][id].push_back(move(instance));
+ components[type][id].push_back(std::move(instance));
return *instance;
}
diff --git a/src/crepe/Metadata.cpp b/src/crepe/Metadata.cpp
index d362e0a..1ba150a 100644
--- a/src/crepe/Metadata.cpp
+++ b/src/crepe/Metadata.cpp
@@ -3,7 +3,6 @@
using namespace crepe;
using namespace std;
-Metadata::Metadata(uint32_t gameObjectId, string name, string tag)
- : Component(gameObjectId), name(name), tag(tag) {}
+Metadata::Metadata(uint32_t game_object_id, const string & name, const string & tag)
+ : Component(game_object_id), name(name), tag(tag) {}
-int Metadata::get_instances_max() const { return 1; }
diff --git a/src/crepe/Metadata.h b/src/crepe/Metadata.h
index 2f08476..b946fd0 100644
--- a/src/crepe/Metadata.h
+++ b/src/crepe/Metadata.h
@@ -9,13 +9,13 @@ namespace crepe {
class Metadata : public Component {
public:
- Metadata(uint32_t game_object_id, std::string name, std::string tag);
- int get_instances_max() const;
+ Metadata(uint32_t game_object_id, const std::string & name, const std::string & tag);
+ virtual int get_instances_max() const { return 1; }
public:
std::string name;
std::string tag;
- uint32_t parent = UINT32_MAX;
+ uint32_t parent = -1;
std::vector<uint32_t> children;
};
diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp
index 2592d2d..8a1a235 100644
--- a/src/crepe/api/GameObject.cpp
+++ b/src/crepe/api/GameObject.cpp
@@ -6,20 +6,21 @@
using namespace crepe;
using namespace std;
-GameObject::GameObject(uint32_t id, std::string name, std::string tag,
- Point position, double rotation, double scale)
- : id(id) {
+GameObject::GameObject(uint32_t id, std::string name, std::string tag, const Point & position, double rotation, double scale) : id(id) {
ComponentManager & mgr = ComponentManager::get_instance();
mgr.add_component<Transform>(this->id, position, rotation, scale);
mgr.add_component<Metadata>(this->id, name, tag);
}
-void GameObject::set_parent(GameObject & parent) {
+void GameObject::set_parent(const GameObject & parent) {
auto & mgr = ComponentManager::get_instance();
- vector<reference_wrapper<Metadata>> thisMetadata
- = mgr.get_components_by_id<Metadata>(this->id);
- vector<reference_wrapper<Metadata>> parentMetadata
- = mgr.get_components_by_id<Metadata>(parent.id);
- thisMetadata.at(0).get().parent = parent.id;
- parentMetadata.at(0).get().children.push_back(this->id);
+
+ // set parent on own Metadata component
+ vector<reference_wrapper<Metadata>> this_metadata = mgr.get_components_by_id<Metadata>(this->id);
+ this_metadata.at(0).get().parent = parent.id;
+
+ // add own id to children list of parent's Metadata component
+ vector<reference_wrapper<Metadata>> parent_metadata = mgr.get_components_by_id<Metadata>(parent.id);
+ parent_metadata.at(0).get().children.push_back(this->id);
}
+
diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h
index dcd33ad..4c87639 100644
--- a/src/crepe/api/GameObject.h
+++ b/src/crepe/api/GameObject.h
@@ -9,9 +9,8 @@ namespace crepe {
class GameObject {
public:
- GameObject(uint32_t id, std::string name, std::string tag, Point position,
- double rotation, double scale);
- void set_parent(GameObject & parent);
+ GameObject(uint32_t id, std::string name, std::string tag, const Point & position, double rotation, double scale);
+ void set_parent(const GameObject & parent);
template <typename T, typename... Args>
T & add_component(Args &&... args);
diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp
index a80aff3..9c9bb06 100644
--- a/src/crepe/api/Transform.cpp
+++ b/src/crepe/api/Transform.cpp
@@ -8,11 +8,10 @@
using namespace crepe;
-Transform::Transform(uint32_t game_id, Point point, double rot, double scale)
+Transform::Transform(uint32_t game_id, const Point & point, double rot, double scale)
: Component(game_id), position(point), rotation(rot), scale(scale) {
dbg_trace();
}
Transform::~Transform() { dbg_trace(); }
-int Transform::get_instances_max() const { return 1; }
diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h
index f918115..557061b 100644
--- a/src/crepe/api/Transform.h
+++ b/src/crepe/api/Transform.h
@@ -14,9 +14,9 @@ class Transform : public Component {
// works similar (or the same) as those found in GLSL?
public:
- Transform(uint32_t id, Point, double, double);
+ Transform(uint32_t id, const Point &, double, double);
~Transform();
- int get_instances_max() const;
+ virtual int get_instances_max() const { return 1; }
//! Translation (shift)
Point position;
//! Rotation, in radians