diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 23 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.h | 41 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.cpp | 7 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.h | 36 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.hpp | 19 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 21 | ||||
-rw-r--r-- | src/crepe/api/Collider.cpp | 5 | ||||
-rw-r--r-- | src/crepe/api/Collider.h | 14 | ||||
-rw-r--r-- | src/crepe/api/GameObject.cpp | 7 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 24 | ||||
-rw-r--r-- | src/crepe/api/GameObject.hpp | 15 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.cpp | 6 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h | 16 | ||||
-rw-r--r-- | src/crepe/api/Script.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/Script.h | 21 | ||||
-rw-r--r-- | src/crepe/api/Sprite.cpp | 8 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 16 |
17 files changed, 282 insertions, 0 deletions
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp new file mode 100644 index 0000000..bb067dc --- /dev/null +++ b/src/crepe/api/AudioSource.cpp @@ -0,0 +1,23 @@ +#include <memory> + +#include "AudioSource.h" + +#include "../Sound.h" + +using namespace crepe::api; + +AudioSource::AudioSource(std::unique_ptr<Asset> audio_clip) { + this->sound = std::make_unique<crepe::Sound>(std::move(audio_clip)); +} + +void AudioSource::play() { return this->play(false); } + +void AudioSource::play(bool looping) { + this->sound->set_looping(looping); + this->sound->play(); +} + +void AudioSource::stop() { + this->sound->pause(); + this->sound->rewind(); +} diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h new file mode 100644 index 0000000..7980212 --- /dev/null +++ b/src/crepe/api/AudioSource.h @@ -0,0 +1,41 @@ +#pragma once + +#include <memory> + +#include "../Asset.h" +#include "../Component.h" + +namespace crepe { +class Sound; +} + +namespace crepe::api { + +//! Audio source component +class AudioSource : Component { +public: + AudioSource(std::unique_ptr<Asset> audio_clip); + virtual ~AudioSource() = default; + +public: + //! Start or resume this audio source + void play(); + void play(bool looping); + //! Stop this audio source + void stop(); + +public: + //! Sample file location + std::unique_ptr<Asset> audio_clip; + //! TODO: ????? + bool play_on_awake; + //! Repeat the current audio clip during playback + bool loop; + //! Normalized volume (0.0 - 1.0) + float volume; + +private: + std::unique_ptr<crepe::Sound> sound; +}; + +} // namespace crepe::api diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp new file mode 100644 index 0000000..84bfd4c --- /dev/null +++ b/src/crepe/api/BehaviorScript.cpp @@ -0,0 +1,7 @@ +#include "../util/log.h" + +#include "BehaviorScript.h" + +using namespace crepe::api; + +BehaviorScript::BehaviorScript() { dbg_trace(); } diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h new file mode 100644 index 0000000..25d3cc5 --- /dev/null +++ b/src/crepe/api/BehaviorScript.h @@ -0,0 +1,36 @@ +#pragma once + +#include <memory> + +#include "../Component.h" +#include "Script.h" + +namespace crepe { +class ScriptSystem; +class ComponentManager; +} // namespace crepe + +namespace crepe::api { + +class Script; + +class BehaviorScript : public Component { +protected: + friend class crepe::ComponentManager; + BehaviorScript(); + +public: + virtual ~BehaviorScript() = default; + +public: + template <class T> + BehaviorScript & set_script(); + +protected: + friend class crepe::ScriptSystem; + std::unique_ptr<Script> script = nullptr; +}; + +} // namespace crepe::api + +#include "BehaviorScript.hpp" diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp new file mode 100644 index 0000000..a6bd81c --- /dev/null +++ b/src/crepe/api/BehaviorScript.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include <type_traits> + +#include "../util/log.h" +#include "BehaviorScript.h" + +namespace crepe::api { + +template <class T> +BehaviorScript & BehaviorScript::set_script() { + static_assert(std::is_base_of<Script, T>::value); + dbg_trace(); + Script * s = new T(); + this->script = std::unique_ptr<Script>(s); + return *this; +} + +} // namespace crepe::api diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt new file mode 100644 index 0000000..ae92f3d --- /dev/null +++ b/src/crepe/api/CMakeLists.txt @@ -0,0 +1,21 @@ +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 <cstdint> +#include <string> + +namespace crepe::api { + +class GameObject { +public: + GameObject(uint32_t id, std::string name, std::string tag, int layer); + + template <typename T, typename... Args> + 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 <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::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/Script.cpp b/src/crepe/api/Script.cpp new file mode 100644 index 0000000..5016ed0 --- /dev/null +++ b/src/crepe/api/Script.cpp @@ -0,0 +1,3 @@ +#include "Script.h" + +using namespace crepe::api; diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h new file mode 100644 index 0000000..0036d1f --- /dev/null +++ b/src/crepe/api/Script.h @@ -0,0 +1,21 @@ +#pragma once + +namespace crepe { +class ScriptSystem; +} + +namespace crepe::api { + +class Script { + friend class crepe::ScriptSystem; + +protected: + virtual void init() {} + virtual void update() {} + // NOTE: additional *events* (like unity's OnDisable and OnEnable) should be + // implemented as member methods in derivative user script classes and + // registered in init(), otherwise this class will balloon in size with each + // added event. +}; + +} // 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 <string> + +#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 <string> + +#include "../Component.h" + +namespace crepe::api { + +class Sprite : public Component { +public: + Sprite(std::string path); + + std::string path; +}; + +} // namespace crepe::api |