diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-08 19:49:41 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-08 19:49:41 +0100 |
commit | 519cc5d16e65ff501d330c03eeb35d2d095ead29 (patch) | |
tree | 3c7c3a64c922ec248f4136d1282530a6ec6647ac /src/crepe/facade | |
parent | 63bcd54e0e0ea64cfef5950568b4253d5dae5c1e (diff) |
made sdlcontext not a singleton anymore
Diffstat (limited to 'src/crepe/facade')
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 12 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 2 | ||||
-rw-r--r-- | src/crepe/facade/Sound.cpp | 2 | ||||
-rw-r--r-- | src/crepe/facade/Sound.h | 3 |
4 files changed, 9 insertions, 10 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 85257d6..82c8c50 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -30,7 +30,7 @@ using namespace crepe; using namespace std; -SDLContext::SDLContext(Mediator & mediator) : Manager(mediator){ +SDLContext::SDLContext(Mediator & mediator) : Manager(mediator) { dbg_trace(); mediator.sdl_context = *this; if (SDL_Init(SDL_INIT_VIDEO) != 0) { @@ -232,7 +232,7 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { const Sprite::Data & data = ctx.sprite.data; - vec2 size; + vec2 size = {data.size.x , data.size.y}; if (data.size.x == 0 && data.size.y != 0) { size.x = data.size.y * ctx.sprite.aspect_ratio; } @@ -258,9 +258,6 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { } void SDLContext::draw(const RenderContext & ctx) { - - if (!ctx.texture.loaded) ctx.texture.load(this->texture_from_path(ctx.sprite.source.get_path())); - const Sprite::Data & data = ctx.sprite.data; SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * data.flip.flip_x) @@ -274,11 +271,12 @@ void SDLContext::draw(const RenderContext & ctx) { .img_scale = ctx.scale, }); + cout << dstrect.w << " " << dstrect.h << " " << dstrect.x << " " << dstrect.y << endl; double angle = ctx.angle + data.angle_offset; this->set_color_texture(ctx.texture, ctx.sprite.data.color); - SDL_RenderCopyExF(this->game_renderer.get(), ctx.texture.texture.get(), &srcrect, - &dstrect, angle, NULL, render_flip); + int error = SDL_RenderCopyExF(this->game_renderer.get(), ctx.texture.texture.get(), + &srcrect, &dstrect, angle, NULL, render_flip); } SDLContext::CameraValues SDLContext::set_camera(const Camera & cam) { diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index d95ebec..9676940 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -64,7 +64,7 @@ public: //! rendering data needed to render on screen struct RenderContext { const Sprite & sprite; - Texture & texture; + const Texture & texture; const CameraValues & cam; const vec2 & pos; const double & angle; diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp index ad50637..97e455e 100644 --- a/src/crepe/facade/Sound.cpp +++ b/src/crepe/facade/Sound.cpp @@ -6,7 +6,7 @@ using namespace crepe; using namespace std; -Sound::Sound(const Asset & src) : Resource(src) { +Sound::Sound(const Asset & src, Mediator & mediator) : Resource(src, mediator) { this->sample.load(src.get_path().c_str()); dbg_trace(); } diff --git a/src/crepe/facade/Sound.h b/src/crepe/facade/Sound.h index 85d141b..4a5d692 100644 --- a/src/crepe/facade/Sound.h +++ b/src/crepe/facade/Sound.h @@ -8,6 +8,7 @@ namespace crepe { class SoundContext; +class Mediator; /** * \brief Sound resource facade @@ -17,7 +18,7 @@ class SoundContext; */ class Sound : public Resource { public: - Sound(const Asset & src); + Sound(const Asset & src, Mediator & mediator); ~Sound(); // dbg_trace private: |