From 04a040e28ade412ea5b1767bf77eed3956121973 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 23 Oct 2024 13:12:18 +0200 Subject: move user-facing classes to api namespace --- src/crepe/CMakeLists.txt | 9 --------- src/crepe/Collider.cpp | 5 ----- src/crepe/Collider.h | 14 -------------- src/crepe/Component.h | 3 +-- src/crepe/GameObject.cpp | 7 ------- src/crepe/GameObject.h | 24 ------------------------ src/crepe/GameObject.hpp | 15 --------------- src/crepe/Rigidbody.cpp | 6 ------ src/crepe/Rigidbody.h | 16 ---------------- src/crepe/Sprite.cpp | 8 -------- src/crepe/Sprite.h | 16 ---------------- src/crepe/api/AudioSource.cpp | 3 ++- src/crepe/api/AudioSource.h | 4 ++-- src/crepe/api/BehaviorScript.cpp | 1 - src/crepe/api/BehaviorScript.h | 2 +- src/crepe/api/CMakeLists.txt | 9 +++++++++ src/crepe/api/Collider.cpp | 5 +++++ src/crepe/api/Collider.h | 14 ++++++++++++++ src/crepe/api/GameObject.cpp | 7 +++++++ src/crepe/api/GameObject.h | 24 ++++++++++++++++++++++++ src/crepe/api/GameObject.hpp | 15 +++++++++++++++ src/crepe/api/Rigidbody.cpp | 6 ++++++ src/crepe/api/Rigidbody.h | 16 ++++++++++++++++ src/crepe/api/Sprite.cpp | 8 ++++++++ src/crepe/api/Sprite.h | 16 ++++++++++++++++ src/example/CMakeLists.txt | 4 ++++ src/example/components_internal.cpp | 11 +++++++---- src/example/script.cpp | 2 +- src/readme.md | 3 ++- 29 files changed, 140 insertions(+), 133 deletions(-) delete mode 100644 src/crepe/Collider.cpp delete mode 100644 src/crepe/Collider.h delete mode 100644 src/crepe/GameObject.cpp delete mode 100644 src/crepe/GameObject.h delete mode 100644 src/crepe/GameObject.hpp delete mode 100644 src/crepe/Rigidbody.cpp delete mode 100644 src/crepe/Rigidbody.h delete mode 100644 src/crepe/Sprite.cpp delete mode 100644 src/crepe/Sprite.h create mode 100644 src/crepe/api/Collider.cpp create mode 100644 src/crepe/api/Collider.h create mode 100644 src/crepe/api/GameObject.cpp create mode 100644 src/crepe/api/GameObject.h create mode 100644 src/crepe/api/GameObject.hpp create mode 100644 src/crepe/api/Rigidbody.cpp create mode 100644 src/crepe/api/Rigidbody.h create mode 100644 src/crepe/api/Sprite.cpp create mode 100644 src/crepe/api/Sprite.h (limited to 'src') diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 8323490..cfa51fb 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -4,10 +4,6 @@ target_sources(crepe PUBLIC SoundContext.cpp ComponentManager.cpp Component.cpp - GameObject.cpp - Collider.cpp - Rigidbody.cpp - Sprite.cpp ScriptSystem.cpp ) @@ -18,11 +14,6 @@ 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 ) diff --git a/src/crepe/Collider.cpp b/src/crepe/Collider.cpp deleted file mode 100644 index 3f12afd..0000000 --- a/src/crepe/Collider.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "Collider.h" - -using namespace crepe; - -Collider::Collider(int size) : size(size) {} diff --git a/src/crepe/Collider.h b/src/crepe/Collider.h deleted file mode 100644 index 120da05..0000000 --- a/src/crepe/Collider.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "Component.h" - -namespace crepe { - -class Collider : public Component { -public: - Collider(int size); - - int size; -}; - -} // namespace crepe diff --git a/src/crepe/Component.h b/src/crepe/Component.h index d9a01ac..9cda177 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -8,9 +8,8 @@ protected: public: virtual ~Component() = default; - // TODO: shouldn't this constructor be deleted because this class will never - // directly be instantiated? +public: bool active = true; }; diff --git a/src/crepe/GameObject.cpp b/src/crepe/GameObject.cpp deleted file mode 100644 index de3beb6..0000000 --- a/src/crepe/GameObject.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "GameObject.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) {} diff --git a/src/crepe/GameObject.h b/src/crepe/GameObject.h deleted file mode 100644 index b5d6399..0000000 --- a/src/crepe/GameObject.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include - -namespace crepe { - -class GameObject { -public: - GameObject(uint32_t id, std::string name, std::string tag, int layer); - - template - T & add_component(Args &&... args); - - uint32_t id; - std::string name; - std::string tag; - bool active; - int layer; -}; - -} // namespace crepe - -#include "GameObject.hpp" diff --git a/src/crepe/GameObject.hpp b/src/crepe/GameObject.hpp deleted file mode 100644 index 8cd1abe..0000000 --- a/src/crepe/GameObject.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "GameObject.h" - -#include "ComponentManager.h" - -namespace crepe { - -template -T & GameObject::add_component(Args &&... args) { - auto & mgr = ComponentManager::get_instance(); - return mgr.add_component(id, std::forward(args)...); -} - -} // namespace crepe diff --git a/src/crepe/Rigidbody.cpp b/src/crepe/Rigidbody.cpp deleted file mode 100644 index 495d908..0000000 --- a/src/crepe/Rigidbody.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Rigidbody.h" - -using namespace crepe; - -Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) - : mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} diff --git a/src/crepe/Rigidbody.h b/src/crepe/Rigidbody.h deleted file mode 100644 index 63a8877..0000000 --- a/src/crepe/Rigidbody.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Component.h" - -namespace crepe { - -class Rigidbody : public Component { -public: - Rigidbody(int mass, int gravityScale, int bodyType); - - int mass; - int gravity_scale; - int body_type; -}; - -} // namespace crepe diff --git a/src/crepe/Sprite.cpp b/src/crepe/Sprite.cpp deleted file mode 100644 index a5a5e68..0000000 --- a/src/crepe/Sprite.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#include "Sprite.h" - -using namespace crepe; -using namespace std; - -Sprite::Sprite(string path) : path(path) {} diff --git a/src/crepe/Sprite.h b/src/crepe/Sprite.h deleted file mode 100644 index 143e702..0000000 --- a/src/crepe/Sprite.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -#include "Component.h" - -namespace crepe { - -class Sprite : public Component { -public: - Sprite(std::string path); - - std::string path; -}; - -} // namespace crepe 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 + #include "AudioSource.h" #include "../Sound.h" -#include 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 -#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 1f236b4..84bfd4c 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 -#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..ae92f3d 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 + Collider.cpp + Rigidbody.cpp + Sprite.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES # AudioSource.h BehaviorScript.h Script.h + GameObject.h + GameObject.hpp + Collider.h + Rigidbody.h + Sprite.h ) diff --git a/src/crepe/api/Collider.cpp b/src/crepe/api/Collider.cpp new file mode 100644 index 0000000..6370a42 --- /dev/null +++ b/src/crepe/api/Collider.cpp @@ -0,0 +1,5 @@ +#include "Collider.h" + +using namespace crepe::api; + +Collider::Collider(int size) : size(size) {} diff --git a/src/crepe/api/Collider.h b/src/crepe/api/Collider.h new file mode 100644 index 0000000..72d8e77 --- /dev/null +++ b/src/crepe/api/Collider.h @@ -0,0 +1,14 @@ +#pragma once + +#include "../Component.h" + +namespace crepe::api { + +class Collider : public Component { +public: + Collider(int size); + + int size; +}; + +} // namespace crepe::api 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/api/GameObject.h b/src/crepe/api/GameObject.h new file mode 100644 index 0000000..57508c5 --- /dev/null +++ b/src/crepe/api/GameObject.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +namespace crepe::api { + +class GameObject { +public: + GameObject(uint32_t id, std::string name, std::string tag, int layer); + + template + T & add_component(Args &&... args); + + uint32_t id; + std::string name; + std::string tag; + bool active; + int layer; +}; + +} // namespace crepe::api + +#include "GameObject.hpp" diff --git a/src/crepe/api/GameObject.hpp b/src/crepe/api/GameObject.hpp new file mode 100644 index 0000000..8295ea3 --- /dev/null +++ b/src/crepe/api/GameObject.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "../ComponentManager.h" + +#include "GameObject.h" + +namespace crepe::api { + +template +T & GameObject::add_component(Args &&... args) { + auto & mgr = ComponentManager::get_instance(); + return mgr.add_component(id, std::forward(args)...); +} + +} // namespace crepe::api diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp new file mode 100644 index 0000000..98d1d60 --- /dev/null +++ b/src/crepe/api/Rigidbody.cpp @@ -0,0 +1,6 @@ +#include "Rigidbody.h" + +using namespace crepe::api; + +Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) + : mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h new file mode 100644 index 0000000..6cae579 --- /dev/null +++ b/src/crepe/api/Rigidbody.h @@ -0,0 +1,16 @@ +#pragma once + +#include "../Component.h" + +namespace crepe::api { + +class Rigidbody : public Component { +public: + Rigidbody(int mass, int gravityScale, int bodyType); + + int mass; + int gravity_scale; + int body_type; +}; + +} // namespace crepe::api diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp new file mode 100644 index 0000000..aa7dbb0 --- /dev/null +++ b/src/crepe/api/Sprite.cpp @@ -0,0 +1,8 @@ +#include + +#include "Sprite.h" + +using namespace crepe::api; +using namespace std; + +Sprite::Sprite(string path) : path(path) {} diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h new file mode 100644 index 0000000..580f825 --- /dev/null +++ b/src/crepe/api/Sprite.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "../Component.h" + +namespace crepe::api { + +class Sprite : public Component { +public: + Sprite(std::string path); + + std::string path; +}; + +} // namespace crepe::api diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 6df4ce7..53f584f 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/components_internal.cpp b/src/example/components_internal.cpp index 54ce295..e2169e1 100644 --- a/src/example/components_internal.cpp +++ b/src/example/components_internal.cpp @@ -6,14 +6,17 @@ #include #include -#include #include #include -#include -#include -#include + +#include +#include +#include +#include + #include +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 -#include #include #include #include +#include #include 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 -- cgit v1.2.3