diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-11-24 11:58:23 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-11-24 11:58:23 +0100 |
commit | f235743e60fd183319d3cdfb103318739ecbb1e9 (patch) | |
tree | 30817cbc4977f6ffc7951268cb6696e408480b5f /src/crepe/system | |
parent | b1caa74439b404e4b3fe911836004dd7cb47dd50 (diff) | |
parent | 1499363d85abedbdb571e33801b821f4dfabc638 (diff) |
Merge remote-tracking branch 'origin/master' into max/ecs
Diffstat (limited to 'src/crepe/system')
-rw-r--r-- | src/crepe/system/ParticleSystem.cpp | 19 | ||||
-rw-r--r-- | src/crepe/system/PhysicsSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/system/ScriptSystem.cpp | 29 | ||||
-rw-r--r-- | src/crepe/system/ScriptSystem.h | 11 |
4 files changed, 17 insertions, 44 deletions
diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index fcf7522..0e62a57 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -4,7 +4,6 @@ #include "api/ParticleEmitter.h" #include "api/Transform.h" -#include "api/Vector2.h" #include "ComponentManager.h" #include "ParticleSystem.h" @@ -42,17 +41,15 @@ void ParticleSystem::update() { } void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform & transform) { - constexpr double DEG_TO_RAD = M_PI / 180.0; + constexpr float DEG_TO_RAD = M_PI / 180.0; - Vector2 initial_position = emitter.data.position + transform.position; - double random_angle - = generate_random_angle(emitter.data.min_angle, emitter.data.max_angle); + vec2 initial_position = emitter.data.position + transform.position; + float random_angle = generate_random_angle(emitter.data.min_angle, emitter.data.max_angle); - double random_speed - = generate_random_speed(emitter.data.min_speed, emitter.data.max_speed); - double angle_radians = random_angle * DEG_TO_RAD; + float random_speed = generate_random_speed(emitter.data.min_speed, emitter.data.max_speed); + float angle_radians = random_angle * DEG_TO_RAD; - Vector2 velocity + vec2 velocity = {random_speed * std::cos(angle_radians), random_speed * std::sin(angle_radians)}; for (Particle & particle : emitter.data.particles) { @@ -77,7 +74,7 @@ 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; + vec2 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 +84,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 vec2 & 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..514a4b3 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 != vec2{0, 0}) { rigidbody.data.linear_velocity *= rigidbody.data.linear_damping; } diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index c33309c..20a83f7 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -1,5 +1,3 @@ -#include <functional> - #include "../ComponentManager.h" #include "../api/BehaviorScript.h" #include "../api/Script.h" @@ -12,30 +10,19 @@ using namespace crepe; void ScriptSystem::update() { dbg_trace(); - RefVector<Script> scripts = this->get_scripts(); - - for (auto & script_ref : scripts) { - Script & script = script_ref.get(); - if (!script.initialized) { - script.init(); - script.initialized = true; - } - script.update(); - } -} - -RefVector<Script> ScriptSystem::get_scripts() const { - RefVector<Script> scripts = {}; ComponentManager & mgr = this->component_manager; RefVector<BehaviorScript> behavior_scripts = mgr.get_components_by_type<BehaviorScript>(); - for (auto behavior_script_ref : behavior_scripts) { - BehaviorScript & behavior_script = behavior_script_ref.get(); + for (BehaviorScript & behavior_script : behavior_scripts) { if (!behavior_script.active) continue; + Script * script = behavior_script.script.get(); if (script == nullptr) continue; - scripts.push_back(*script); - } - return scripts; + if (!script->initialized) { + script->init(); + script->initialized = true; + } + script->update(); + } } diff --git a/src/crepe/system/ScriptSystem.h b/src/crepe/system/ScriptSystem.h index 32e1fcd..936e9ca 100644 --- a/src/crepe/system/ScriptSystem.h +++ b/src/crepe/system/ScriptSystem.h @@ -2,8 +2,6 @@ #include "System.h" -#include "../types.h" - namespace crepe { class Script; @@ -25,15 +23,6 @@ public: * the \c BehaviorScript instance. */ void update() override; - -private: - /** - * \brief Aggregate all active \c BehaviorScript components and return a list - * of references to their \c Script instances (utility) - * - * \returns List of active \c Script instances - */ - RefVector<Script> get_scripts() const; }; } // namespace crepe |