diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/Component.cpp | 4 | ||||
-rw-r--r-- | src/crepe/Metadata.cpp | 7 | ||||
-rw-r--r-- | src/crepe/System.h | 4 | ||||
-rw-r--r-- | src/crepe/api/GameObject.cpp | 12 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 3 | ||||
-rw-r--r-- | src/crepe/api/Transform.cpp | 7 | ||||
-rw-r--r-- | src/example/ecs.cpp | 58 | ||||
-rw-r--r-- | src/example/physics.cpp | 3 |
8 files changed, 54 insertions, 44 deletions
diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp index 25c6947..78b47fa 100644 --- a/src/crepe/Component.cpp +++ b/src/crepe/Component.cpp @@ -4,6 +4,4 @@ using namespace crepe; Component::Component(uint32_t id) : game_object_id(id), active(true) {} -int Component::get_instances_max() const { - return -1; -} +int Component::get_instances_max() const { return -1; } diff --git a/src/crepe/Metadata.cpp b/src/crepe/Metadata.cpp index 3d1d910..d362e0a 100644 --- a/src/crepe/Metadata.cpp +++ b/src/crepe/Metadata.cpp @@ -3,8 +3,7 @@ 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 gameObjectId, string name, string tag) + : Component(gameObjectId), name(name), tag(tag) {} -int Metadata::get_instances_max() const { - return 1; -} +int Metadata::get_instances_max() const { return 1; } diff --git a/src/crepe/System.h b/src/crepe/System.h index ecbb7f5..8744920 100644 --- a/src/crepe/System.h +++ b/src/crepe/System.h @@ -8,8 +8,8 @@ public: virtual void update() = 0; protected: - System() {}; - virtual ~System() {}; + System(){}; + virtual ~System(){}; private: // singleton diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 388f1c4..5393e39 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -1,12 +1,14 @@ #include "api/Transform.h" -#include "Metadata.h" #include "GameObject.h" +#include "Metadata.h" using namespace crepe::api; 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, + 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); @@ -14,8 +16,10 @@ GameObject::GameObject(uint32_t id, std::string name, std::string tag, Point pos void GameObject::set_parent(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); + 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); } diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index fd513ec..862fee8 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -9,7 +9,8 @@ namespace crepe::api { class GameObject { public: - GameObject(uint32_t id, std::string name, std::string tag, Point position, double rotation, double scale); + GameObject(uint32_t id, std::string name, std::string tag, Point position, + double rotation, double scale); void set_parent(GameObject & parent); template <typename T, typename... Args> diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index 64ad81c..4b4da8f 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -8,14 +8,11 @@ using namespace crepe::api; -Transform::Transform(uint32_t game_id, Point point, double rot, - double scale) +Transform::Transform(uint32_t game_id, 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; -} +int Transform::get_instances_max() const { return 1; } diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp index 4c0e07d..2eb09b2 100644 --- a/src/example/ecs.cpp +++ b/src/example/ecs.cpp @@ -1,8 +1,8 @@ #include <iostream> -#include "../crepe/api/GameObject.h" #include "../crepe/ComponentManager.h" #include "../crepe/Metadata.h" +#include "../crepe/api/GameObject.h" #include "../crepe/api/Transform.h" using namespace crepe::api; @@ -11,33 +11,43 @@ using namespace std; int main() { // Create a few GameObjects - GameObject body(0, "body", "person", Point{0, 0}, 0, 1); - GameObject rightLeg(1, "rightLeg", "person", Point{1, 1}, 0, 1); - GameObject leftLeg(2, "leftLeg", "person", Point{1, 1}, 0, 1); - GameObject rightFoot(3, "rightFoot", "person", Point{2, 2}, 0, 1); - GameObject leftFoot(4, "leftFoot", "person", Point{2, 2}, 0, 1); + try { + GameObject body(0, "body", "person", Point{0, 0}, 0, 1); + GameObject rightLeg(1, "rightLeg", "person", Point{1, 1}, 0, 1); + GameObject leftLeg(2, "leftLeg", "person", Point{1, 1}, 0, 1); + GameObject rightFoot(3, "rightFoot", "person", Point{2, 2}, 0, 1); + GameObject leftFoot(4, "leftFoot", "person", Point{2, 2}, 0, 1); - // Set the parent of each GameObject - rightFoot.set_parent(rightLeg); - leftFoot.set_parent(leftLeg); - rightLeg.set_parent(body); - leftLeg.set_parent(body); + // Set the parent of each GameObject + rightFoot.set_parent(rightLeg); + leftFoot.set_parent(leftLeg); + rightLeg.set_parent(body); + leftLeg.set_parent(body); - // Get the Metadata and Transform components of each GameObject - ComponentManager & mgr = ComponentManager::get_instance(); - vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>(); - vector<reference_wrapper<Transform>> transform = mgr.get_components_by_type<Transform>(); + // Get the Metadata and Transform components of each GameObject + ComponentManager & mgr = ComponentManager::get_instance(); + vector<reference_wrapper<Metadata>> metadata + = mgr.get_components_by_type<Metadata>(); + vector<reference_wrapper<Transform>> transform + = mgr.get_components_by_type<Transform>(); - // Print the Metadata and Transform components - for(auto & m : metadata) { - cout << "Id: " << m.get().game_object_id << " Name: " << m.get().name << " Tag: " << m.get().tag << " Parent: " << m.get().parent << " Children: "; - for(auto & c : m.get().children) { - cout << c << " "; + // Print the Metadata and Transform components + for (auto & m : metadata) { + cout << "Id: " << m.get().game_object_id + << " Name: " << m.get().name << " Tag: " << m.get().tag + << " Parent: " << m.get().parent << " Children: "; + for (auto & c : m.get().children) { + cout << c << " "; + } + cout << endl; } - cout << endl; - } - for(auto & t : transform) { - cout << "Id: " << t.get().game_object_id << " Position: [" << t.get().position.x << ", " << t.get().position.y << "]" << endl; + for (auto & t : transform) { + cout << "Id: " << t.get().game_object_id << " Position: [" + << t.get().position.x << ", " << t.get().position.y << "]" + << endl; + } + } catch (const exception & e) { + cerr << e.what() << endl; } return 0; diff --git a/src/example/physics.cpp b/src/example/physics.cpp index 54d1807..1bafdf3 100644 --- a/src/example/physics.cpp +++ b/src/example/physics.cpp @@ -16,7 +16,8 @@ using namespace std; int main(int argc, char * argv[]) { PhysicsSystem physics_system; GameObject * game_object[2]; - game_object[1] = new GameObject(2, "Name", "Tag", Point{0, 0}, 0, 0); // not found not used + // not found not used + game_object[1] = new GameObject(2, "Name", "Tag", Point{0, 0}, 0, 0); game_object[0] = new GameObject(5, "Name", "Tag", Point{0, 0}, 0, 0); game_object[0]->add_component<Rigidbody>(1, 1, BodyType::DYNAMIC); game_object[0]->add_component<Force>(1, 0); |