diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/Component.cpp | 1 | ||||
-rw-r--r-- | src/crepe/Component.h | 2 | ||||
-rw-r--r-- | src/crepe/ComponentManager.hpp | 3 | ||||
-rw-r--r-- | src/crepe/Metadata.cpp | 5 | ||||
-rw-r--r-- | src/crepe/Metadata.h | 6 | ||||
-rw-r--r-- | src/crepe/api/GameObject.cpp | 21 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 5 | ||||
-rw-r--r-- | src/crepe/api/Transform.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/Transform.h | 4 | ||||
-rw-r--r-- | src/example/ecs.cpp | 16 | ||||
-rw-r--r-- | src/example/rendering.cpp | 1 | ||||
-rw-r--r-- | src/makefile | 104 |
12 files changed, 133 insertions, 38 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 diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp index eb5eeba..6f9752e 100644 --- a/src/example/ecs.cpp +++ b/src/example/ecs.cpp @@ -12,16 +12,16 @@ int main() { // Create a few GameObjects 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); + GameObject right_leg(1, "rightLeg", "person", Point{1, 1}, 0, 1); + GameObject left_leg(2, "leftLeg", "person", Point{1, 1}, 0, 1); + GameObject right_foot(3, "rightFoot", "person", Point{2, 2}, 0, 1); + GameObject left_foot(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); + right_foot.set_parent(right_leg); + left_foot.set_parent(left_leg); + right_leg.set_parent(body); + left_leg.set_parent(body); // Adding a second Transform component is not allowed and will invoke an exception body.add_component<Transform>(Point{10, 10}, 0, 1); diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp index f3d8a7d..3fe43d6 100644 --- a/src/example/rendering.cpp +++ b/src/example/rendering.cpp @@ -17,7 +17,6 @@ using namespace std; using namespace crepe; int main() { - dbg_trace(); auto obj = GameObject(0, "name", "tag", Point{0, 0}, 1, 1); diff --git a/src/makefile b/src/makefile index 3f74a2a..8506a43 100644 --- a/src/makefile +++ b/src/makefile @@ -1,8 +1,106 @@ .PHONY: FORCE -FMT += $(shell git ls-files '*.c' '*.cpp' '*.h' '*.hpp') +# STEPS FOR BIG CLEANUP +# +# 1. Change TODO to your name (in capitals) for each file in the list below +# that is yours (or you are going to fix) +# 2. Update the name between parentheses below this list (see comment) to your +# name +# 3. Create a git commit at this point (ensure `git status` reports "working +# tree clean") +# 4. Run `make format` in the REPOSITORY ROOT DIRECTORY (NOT HERE), and start +# fixing reported errors or miscorrections manually until everything works +# again. +# 5. Once everything is working again, create another git commit, and create a +# pull request. Make sure to ask someone to review the code standards for +# each ENTIRE FILE in this pull request. + +LOEK += crepe/Asset.cpp +LOEK += crepe/Asset.h +TODO += crepe/Collider.cpp +TODO += crepe/Collider.h +TODO += crepe/Component.cpp +TODO += crepe/Component.h +TODO += crepe/ComponentManager.cpp +TODO += crepe/ComponentManager.h +TODO += crepe/ComponentManager.hpp +TODO += crepe/Metadata.cpp +TODO += crepe/Metadata.h +TODO += crepe/Particle.cpp +TODO += crepe/Particle.h +TODO += crepe/Position.h +TODO += crepe/api/AssetManager.cpp +TODO += crepe/api/AssetManager.h +TODO += crepe/api/AssetManager.hpp +LOEK += crepe/api/AudioSource.cpp +LOEK += crepe/api/AudioSource.h +LOEK += crepe/api/BehaviorScript.cpp +LOEK += crepe/api/BehaviorScript.h +LOEK += crepe/api/BehaviorScript.hpp +TODO += crepe/api/CircleCollider.h +TODO += crepe/api/Color.cpp +TODO += crepe/api/Color.h +LOEK += crepe/api/Config.h +TODO += crepe/api/Force.cpp +TODO += crepe/api/Force.h +TODO += crepe/api/GameObject.cpp +TODO += crepe/api/GameObject.h +TODO += crepe/api/GameObject.hpp +TODO += crepe/api/ParticleEmitter.cpp +TODO += crepe/api/ParticleEmitter.h +TODO += crepe/api/Point.h +TODO += crepe/api/Rigidbody.cpp +TODO += crepe/api/Rigidbody.h +LOEK += crepe/api/Script.cpp +LOEK += crepe/api/Script.h +LOEK += crepe/api/Script.hpp +TODO += crepe/api/Sprite.cpp +TODO += crepe/api/Sprite.h +TODO += crepe/api/Texture.cpp +TODO += crepe/api/Texture.h +TODO += crepe/api/Transform.cpp +TODO += crepe/api/Transform.h +TODO += crepe/facade/SDLApp.cpp +TODO += crepe/facade/SDLApp.h +TODO += crepe/facade/SDLContext.cpp +TODO += crepe/facade/SDLContext.h +LOEK += crepe/facade/Sound.cpp +LOEK += crepe/facade/Sound.h +LOEK += crepe/facade/SoundContext.cpp +LOEK += crepe/facade/SoundContext.h +TODO += crepe/system/CollisionSystem.cpp +TODO += crepe/system/CollisionSystem.h +TODO += crepe/system/ParticleSystem.cpp +TODO += crepe/system/ParticleSystem.h +TODO += crepe/system/PhysicsSystem.cpp +TODO += crepe/system/PhysicsSystem.h +TODO += crepe/system/RenderSystem.cpp +TODO += crepe/system/RenderSystem.h +LOEK += crepe/system/ScriptSystem.cpp +LOEK += crepe/system/ScriptSystem.h +LOEK += crepe/system/System.h +LOEK += crepe/util/LogColor.cpp +LOEK += crepe/util/LogColor.h +LOEK += crepe/util/fmt.cpp +LOEK += crepe/util/fmt.h +LOEK += crepe/util/log.cpp +LOEK += crepe/util/log.h +TODO += example/asset_manager.cpp +LOEK += example/audio_internal.cpp +TODO += example/components_internal.cpp +TODO += example/ecs.cpp +LOEK += example/log.cpp +TODO += example/particle.cpp +TODO += example/physics.cpp +TODO += example/rendering.cpp +LOEK += example/script.cpp +LOEK += test/audio.cpp +LOEK += test/dummy.cpp + +FMT := $(LOEK) #<<< CHANGE THIS TO YOUR NAME FOR STEP 2 format: FORCE - # clang-tidy -p build/compile_commands.json --fix-errors $(FMT) + clang-tidy -p build/compile_commands.json --fix-errors $(FMT) -# TODO: re-enable linter after 2024-11-10 +# FMT += $(shell git ls-files '*.c' '*.cpp' '*.h' '*.hpp') +# TODO: re-enable linter after all corrections |