diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/CMakeLists.txt | 25 | ||||
-rw-r--r-- | src/crepe/Collider.cpp (renamed from src/crepe/api/Collider.cpp) | 2 | ||||
-rw-r--r-- | src/crepe/Collider.h (renamed from src/crepe/api/Collider.h) | 6 | ||||
-rw-r--r-- | src/crepe/Component.h | 8 | ||||
-rw-r--r-- | src/crepe/GameObject.hpp | 15 | ||||
-rw-r--r-- | src/crepe/ParticleSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/ParticleSystem.h | 2 | ||||
-rw-r--r-- | src/crepe/PhysicsSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/SDLApp.cpp | 2 | ||||
-rw-r--r-- | src/crepe/SDLApp.h | 2 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 14 | ||||
-rw-r--r-- | src/crepe/api/CircleCollider.h (renamed from src/crepe/CircleCollider.h) | 4 | ||||
-rw-r--r-- | src/crepe/api/Force.cpp (renamed from src/crepe/Force.cpp) | 4 | ||||
-rw-r--r-- | src/crepe/api/Force.h (renamed from src/crepe/Force.h) | 4 | ||||
-rw-r--r-- | src/crepe/api/ParticleEmitter.cpp (renamed from src/crepe/ParticleEmitter.cpp) | 0 | ||||
-rw-r--r-- | src/crepe/api/ParticleEmitter.h (renamed from src/crepe/ParticleEmitter.h) | 0 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h | 2 | ||||
-rw-r--r-- | src/example/Physics.cpp | 9 | ||||
-rw-r--r-- | src/example/particle.cpp | 5 |
20 files changed, 61 insertions, 49 deletions
diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 245df31..1b4b1c2 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -3,35 +3,34 @@ target_sources(crepe PUBLIC Asset.cpp Sound.cpp SoundContext.cpp - #Particle.cpp - #ParticleEmitter.cpp - #ParticleSystem.cpp - SdlContext.cpp + Particle.cpp + ParticleSystem.cpp + SDLApp.cpp ComponentManager.cpp Component.cpp ScriptSystem.cpp + PhysicsSystem.cpp + CollisionSystem.cpp + Collider.cpp + SdlContext.cpp + RenderSystem.cpp - #PhysicsSystem.cpp - #Force.cpp - #CollisionSystem.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES Asset.h Sound.h SoundContext.h - #ParticleEmitter.h - #ParticleSystem.h - #Particle.h SdlContext.h ComponentManager.h ComponentManager.hpp Component.h System.h ScriptSystem.h - #PhysicsSystem.h - #Force.h - #CollisionSystem.h + PhysicsSystem.h + CollisionSystem.h + Collider.h + SdlContext.h RenderSystem.h ) diff --git a/src/crepe/api/Collider.cpp b/src/crepe/Collider.cpp index c3e4929..311ffb3 100644 --- a/src/crepe/api/Collider.cpp +++ b/src/crepe/Collider.cpp @@ -1,5 +1,5 @@ #include "Collider.h" -using namespace crepe::api; +using namespace crepe; Collider::Collider(uint32_t gameObjectId) : Component(gameObjectId){} diff --git a/src/crepe/api/Collider.h b/src/crepe/Collider.h index 1d540de..cfc044c 100644 --- a/src/crepe/api/Collider.h +++ b/src/crepe/Collider.h @@ -1,8 +1,8 @@ #pragma once -#include "../Component.h" +#include "Component.h" -namespace crepe::api { +namespace crepe { class Collider : public Component { public: @@ -11,4 +11,4 @@ public: int size; }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/Component.h b/src/crepe/Component.h index 8a42a45..9483dad 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -5,16 +5,12 @@ namespace crepe { class Component { protected: - Component() = default; + Component(uint32_t id); public: - Component(uint32_t id); - virtual ~Component() {} - // TODO: shouldn't this constructor be deleted because this class will never - // directly be instantiated? - //changed so it sets the id (jaro) uint32_t gameObjectId; bool active; + virtual ~Component() = default; }; } // namespace crepe diff --git a/src/crepe/GameObject.hpp b/src/crepe/GameObject.hpp new file mode 100644 index 0000000..8cd1abe --- /dev/null +++ b/src/crepe/GameObject.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "GameObject.h" + +#include "ComponentManager.h" + +namespace crepe { + +template <typename T, typename... Args> +T & GameObject::add_component(Args &&... args) { + auto & mgr = ComponentManager::get_instance(); + return mgr.add_component<T>(id, std::forward<Args>(args)...); +} + +} // namespace crepe diff --git a/src/crepe/ParticleSystem.cpp b/src/crepe/ParticleSystem.cpp index 0dad4cd..bf7f8fc 100644 --- a/src/crepe/ParticleSystem.cpp +++ b/src/crepe/ParticleSystem.cpp @@ -1,7 +1,7 @@ #include "ParticleSystem.h" #include <cmath> #include <ctime> -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" #include "Particle.h" #include "ComponentManager.h" diff --git a/src/crepe/ParticleSystem.h b/src/crepe/ParticleSystem.h index c8777f5..313e1dd 100644 --- a/src/crepe/ParticleSystem.h +++ b/src/crepe/ParticleSystem.h @@ -1,7 +1,7 @@ #pragma once #include <vector> -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" namespace crepe { diff --git a/src/crepe/PhysicsSystem.cpp b/src/crepe/PhysicsSystem.cpp index 3ed84f8..d9930a8 100644 --- a/src/crepe/PhysicsSystem.cpp +++ b/src/crepe/PhysicsSystem.cpp @@ -2,7 +2,7 @@ #include "ComponentManager.h" #include "api/Rigidbody.h" #include "api/Transform.h" -#include "Force.h" +#include "api/Force.h" #include <iostream> using namespace crepe; diff --git a/src/crepe/SDLApp.cpp b/src/crepe/SDLApp.cpp index 715dd6f..ca7e819 100644 --- a/src/crepe/SDLApp.cpp +++ b/src/crepe/SDLApp.cpp @@ -2,7 +2,7 @@ #include <iostream> #include <vector> #include "Particle.h" -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" SDLApp::SDLApp(int windowWidth, int windowHeight) : windowWidth(windowWidth), windowHeight(windowHeight), window(nullptr), renderer(nullptr) {} diff --git a/src/crepe/SDLApp.h b/src/crepe/SDLApp.h index 8915d30..b536ac8 100644 --- a/src/crepe/SDLApp.h +++ b/src/crepe/SDLApp.h @@ -3,7 +3,7 @@ #include <SDL2/SDL.h> #include "Particle.h" -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" class SDLApp { public: diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index b246cc9..10b3b49 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -2,7 +2,7 @@ #include "AudioSource.h" -#include "Sound.h" +#include "../Sound.h" #include <memory> using namespace crepe::api; diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 37c194d..f2d45eb 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -2,14 +2,15 @@ target_sources(crepe PUBLIC # AudioSource.cpp BehaviorScript.cpp Script.cpp + GameObject.cpp + Rigidbody.cpp + Force.cpp + ParticleEmitter.cpp + Transform.cpp Color.cpp Texture.cpp - Sprite.cpp - Transform.cpp AssetManager.cpp - GameObject.cpp Collider.cpp - Rigidbody.cpp Sprite.cpp ) @@ -19,13 +20,10 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Script.h GameObject.h GameObject.hpp - Collider.h Rigidbody.h Sprite.h Point.h - Transform.h - Color.h - Sprite.h + Color.h Texture.h AssetManager.h ) diff --git a/src/crepe/CircleCollider.h b/src/crepe/api/CircleCollider.h index 922477b..4a4883c 100644 --- a/src/crepe/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -1,7 +1,7 @@ #pragma once -#include "Collider.h" +#include "../Collider.h" -namespace crepe { +namespace crepe::api { class CircleCollider : public Collider { public: diff --git a/src/crepe/Force.cpp b/src/crepe/api/Force.cpp index b314f49..1b4c81a 100644 --- a/src/crepe/Force.cpp +++ b/src/crepe/api/Force.cpp @@ -1,7 +1,7 @@ #include "Force.h" #include <cmath> -namespace crepe { +namespace crepe::api { Force::Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction): Component(gameObjectId) { @@ -11,4 +11,4 @@ Force::Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction) force_y = static_cast<int32_t>(std::round(forceMagnitude * std::sin(radian_direction))); } -} // namespace crepe +} // namespace crepe::api diff --git a/src/crepe/Force.h b/src/crepe/api/Force.h index a121ec2..0b06da1 100644 --- a/src/crepe/Force.h +++ b/src/crepe/api/Force.h @@ -1,10 +1,10 @@ #pragma once -#include "Component.h" +#include "../Component.h" #include <cstdint> #include <utility> -namespace crepe { +namespace crepe::api { class Force : public Component { public: diff --git a/src/crepe/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp index 318c6db..318c6db 100644 --- a/src/crepe/ParticleEmitter.cpp +++ b/src/crepe/api/ParticleEmitter.cpp diff --git a/src/crepe/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h index 8cd78a9..8cd78a9 100644 --- a/src/crepe/ParticleEmitter.h +++ b/src/crepe/api/ParticleEmitter.h diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index c16a300..e59e217 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -1,6 +1,6 @@ #pragma once -#include "Component.h" +#include "../Component.h" #include <cstdint> namespace crepe::api{ diff --git a/src/example/Physics.cpp b/src/example/Physics.cpp index 9ad6da0..6499fb0 100644 --- a/src/example/Physics.cpp +++ b/src/example/Physics.cpp @@ -2,13 +2,14 @@ #include <thread> #include <chrono> #include "Transform.h" -#include "Rigidbody.h" -#include "Force.h" +#include <crepe/api/Rigidbody.h> +#include <crepe/api/Force.h> #include "PhysicsSystem.h" #include <crepe/Component.h> #include <crepe/ComponentManager.h> -#include <crepe/GameObject.h> +#include <crepe/api/GameObject.h> +using namespace crepe::api; using namespace crepe; using namespace std; @@ -18,6 +19,8 @@ int main(int argc, char* argv[]) { GameObject * game_object[2]; game_object[1] = new GameObject(2, "Name", "Tag", 0); // not found not used game_object[0] = new GameObject(5, "Name", "Tag", 0); + Position position = {0, 0}; + game_object[0]->add_component<Transform>(position,0,0); game_object[0]->add_component<Rigidbody>(1, 1 , BodyType::Dynamic); game_object[0]->add_component<Force>(1 , 0); physicsSystem.update(); diff --git a/src/example/particle.cpp b/src/example/particle.cpp index df1dbfd..fb89a3d 100644 --- a/src/example/particle.cpp +++ b/src/example/particle.cpp @@ -2,14 +2,15 @@ #include <thread> #include <chrono> #include "SDLApp.h" -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" #include "ParticleSystem.h" #include "Particle.h" #include <crepe/Component.h> #include <crepe/ComponentManager.h> -#include <crepe/GameObject.h> +#include <crepe/api/GameObject.h> #include <chrono> +using namespace crepe::api; using namespace crepe; using namespace std; |