diff options
-rw-r--r-- | src/crepe/api/Animator.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Animator.h | 11 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 9 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 7 | ||||
-rw-r--r-- | src/crepe/manager/Mediator.h | 2 | ||||
-rw-r--r-- | src/crepe/system/AISystem.cpp | 3 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 4 | ||||
-rw-r--r-- | src/example/sound.cpp | 54 | ||||
-rw-r--r-- | src/test/ParticleTest.cpp | 1 | ||||
-rw-r--r-- | src/test/RenderSystemTest.cpp | 1 |
10 files changed, 79 insertions, 15 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 4c72cc0..123f0e7 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -19,6 +19,8 @@ Animator::Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & sing this->spritesheet.mask.h = single_frame_size.y; this->spritesheet.mask.x = 0; this->spritesheet.mask.y = 0; + + this->spritesheet.aspect_ratio = static_cast<float>(single_frame_size.x) / single_frame_size.y; } Animator::~Animator() { dbg_trace(); } diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 9a26bf0..09f0134 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -75,8 +75,9 @@ public: * * \param id The unique identifier for the component, typically assigned automatically. * \param spritesheet the reference to the spritesheet - * \param max_row maximum of rows inside the given spritesheet - * \param max_col maximum of columns inside the given spritesheet + * \param single_frame_size the width and height in pixels of a single frame inside the + * spritesheet + * \param max_cell_size the max rows and columns inside the given spritesheet * \param data extra animation data for more control * * This constructor sets up the Animator with the given parameters, and initializes the @@ -87,15 +88,15 @@ public: ~Animator(); // dbg_trace public: - //! The maximum number of rows and columns size - const uvec2 max_cell_size; - Animator::Data data; private: //! A reference to the Sprite sheet containing. Sprite & spritesheet; + //! The maximum number of rows and columns size + const uvec2 max_cell_size; + //! Uses the spritesheet friend AnimatorSystem; }; diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 7e9812d..14a873b 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -92,6 +92,15 @@ private: //! Reads the all the variables plus the mask friend class AnimatorSystem; + + /** + * \aspect_ratio the ratio of the sprite image + * + * - this value will only be set by the \c Animator component for the ratio of the Animation + * - if \c Animator component is not added it will not use this ratio (because 0) and will use aspect_ratio of the Asset. + */ + float aspect_ratio = 0; + struct Rect { int w = 0; int h = 0; diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index a0d7f04..0566ecf 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -233,12 +233,14 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { const Sprite::Data & data = ctx.sprite.data; + float aspect_ratio = (ctx.sprite.aspect_ratio == 0) ? ctx.texture.get_ratio() : ctx.sprite.aspect_ratio; + vec2 size = data.size; if (data.size.x == 0 && data.size.y != 0) { - size.x = data.size.y * ctx.texture.get_ratio(); + size.x = data.size.y * aspect_ratio; } if (data.size.y == 0 && data.size.x != 0) { - size.y = data.size.x / ctx.texture.get_ratio(); + size.y = data.size.x / aspect_ratio; } const CameraValues & cam = ctx.cam; @@ -273,7 +275,6 @@ void SDLContext::draw(const RenderContext & ctx) { .img_scale = ctx.scale, }); - cout << srcrect->w << " " << srcrect->h << " " << srcrect->x << " " << srcrect->y << endl; double angle = ctx.angle + data.angle_offset; this->set_color_texture(ctx.texture, ctx.sprite.data.color); diff --git a/src/crepe/manager/Mediator.h b/src/crepe/manager/Mediator.h index d5f7e00..628154a 100644 --- a/src/crepe/manager/Mediator.h +++ b/src/crepe/manager/Mediator.h @@ -4,8 +4,6 @@ // TODO: remove these singletons: #include "EventManager.h" -#include "SaveManager.h" -#include "api/LoopTimer.h" namespace crepe { diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp index e2e36a5..7f04432 100644 --- a/src/crepe/system/AISystem.cpp +++ b/src/crepe/system/AISystem.cpp @@ -12,10 +12,11 @@ using namespace crepe; void AISystem::update() { const Mediator & mediator = this->mediator; ComponentManager & mgr = mediator.component_manager; + LoopTimer & timer = mediator.timer; RefVector<AI> ai_components = mgr.get_components_by_type<AI>(); //TODO: Use fixed loop dt (this is not available at master at the moment) - double dt = LoopTimer::get_instance().get_delta_time(); + double dt = timer.get_delta_time(); // Loop through all AI components for (AI & ai : ai_components) { diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 44bd96a..bd4ef95 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -63,8 +63,8 @@ public: .position_offset = {0, 0}, }); - auto & anim = game_object.add_component<Animator>(test_sprite,ivec2{32, 64}, uvec2{4,1}, Animator::Data{}); - anim.set_anim(0); + //auto & anim = game_object.add_component<Animator>(test_sprite,ivec2{32, 64}, uvec2{4,1}, Animator::Data{}); + //anim.set_anim(0); auto & cam = game_object.add_component<Camera>(ivec2{1280, 720}, vec2{400, 400}, Camera::Data{ diff --git a/src/example/sound.cpp b/src/example/sound.cpp new file mode 100644 index 0000000..a9b0930 --- /dev/null +++ b/src/example/sound.cpp @@ -0,0 +1,54 @@ + + +#include "api/Asset.h" +#include "api/AudioSource.h" +#include "api/BehaviorScript.h" +#include "api/Camera.h" +#include "api/GameObject.h" +#include "api/LoopManager.h" +#include "api/Scene.h" +#include "api/Script.h" +#include "manager/ComponentManager.h" +#include "types.h" +#include <string> + +using namespace crepe; + + +class ScriptTest : public Script { + void init(){ + auto & audio = this->get_component<AudioSource>(); + audio.play(); + } + void update(){ + } +}; + + +class TestSound : public Scene { +public: + void load_scene(){ + Mediator & mediator = this->mediator; + ComponentManager & mgr = mediator.component_manager; + + GameObject obj = mgr.new_object("SOUND"); + GameObject cam = mgr.new_object("cam"); + cam.add_component<Camera>(ivec2{100,100},vec2{100,100}, Camera::Data{}); + + Asset asset{"asset/audio/sample.ogg"}; + auto & test = obj.add_component<AudioSource>(asset); + obj.add_component<BehaviorScript>().set_script<ScriptTest>(); + + + } + + std::string get_name() const { return "TestScene"; }; + +}; + +int main(){ + LoopManager engine; + engine.add_scene<TestSound>(); + engine.start(); + return 0; +} diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index 38f4bde..9112a3f 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -5,7 +5,6 @@ #include <crepe/api/ParticleEmitter.h> #include <crepe/api/Rigidbody.h> #include <crepe/api/Sprite.h> -#include <crepe/api/Texture.h> #include <crepe/api/Transform.h> #include <crepe/manager/ComponentManager.h> #include <crepe/system/ParticleSystem.h> diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp index 1b2de7a..eb5033b 100644 --- a/src/test/RenderSystemTest.cpp +++ b/src/test/RenderSystemTest.cpp @@ -14,7 +14,6 @@ #include <crepe/api/Color.h> #include <crepe/api/GameObject.h> #include <crepe/api/Sprite.h> -#include <crepe/api/Texture.h> #include <crepe/manager/ComponentManager.h> #include <crepe/system/RenderSystem.h> |