diff options
Diffstat (limited to 'src/crepe')
-rw-r--r-- | src/crepe/ComponentManager.cpp | 2 | ||||
-rw-r--r-- | src/crepe/ComponentManager.h | 2 | ||||
-rw-r--r-- | src/crepe/Particle.cpp | 4 | ||||
-rw-r--r-- | src/crepe/Particle.h | 10 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/api/GameObject.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 4 | ||||
-rw-r--r-- | src/crepe/api/ParticleEmitter.h | 6 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h | 8 | ||||
-rw-r--r-- | src/crepe/api/Transform.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/Transform.h | 5 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 4 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 8 | ||||
-rw-r--r-- | src/crepe/system/ParticleSystem.cpp | 9 | ||||
-rw-r--r-- | src/crepe/system/PhysicsSystem.cpp | 2 |
16 files changed, 38 insertions, 35 deletions
diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp index e310577..20c6dd4 100644 --- a/src/crepe/ComponentManager.cpp +++ b/src/crepe/ComponentManager.cpp @@ -26,7 +26,7 @@ void ComponentManager::delete_all_components() { } GameObject ComponentManager::new_object(const string & name, const string & tag, - const Vector2 & position, double rotation, + const Vector2<double> & position, double rotation, double scale) { GameObject object{*this, this->next_id, name, tag, position, rotation, scale}; this->next_id++; diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h index 0956d1e..906e3a7 100644 --- a/src/crepe/ComponentManager.h +++ b/src/crepe/ComponentManager.h @@ -45,7 +45,7 @@ public: * \note This method automatically assigns a new entity ID */ GameObject new_object(const std::string & name, const std::string & tag = "", - const Vector2 & position = {0, 0}, double rotation = 0, + const Vector2<double> & position = {0, 0}, double rotation = 0, double scale = 1); protected: diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp index 1068cbf..4c994fa 100644 --- a/src/crepe/Particle.cpp +++ b/src/crepe/Particle.cpp @@ -2,8 +2,8 @@ using namespace crepe; -void Particle::reset(uint32_t lifespan, const Vector2 & position, const Vector2 & velocity, - double angle) { +void Particle::reset(uint32_t lifespan, const Vector2<double> & position, + const Vector2<double> & velocity, double angle) { // Initialize the particle state this->time_in_life = 0; this->lifespan = lifespan; diff --git a/src/crepe/Particle.h b/src/crepe/Particle.h index 19859fe..570c9be 100644 --- a/src/crepe/Particle.h +++ b/src/crepe/Particle.h @@ -18,11 +18,11 @@ class Particle { public: //! Position of the particle in 2D space. - Vector2 position; + Vector2<double> position; //! Velocity vector indicating the speed and direction of the particle. - Vector2 velocity; + Vector2<double> velocity; //! Accumulated force affecting the particle over time. - Vector2 force_over_time; + Vector2<double> force_over_time; //! Total lifespan of the particle in milliseconds. uint32_t lifespan; //! Active state of the particle; true if it is in use, false otherwise. @@ -43,8 +43,8 @@ public: * \param velocity The initial velocity of the particle. * \param angle The angle of the particle's trajectory or orientation. */ - void reset(uint32_t lifespan, const Vector2 & position, const Vector2 & velocity, - double angle); + void reset(uint32_t lifespan, const Vector2<double> & position, + const Vector2<double> & velocity, double angle); /** * \brief Updates the particle's state. * diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index d6b6801..92ff328 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -14,7 +14,6 @@ target_sources(crepe PUBLIC Metadata.cpp Scene.cpp SceneManager.cpp - Vector2.cpp Camera.cpp Animator.cpp EventManager.cpp @@ -37,6 +36,7 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Rigidbody.h Sprite.h Vector2.h + Vector2.hpp Color.h Texture.h AssetManager.h diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 4874426..49bb158 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -9,7 +9,7 @@ using namespace std; GameObject::GameObject(ComponentManager & component_manager, game_object_id_t id, const std::string & name, const std::string & tag, - const Vector2 & position, double rotation, double scale) + const Vector2<double> & position, double rotation, double scale) : id(id), component_manager(component_manager) { diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index 34ef8bb..29c9fcd 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -30,8 +30,8 @@ private: * \param scale The scale of the GameObject */ GameObject(ComponentManager & component_manager, game_object_id_t id, - const std::string & name, const std::string & tag, const Vector2 & position, - double rotation, double scale); + const std::string & name, const std::string & tag, + const Vector2<double> & position, double rotation, double scale); //! ComponentManager instances GameObject friend class ComponentManager; diff --git a/src/crepe/api/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h index 33112e1..1960d0d 100644 --- a/src/crepe/api/ParticleEmitter.h +++ b/src/crepe/api/ParticleEmitter.h @@ -30,7 +30,7 @@ public: //! boundary height (midpoint is emitter location) double height = 0.0; //! boundary offset from particle emitter location - Vector2 offset; + Vector2<double> offset; //! reset on exit or stop velocity and set max postion bool reset_on_exit = false; }; @@ -43,7 +43,7 @@ public: */ struct Data { //! position of the emitter - Vector2 position; + Vector2<double> position; //! maximum number of particles const unsigned int max_particles = 0; //! rate of particle emission per update (Lowest value = 0.001 any lower is ignored) @@ -61,7 +61,7 @@ public: //! end Lifespan of particle double end_lifespan = 0.0; //! force over time (physics) - Vector2 force_over_time; + Vector2<double> force_over_time; //! particle boundary Boundary boundary; //! collection of particles diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp index 6b87695..384aabb 100644 --- a/src/crepe/api/Rigidbody.cpp +++ b/src/crepe/api/Rigidbody.cpp @@ -6,7 +6,7 @@ crepe::Rigidbody::Rigidbody(game_object_id_t id, const Data & data) : Component(id), data(data) {} -void crepe::Rigidbody::add_force_linear(const Vector2 & force) { +void crepe::Rigidbody::add_force_linear(const Vector2<double> & force) { this->data.linear_velocity += force; } diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index 3e5c7a3..4745d56 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -56,11 +56,11 @@ public: //! Changes if physics apply BodyType body_type = BodyType::DYNAMIC; //! linear velocity of object - Vector2 linear_velocity; + Vector2<double> linear_velocity; //! maximum linear velocity of object - Vector2 max_linear_velocity; + Vector2<double> max_linear_velocity; //! linear damping of object - Vector2 linear_damping; + Vector2<double> linear_damping; //! angular velocity of object double angular_velocity = 0.0; //! max angular velocity of object @@ -90,7 +90,7 @@ public: * * \param force Vector2 that is added to the linear force. */ - void add_force_linear(const Vector2 & force); + void add_force_linear(const Vector2<double> & force); /** * \brief add a angular force to the Rigidbody. * diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index cd944bd..1ca5b4d 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -4,7 +4,8 @@ using namespace crepe; -Transform::Transform(game_object_id_t id, const Vector2 & point, double rotation, double scale) +Transform::Transform(game_object_id_t id, const Vector2<double> & point, double rotation, + double scale) : Component(id), position(point), rotation(rotation), diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h index 18aa293..b0488f5 100644 --- a/src/crepe/api/Transform.h +++ b/src/crepe/api/Transform.h @@ -15,7 +15,7 @@ namespace crepe { class Transform : public Component { public: //! Translation (shift) - Vector2 position = {0, 0}; + Vector2<double> position = {0, 0}; //! Rotation, in degrees double rotation = 0; //! Multiplication factor @@ -28,7 +28,8 @@ protected: * \param rotation The rotation of the GameObject * \param scale The scale of the GameObject */ - Transform(game_object_id_t id, const Vector2 & point, double rotation, double scale); + Transform(game_object_id_t id, const Vector2<double> & point, double rotation, + double scale); /** * There is always exactly one transform component per entity * \return 1 diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 00523a6..c808d41 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -104,7 +104,7 @@ SDL_Rect SDLContext::get_src_rect(const Sprite & sprite) const { .h = sprite.sprite_rect.h, }; } -SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const Vector2 & pos, +SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const Vector2<double> & pos, const double & scale, const Camera & cam) const { double adjusted_x = (pos.x - cam.x) * cam.zoom; @@ -120,7 +120,7 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const Vector2 & pos, }; } -void SDLContext::draw_particle(const Sprite & sprite, const Vector2 & pos, +void SDLContext::draw_particle(const Sprite & sprite, const Vector2<double> & pos, const double & angle, const double & scale, const Camera & camera) { diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 841ffc9..e4a0da5 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -120,8 +120,8 @@ private: */ void draw(const Sprite & sprite, const Transform & transform, const Camera & camera); - void draw_particle(const Sprite & sprite, const Vector2 & pos, const double & angle, - const double & scale, const Camera & camera); + void draw_particle(const Sprite & sprite, const Vector2<double> & pos, + const double & angle, const double & scale, const Camera & camera); //! Clears the screen, preparing for a new frame. void clear_screen(); @@ -153,8 +153,8 @@ private: * on the camera * \return sdl rectangle to draw a dst image to draw on the screen */ - SDL_Rect get_dst_rect(const Sprite & sprite, const Vector2 & pos, const double & scale, - const Camera & cam) const; + SDL_Rect get_dst_rect(const Sprite & sprite, const Vector2<double> & pos, + const double & scale, const Camera & cam) const; private: //! sdl Window diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index fcf7522..b839f35 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -44,7 +44,7 @@ void ParticleSystem::update() { void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform & transform) { constexpr double DEG_TO_RAD = M_PI / 180.0; - Vector2 initial_position = emitter.data.position + transform.position; + Vector2<double> initial_position = emitter.data.position + transform.position; double random_angle = generate_random_angle(emitter.data.min_angle, emitter.data.max_angle); @@ -52,7 +52,7 @@ void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform & = generate_random_speed(emitter.data.min_speed, emitter.data.max_speed); double angle_radians = random_angle * DEG_TO_RAD; - Vector2 velocity + Vector2<double> velocity = {random_speed * std::cos(angle_radians), random_speed * std::sin(angle_radians)}; for (Particle & particle : emitter.data.particles) { @@ -77,7 +77,8 @@ int ParticleSystem::calculate_update(int count, double emission) const { } void ParticleSystem::check_bounds(ParticleEmitter & emitter, const Transform & transform) { - Vector2 offset = emitter.data.boundary.offset + transform.position + emitter.data.position; + Vector2<double> offset + = emitter.data.boundary.offset + transform.position + emitter.data.position; double half_width = emitter.data.boundary.width / 2.0; double half_height = emitter.data.boundary.height / 2.0; @@ -87,7 +88,7 @@ void ParticleSystem::check_bounds(ParticleEmitter & emitter, const Transform & t const double BOTTOM = offset.y + half_height; for (Particle & particle : emitter.data.particles) { - const Vector2 & position = particle.position; + const Vector2<double> & position = particle.position; bool within_bounds = (position.x >= LEFT && position.x <= RIGHT && position.y >= TOP && position.y <= BOTTOM); diff --git a/src/crepe/system/PhysicsSystem.cpp b/src/crepe/system/PhysicsSystem.cpp index bcde431..e7ecd14 100644 --- a/src/crepe/system/PhysicsSystem.cpp +++ b/src/crepe/system/PhysicsSystem.cpp @@ -34,7 +34,7 @@ void PhysicsSystem::update() { if (rigidbody.data.angular_damping != 0) { rigidbody.data.angular_velocity *= rigidbody.data.angular_damping; } - if (rigidbody.data.linear_damping != Vector2{0, 0}) { + if (rigidbody.data.linear_damping != Vector2<double>{0, 0}) { rigidbody.data.linear_velocity *= rigidbody.data.linear_damping; } |