diff options
author | jaroWMR <jarorutjes07@gmail.com> | 2024-10-23 16:22:30 +0200 |
---|---|---|
committer | jaroWMR <jarorutjes07@gmail.com> | 2024-10-23 16:22:30 +0200 |
commit | 5558d2d0530cc01fd8e3c8ce18cc38ce9c6f8057 (patch) | |
tree | d85836ede083ee9faa42eed6fc35bb6b980a8b6a /src | |
parent | 5445331293854aac26af2d5c6a20cedeaa819383 (diff) | |
parent | 04a040e28ade412ea5b1767bf77eed3956121973 (diff) |
merge with master
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/CMakeLists.txt | 13 | ||||
-rw-r--r-- | src/crepe/Component.h | 8 | ||||
-rw-r--r-- | src/crepe/GameObject.cpp | 12 | ||||
-rw-r--r-- | src/crepe/PhysicsSystem.cpp | 5 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.h | 4 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.cpp | 1 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.h | 2 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 9 | ||||
-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/GameObject.cpp | 7 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h (renamed from src/crepe/GameObject.h) | 4 | ||||
-rw-r--r-- | src/crepe/api/GameObject.hpp (renamed from src/crepe/GameObject.hpp) | 8 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.cpp (renamed from src/crepe/Rigidbody.cpp) | 2 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h (renamed from src/crepe/Rigidbody.h) | 6 | ||||
-rw-r--r-- | src/crepe/api/Sprite.cpp (renamed from src/crepe/Sprite.cpp) | 2 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h (renamed from src/crepe/Sprite.h) | 6 | ||||
-rw-r--r-- | src/example/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/example/Physics.cpp | 9 | ||||
-rw-r--r-- | src/example/components_internal.cpp | 11 | ||||
-rw-r--r-- | src/example/script.cpp | 2 | ||||
-rw-r--r-- | src/readme.md | 3 |
24 files changed, 68 insertions, 65 deletions
diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index ef2584e..57c77be 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -9,15 +9,11 @@ target_sources(crepe PUBLIC SDLApp.cpp ComponentManager.cpp Component.cpp - GameObject.cpp - Collider.cpp - Rigidbody.cpp - Sprite.cpp ScriptSystem.cpp PhysicsSystem.cpp Transform.cpp - Force.cpp CollisionSystem.cpp + Collider.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -31,17 +27,12 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES ComponentManager.h ComponentManager.hpp Component.h - GameObject.h - GameObject.hpp - Collider.h - Rigidbody.h - Sprite.h System.h ScriptSystem.h PhysicsSystem.h Transform.h - Force.h CollisionSystem.h + Collider.h ) add_subdirectory(api) 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.cpp b/src/crepe/GameObject.cpp deleted file mode 100644 index 36eb886..0000000 --- a/src/crepe/GameObject.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "GameObject.h" -#include "Transform.h" - -using namespace crepe; - -GameObject::GameObject(uint32_t id, std::string name, std::string tag, - int layer) - : id(id), name(name), tag(tag), active(true), layer(layer) -{ - Position pos = {0,0}; - this->add_component<Transform>(pos, 0, 0); -} diff --git a/src/crepe/PhysicsSystem.cpp b/src/crepe/PhysicsSystem.cpp index 7d16044..e0bbc5b 100644 --- a/src/crepe/PhysicsSystem.cpp +++ b/src/crepe/PhysicsSystem.cpp @@ -1,11 +1,12 @@ #include "PhysicsSystem.h" #include "ComponentManager.h" -#include "Rigidbody.h" +#include "api/Rigidbody.h" #include "Transform.h" -#include "Force.h" +#include "api/Force.h" #include <iostream> using namespace crepe; +using namespace crepe::api; PhysicsSystem::PhysicsSystem() { diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index b512d27..bb067dc 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -1,7 +1,8 @@ +#include <memory> + #include "AudioSource.h" #include "../Sound.h" -#include <memory> using namespace crepe::api; diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 2d26cda..7980212 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -2,8 +2,8 @@ #include <memory> -#include "Asset.h" -#include "Component.h" +#include "../Asset.h" +#include "../Component.h" namespace crepe { class Sound; diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index 063d225..74788ec 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -1,7 +1,6 @@ #include "../util/log.h" #include "BehaviorScript.h" -#include "Script.h" using namespace crepe::api; diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 6ce6798..25d3cc5 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -2,7 +2,7 @@ #include <memory> -#include "Component.h" +#include "../Component.h" #include "Script.h" namespace crepe { diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 6b337be..c97423d 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -2,11 +2,20 @@ target_sources(crepe PUBLIC # AudioSource.cpp BehaviorScript.cpp Script.cpp + GameObject.cpp + Rigidbody.cpp + Sprite.cpp + Force.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES # AudioSource.h BehaviorScript.h Script.h + GameObject.h + GameObject.hpp + Rigidbody.h + Sprite.h + Force.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/api/GameObject.cpp b/src/crepe/api/GameObject.cpp new file mode 100644 index 0000000..b167187 --- /dev/null +++ b/src/crepe/api/GameObject.cpp @@ -0,0 +1,7 @@ +#include "GameObject.h" + +using namespace crepe::api; +using namespace std; + +GameObject::GameObject(uint32_t id, string name, string tag, int layer) + : id(id), name(name), tag(tag), active(true), layer(layer) {} diff --git a/src/crepe/GameObject.h b/src/crepe/api/GameObject.h index b5d6399..57508c5 100644 --- a/src/crepe/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -3,7 +3,7 @@ #include <cstdint> #include <string> -namespace crepe { +namespace crepe::api { class GameObject { public: @@ -19,6 +19,6 @@ public: int layer; }; -} // namespace crepe +} // namespace crepe::api #include "GameObject.hpp" diff --git a/src/crepe/GameObject.hpp b/src/crepe/api/GameObject.hpp index 8cd1abe..8295ea3 100644 --- a/src/crepe/GameObject.hpp +++ b/src/crepe/api/GameObject.hpp @@ -1,10 +1,10 @@ #pragma once -#include "GameObject.h" +#include "../ComponentManager.h" -#include "ComponentManager.h" +#include "GameObject.h" -namespace crepe { +namespace crepe::api { template <typename T, typename... Args> T & GameObject::add_component(Args &&... args) { @@ -12,4 +12,4 @@ T & GameObject::add_component(Args &&... args) { return mgr.add_component<T>(id, std::forward<Args>(args)...); } -} // namespace crepe +} // namespace crepe::api diff --git a/src/crepe/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp index a610e55..30a2cff 100644 --- a/src/crepe/Rigidbody.cpp +++ b/src/crepe/api/Rigidbody.cpp @@ -1,6 +1,6 @@ #include "Rigidbody.h" -using namespace crepe; +using namespace crepe::api; Rigidbody::Rigidbody(uint32_t gameObjectId,int mass, int gravityScale, BodyType bodyType) : Component(gameObjectId), mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} diff --git a/src/crepe/Rigidbody.h b/src/crepe/api/Rigidbody.h index a03346f..b7a0064 100644 --- a/src/crepe/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -1,9 +1,9 @@ #pragma once -#include "Component.h" +#include "../Component.h" #include <cstdint> -namespace crepe { +namespace crepe::api { enum class BodyType { Static, // Does not move (e.g. walls, ground ...) @@ -21,4 +21,4 @@ public: BodyType body_type; }; -} // namespace crepe +} // namespace crepe::api diff --git a/src/crepe/Sprite.cpp b/src/crepe/api/Sprite.cpp index 7f5bca7..4eda466 100644 --- a/src/crepe/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -2,7 +2,7 @@ #include "Sprite.h" -using namespace crepe; +using namespace crepe::api; using namespace std; Sprite::Sprite(uint32_t gameObjectId, string path) : Component(gameObjectId), path(path) {} diff --git a/src/crepe/Sprite.h b/src/crepe/api/Sprite.h index 8c517ed..c06e76c 100644 --- a/src/crepe/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -2,9 +2,9 @@ #include <string> -#include "Component.h" +#include "../Component.h" -namespace crepe { +namespace crepe::api { class Sprite : public Component { public: @@ -13,4 +13,4 @@ public: std::string path; }; -} // namespace crepe +} // namespace crepe::api diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 256d87e..ceb8f9d 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -1,3 +1,6 @@ +# all examples +add_custom_target(examples) + # add_example(target_name [SOURCES...]) function(add_example target_name) # if SOURCES is not specified @@ -10,6 +13,7 @@ function(add_example target_name) add_executable(${target_name} EXCLUDE_FROM_ALL ${sources}) target_link_libraries(${target_name} PUBLIC crepe) + add_dependencies(examples ${target_name}) endfunction() add_example(audio_internal) 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/components_internal.cpp b/src/example/components_internal.cpp index 3ba5b5a..ae6c765 100644 --- a/src/example/components_internal.cpp +++ b/src/example/components_internal.cpp @@ -6,14 +6,17 @@ #include <cassert> #include <chrono> -#include <crepe/Collider.h> #include <crepe/Component.h> #include <crepe/ComponentManager.h> -#include <crepe/GameObject.h> -#include <crepe/Rigidbody.h> -#include <crepe/Sprite.h> + +#include <crepe/api/Collider.h> +#include <crepe/api/GameObject.h> +#include <crepe/api/Rigidbody.h> +#include <crepe/api/Sprite.h> + #include <crepe/util/log.h> +using namespace crepe::api; using namespace crepe; using namespace std; diff --git a/src/example/script.cpp b/src/example/script.cpp index cc585db..6e5563c 100644 --- a/src/example/script.cpp +++ b/src/example/script.cpp @@ -4,11 +4,11 @@ */ #include <crepe/ComponentManager.h> -#include <crepe/GameObject.h> #include <crepe/ScriptSystem.h> #include <crepe/util/log.h> #include <crepe/api/BehaviorScript.h> +#include <crepe/api/GameObject.h> #include <crepe/api/Script.h> using namespace crepe; diff --git a/src/readme.md b/src/readme.md index a4a71e7..a8ffc51 100644 --- a/src/readme.md +++ b/src/readme.md @@ -18,7 +18,8 @@ running the build command: $ ninja -C build test_main ``` -Each source file in the example/ folder corresponds to a CMake target as well: +Each source file in the example/ folder corresponds to a CMake target as well +(all examples can be built at once by specifying the `examples` target): ``` $ ninja -C build audio_internal components_internal |