diff options
Diffstat (limited to 'src/crepe/system')
-rw-r--r-- | src/crepe/system/AnimatorSystem.cpp | 42 | ||||
-rw-r--r-- | src/crepe/system/AudioSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 6 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.h | 5 | ||||
-rw-r--r-- | src/crepe/system/ScriptSystem.cpp | 17 |
5 files changed, 31 insertions, 41 deletions
diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index 467d2a2..143d5d6 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -1,7 +1,8 @@ +#include <chrono> + #include "../api/Animator.h" #include "../manager/ComponentManager.h" #include "../manager/LoopTimerManager.h" -#include <chrono> #include "AnimatorSystem.h" @@ -13,30 +14,31 @@ void AnimatorSystem::frame_update() { LoopTimerManager & timer = this->mediator.loop_timer; RefVector<Animator> animations = mgr.get_components_by_type<Animator>(); - duration_t elapsed = timer.get_delta_time(); - - for (Animator & animator : animations) { - if (!animator.active) continue; + duration_t elapsed_time = timer.get_delta_time(); - Animator::Data & data = animator.data; - if (animator.data.fps == 0) continue; + for (Animator & a : animations) { + if (!a.active) continue; + if (a.data.fps == 0) continue; - if (animator.data.cycle_end == -1) - animator.data.cycle_end = animator.grid_size.x * animator.grid_size.y; + Animator::Data & ctx = a.data; - animator.elapsed += elapsed; - duration_t frame_duration = 1000ms / animator.data.fps; + a.elapsed_time += elapsed_time; + duration_t frame_duration = 1000ms / ctx.fps; - if (animator.elapsed > frame_duration) { - animator.elapsed = 0ms; - animator.data.frame++; - - if (animator.data.looping && animator.data.frame >= animator.data.cycle_end) - animator.data.frame = animator.data.cycle_start; + int cycle_end = (ctx.cycle_end == -1) ? a.grid_size.x : ctx.cycle_end; + if (a.elapsed_time >= frame_duration) { + a.elapsed_time = 0ms; + a.frame++; + if (a.frame == cycle_end) { + a.frame = ctx.cycle_start; + if (!ctx.looping) { + a.active = false; + continue; + } + } } - Sprite::Mask & mask = animator.spritesheet.mask; - mask.x = animator.data.frame % animator.grid_size.x * mask.w; - mask.y = animator.data.frame / animator.grid_size.x * mask.h; + ctx.row = ctx.cycle_start + a.frame; + a.spritesheet.mask.x = ctx.row * a.spritesheet.mask.w; } } diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp index d4e8b9f..3c2232f 100644 --- a/src/crepe/system/AudioSystem.cpp +++ b/src/crepe/system/AudioSystem.cpp @@ -36,6 +36,8 @@ void AudioSystem::diff_update(AudioSource & component, Sound & resource) { if (component.oneshot_play) { component.voice = context.play(resource); + context.set_loop(component.voice, component.loop); + context.set_volume(component.voice, component.volume); component.oneshot_play = false; } if (component.oneshot_stop) { diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index b4a0633..be7eda6 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -1,8 +1,8 @@ #include "../api/Button.h" +#include "../api/Config.h" #include "../facade/SDLContext.h" #include "../manager/ComponentManager.h" #include "../manager/EventManager.h" -#include "util/Log.h" #include "InputSystem.h" @@ -213,10 +213,10 @@ bool InputSystem::is_mouse_inside_button( const Transform & cam_transform ) { vec2 actual_pos = transform.position + button.offset; - if (!button.world_space) { + if (!button.data.world_space) { actual_pos += cam_transform.position; } - vec2 half_dimensions = button.dimensions / 2; + vec2 half_dimensions = button.dimensions * transform.scale / 2; return mouse_pos.x >= actual_pos.x - half_dimensions.x && mouse_pos.x <= actual_pos.x + half_dimensions.x diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 37311cc..be62367 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -1,12 +1,9 @@ #pragma once -#include "../api/Config.h" -#include "../facade/EventData.h" - #include "../api/Event.h" #include "../api/Metadata.h" +#include "../facade/EventData.h" #include "../types.h" -#include "../util/OptionalRef.h" #include "System.h" diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index 411a9a3..ed0c7cc 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -32,21 +32,10 @@ void ScriptSystem::update( if (script == nullptr) continue; if (!script->initialized) { - try { - script->init(); - script->initialized = true; - } catch (const exception & e) { - Log::logf(Log::Level::WARNING, "Disabled script \"{}\" due to exception in init function: {}", behavior_script.name, e.what()); - behavior_script.active = false; - } + script->init(); + script->initialized = true; } - try { - (*script.*update_function)(delta_time); - } catch (const exception & e) { - // TODO: discern between fixed/frame update - Log::logf(Log::Level::WARNING, "Disabled script \"{}\" due to exception in update function: {}", behavior_script.name, e.what()); - behavior_script.active = false; - } + (*script.*update_function)(delta_time); } } |