diff options
-rw-r--r-- | src/crepe/api/Sprite.h | 24 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 12 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.cpp | 3 | ||||
-rw-r--r-- | src/crepe/types.h | 15 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 3 | ||||
-rw-r--r-- | src/test/ParticleTest.cpp | 2 | ||||
-rw-r--r-- | src/test/RenderSystemTest.cpp | 10 |
7 files changed, 33 insertions, 36 deletions
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 9d75ab6..2d73879 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -8,18 +8,6 @@ namespace crepe { -struct Rect { - int w = 0; - int h = 0; - int x = 0; - int y = 0; -}; - -struct FlipSettings { - bool flip_x = false; - bool flip_y = false; -}; - class SDLContext; class Animator; class AnimatorSystem; @@ -33,6 +21,12 @@ class AnimatorSystem; class Sprite : public Component { public: + struct FlipSettings { + bool flip_x = false; + bool flip_y = false; + }; + +public: // TODO: Loek comment in github #27 will be looked another time // about shared_ptr Texture /** @@ -88,6 +82,12 @@ private: //! Reads the all the variables plus the sprite_rect friend class AnimatorSystem; + struct Rect { + int w = 0; + int h = 0; + int x = 0; + int y = 0; + }; //! Render area of the sprite this will also be adjusted by the AnimatorSystem if an Animator // object is present in GameObject. this is in sprite pixels Rect sprite_rect; diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 7907a0f..25f2818 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -16,6 +16,16 @@ namespace crepe { +struct RenderCtx{ + const Sprite & sprite; + const Camera & cam; + const vec2 & cam_pos; + const vec2 & pos; + const double & angle; + const double & scale; + +}; + // TODO: SDL_Keycode is defined in a header not distributed with crepe, which means this // typedef is unusable when crepe is packaged. Wouter will fix this later. typedef SDL_Keycode CREPE_KEYCODES; @@ -29,6 +39,8 @@ typedef SDL_Keycode CREPE_KEYCODES; */ class SDLContext { + + public: /** * \brief Gets the singleton instance of SDLContext. diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index bfee658..0bef69b 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -9,9 +9,8 @@ #include "../api/ParticleEmitter.h" #include "../api/Sprite.h" #include "../api/Transform.h" +#include "../api/Camera.h" #include "../facade/SDLContext.h" -#include "api/Camera.h" -#include "types.h" #include "RenderSystem.h" diff --git a/src/crepe/types.h b/src/crepe/types.h index aa03f53..69cc526 100644 --- a/src/crepe/types.h +++ b/src/crepe/types.h @@ -27,17 +27,4 @@ typedef Vector2<float> vec2; //! Default Vector2<double> type typedef Vector2<double> dvec2; -class Sprite; -class Camera; - -struct RenderCtx{ - const Sprite & sprite; - const Camera & cam; - const vec2 & cam_pos; - const vec2 & pos; - const double & angle; - const double & scale; - -} ; - -} // namespace crepe +}; // namespace crepe diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 6e426cf..68dadd7 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -17,7 +17,6 @@ #include <crepe/types.h> #include <chrono> -#include <memory> using namespace crepe; using namespace std; @@ -33,7 +32,7 @@ int main(int argc, char * argv[]) { auto img = Texture("asset/texture/test_ap43.png"); Sprite & test_sprite - = game_object.add_component<Sprite>(img, color, FlipSettings{true, true}, 1, 1, 500); + = game_object.add_component<Sprite>(img, color, Sprite::FlipSettings{true, true}, 1, 1, 500); //game_object.add_component<Animator>(test_sprite, 4, 1, 0).active = true; game_object.add_component<Animator>(test_sprite, 1, 1, 0).active = true; diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index ea3652a..1ac058f 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -31,7 +31,7 @@ public: auto s1 = Texture("asset/texture/img.png"); Sprite & test_sprite = game_object.add_component<Sprite>( s1, color, - FlipSettings{true, true}, 1,1,100); + Sprite::FlipSettings{true, true}, 1,1,100); game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{ .position = {0, 0}, diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp index 2c4f21c..138aa36 100644 --- a/src/test/RenderSystemTest.cpp +++ b/src/test/RenderSystemTest.cpp @@ -35,24 +35,24 @@ public: auto s3 = Texture("asset/texture/img.png"); auto s4 = Texture("asset/texture/img.png"); auto & sprite1 = entity1.add_component<Sprite>(s1, Color(0, 0, 0, 0), - FlipSettings{false, false}, 5, 5, 100); + Sprite::FlipSettings{false, false}, 5, 5, 100); ASSERT_NE(sprite1.sprite_image.texture.get(), nullptr); EXPECT_EQ(sprite1.order_in_layer, 5); EXPECT_EQ(sprite1.sorting_in_layer, 5); auto & sprite2 = entity2.add_component<Sprite>(s2, Color(0, 0, 0, 0), - FlipSettings{false, false}, 2, 1, 100); + Sprite::FlipSettings{false, false}, 2, 1, 100); ASSERT_NE(sprite2.sprite_image.texture.get(), nullptr); EXPECT_EQ(sprite2.sorting_in_layer, 2); EXPECT_EQ(sprite2.order_in_layer, 1); auto & sprite3 = entity3.add_component<Sprite>(s3, Color(0, 0, 0, 0), - FlipSettings{false, false}, 1, 2, 100); + Sprite::FlipSettings{false, false}, 1, 2, 100); ASSERT_NE(sprite3.sprite_image.texture.get(), nullptr); EXPECT_EQ(sprite3.sorting_in_layer, 1); EXPECT_EQ(sprite3.order_in_layer, 2); auto & sprite4 = entity4.add_component<Sprite>(s4, Color(0, 0, 0, 0), - FlipSettings{false, false}, 1, 1, 100); + Sprite::FlipSettings{false, false}, 1, 1, 100); ASSERT_NE(sprite4.sprite_image.texture.get(), nullptr); EXPECT_EQ(sprite4.sorting_in_layer, 1); EXPECT_EQ(sprite4.order_in_layer, 1); @@ -66,7 +66,7 @@ TEST_F(RenderSystemTest, expected_throws) { EXPECT_ANY_THROW({ auto test = Texture(""); entity1.add_component<Sprite>(test, Color(0, 0, 0, 0), - FlipSettings{false, false},1,1,100); + Sprite::FlipSettings{false, false},1,1,100); }); // No camera |