diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/BehaviorScript.h | 2 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.hpp | 1 | ||||
-rw-r--r-- | src/crepe/api/Components.h | 16 | ||||
-rw-r--r-- | src/crepe/api/Config.h | 3 | ||||
-rw-r--r-- | src/crepe/api/Engine.cpp | 14 | ||||
-rw-r--r-- | src/crepe/api/Vector2.h | 39 | ||||
-rw-r--r-- | src/crepe/api/Vector2.hpp | 9 |
7 files changed, 61 insertions, 23 deletions
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 3909b96..52cf259 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -48,6 +48,8 @@ public: BehaviorScript & set_script(Args &&... args); protected: + //! Script type name + std::string name = "unknown script"; //! Script instance std::unique_ptr<Script> script = nullptr; //! ScriptSystem needs direct access to the script instance diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp index 353d5e2..218f27c 100644 --- a/src/crepe/api/BehaviorScript.hpp +++ b/src/crepe/api/BehaviorScript.hpp @@ -11,6 +11,7 @@ template <class T, typename... Args> BehaviorScript & BehaviorScript::set_script(Args &&... args) { static_assert(std::is_base_of<Script, T>::value); this->script = std::unique_ptr<Script>(new T(std::forward<Args>(args)...)); + this->name = typeid(T).name(); this->script->game_object_id = this->game_object_id; this->script->active = this->active; diff --git a/src/crepe/api/Components.h b/src/crepe/api/Components.h new file mode 100644 index 0000000..fa0663d --- /dev/null +++ b/src/crepe/api/Components.h @@ -0,0 +1,16 @@ +#pragma once + +#include "AI.h" +#include "Animator.h" +#include "AudioSource.h" +#include "BehaviorScript.h" +#include "BoxCollider.h" +#include "Button.h" +#include "Camera.h" +#include "CircleCollider.h" +#include "Metadata.h" +#include "ParticleEmitter.h" +#include "Rigidbody.h" +#include "Sprite.h" +#include "Text.h" +#include "Transform.h" diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index 6b9e3ca..32f1a2e 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -60,7 +60,8 @@ struct Config final { struct { //! default screen size in pixels ivec2 default_size = {1280, 720}; - std::string window_title = "Jetpack joyride clone"; + //! default window title + std::string window_title = "crepe window"; } window_settings; //! Asset loading options diff --git a/src/crepe/api/Engine.cpp b/src/crepe/api/Engine.cpp index cd9786b..bfc1c4a 100644 --- a/src/crepe/api/Engine.cpp +++ b/src/crepe/api/Engine.cpp @@ -1,3 +1,6 @@ +#include <segvcatch.h> + +#include "../facade/SignalCatch.h" #include "../util/Log.h" #include "Engine.h" @@ -6,6 +9,8 @@ using namespace crepe; using namespace std; int Engine::main() noexcept { + SignalCatch signal_catch; + try { this->setup(); } catch (const exception & e) { @@ -45,23 +50,24 @@ void Engine::loop() { while (timer.get_lag() >= timer.get_fixed_delta_time()) { try { systems.fixed_update(); + timer.advance_fixed_elapsed_time(); } catch (const exception & e) { Log::logf( - Log::Level::WARNING, "Uncaught exception in fixed update function: {}\n", + Log::Level::WARNING, "Uncaught exception in fixed update function: {}", e.what() ); } - timer.advance_fixed_elapsed_time(); } try { systems.frame_update(); + timer.enforce_frame_rate(); } catch (const exception & e) { Log::logf( - Log::Level::WARNING, "Uncaught exception in frame update function: {}\n", + Log::Level::WARNING, "Uncaught exception in frame update function: {}", e.what() ); } - timer.enforce_frame_rate(); } } + diff --git a/src/crepe/api/Vector2.h b/src/crepe/api/Vector2.h index 52e1bb6..0f46964 100644 --- a/src/crepe/api/Vector2.h +++ b/src/crepe/api/Vector2.h @@ -11,55 +11,55 @@ struct Vector2 { T y = 0; //! Subtracts another vector from this vector and returns the result. - Vector2 operator-(const Vector2<T> & other) const; + Vector2<T> operator-(const Vector2<T> & other) const; //! Subtracts a scalar value from both components of this vector and returns the result. - Vector2 operator-(T scalar) const; + Vector2<T> operator-(T scalar) const; //! Adds another vector to this vector and returns the result. - Vector2 operator+(const Vector2<T> & other) const; + Vector2<T> operator+(const Vector2<T> & other) const; //! Adds a scalar value to both components of this vector and returns the result. - Vector2 operator+(T scalar) const; + Vector2<T> operator+(T scalar) const; //! Multiplies this vector by another vector element-wise and returns the result. - Vector2 operator*(const Vector2<T> & other) const; + Vector2<T> operator*(const Vector2<T> & other) const; //! Multiplies this vector by a scalar and returns the result. - Vector2 operator*(T scalar) const; + Vector2<T> operator*(T scalar) const; //! Divides this vector by another vector element-wise and returns the result. - Vector2 operator/(const Vector2<T> & other) const; + Vector2<T> operator/(const Vector2<T> & other) const; //! Divides this vector by a scalar and returns the result. - Vector2 operator/(T scalar) const; + Vector2<T> operator/(T scalar) const; //! Adds another vector to this vector and updates this vector. - Vector2 & operator+=(const Vector2<T> & other); + Vector2<T> & operator+=(const Vector2<T> & other); //! Adds a scalar value to both components of this vector and updates this vector. - Vector2 & operator+=(T other); + Vector2<T> & operator+=(T other); //! Subtracts another vector from this vector and updates this vector. - Vector2 & operator-=(const Vector2<T> & other); + Vector2<T> & operator-=(const Vector2<T> & other); //! Subtracts a scalar value from both components of this vector and updates this vector. - Vector2 & operator-=(T other); + Vector2<T> & operator-=(T other); //! Multiplies this vector by another vector element-wise and updates this vector. - Vector2 & operator*=(const Vector2<T> & other); + Vector2<T> & operator*=(const Vector2<T> & other); //! Multiplies this vector by a scalar and updates this vector. - Vector2 & operator*=(T other); + Vector2<T> & operator*=(T other); //! Divides this vector by another vector element-wise and updates this vector. - Vector2 & operator/=(const Vector2<T> & other); + Vector2<T> & operator/=(const Vector2<T> & other); //! Divides this vector by a scalar and updates this vector. - Vector2 & operator/=(T other); + Vector2<T> & operator/=(T other); //! Returns the negation of this vector. - Vector2 operator-() const; + Vector2<T> operator-() const; //! Checks if this vector is equal to another vector. bool operator==(const Vector2<T> & other) const; @@ -89,10 +89,13 @@ struct Vector2 { T distance_squared(const Vector2<T> & other) const; //! Returns the perpendicular vector to this vector. - Vector2 perpendicular() const; + Vector2<T> perpendicular() const; //! Checks if both components of the vector are NaN. bool is_nan() const; + + //! Rotate this vector clockwise by \c deg degrees + Vector2<T> rotate(float deg) const; }; } // namespace crepe diff --git a/src/crepe/api/Vector2.hpp b/src/crepe/api/Vector2.hpp index e195760..5709f46 100644 --- a/src/crepe/api/Vector2.hpp +++ b/src/crepe/api/Vector2.hpp @@ -168,4 +168,13 @@ bool Vector2<T>::is_nan() const { return std::isnan(x) && std::isnan(y); } +template <class T> +Vector2<T> Vector2<T>::rotate(float deg) const { + float rad = -deg / 180 * M_PI; + return { + x * std::cos(rad) - y * std::sin(rad), + x * std::sin(rad) + y * std::cos(rad), + }; +} + } // namespace crepe |