From 1ef80ecfdc1a70a6ebdd43fed82d0f9d305d63dc Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 13:07:31 +0100 Subject: implement animator replay --- src/crepe/api/Animator.cpp | 17 ++++++++++++++++- src/crepe/api/Animator.h | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index c558d86..f9a283e 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,4 +1,3 @@ - #include "util/dbg.h" #include "Animator.h" @@ -6,6 +5,7 @@ #include "Sprite.h" using namespace crepe; +using namespace std; Animator::Animator( game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, @@ -57,3 +57,18 @@ void Animator::next_anim() { ctx.row = ++ctx.row % this->grid_size.x; this->spritesheet.mask.x = ctx.row * this->spritesheet.mask.w; } + +unique_ptr Animator::save() const { + return unique_ptr(new Animator(*this)); +} + +void Animator::restore(const Component & snapshot) { + *this = static_cast(snapshot); +} + +Animator & Animator::operator=(const Animator & snapshot) { + this->data = snapshot.data; + this->elapsed_time = snapshot.elapsed_time; + this->frame = snapshot.frame; + return *this; +} diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 95539d3..d1f49c4 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -108,6 +108,12 @@ private: //! Uses the spritesheet friend AnimatorSystem; + +protected: + virtual std::unique_ptr save() const; + Animator(const Animator &) = default; + virtual void restore(const Component & snapshot); + virtual Animator & operator=(const Animator &); }; } // namespace crepe -- cgit v1.2.3 From 4d5a1570908d47b8f2d3bfa65634f2fb2dcf7e3c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 13:10:03 +0100 Subject: Revert "implement animator replay" This reverts commit 1ef80ecfdc1a70a6ebdd43fed82d0f9d305d63dc. --- src/crepe/api/Animator.cpp | 17 +---------------- src/crepe/api/Animator.h | 6 ------ 2 files changed, 1 insertion(+), 22 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index f9a283e..c558d86 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,3 +1,4 @@ + #include "util/dbg.h" #include "Animator.h" @@ -5,7 +6,6 @@ #include "Sprite.h" using namespace crepe; -using namespace std; Animator::Animator( game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, @@ -57,18 +57,3 @@ void Animator::next_anim() { ctx.row = ++ctx.row % this->grid_size.x; this->spritesheet.mask.x = ctx.row * this->spritesheet.mask.w; } - -unique_ptr Animator::save() const { - return unique_ptr(new Animator(*this)); -} - -void Animator::restore(const Component & snapshot) { - *this = static_cast(snapshot); -} - -Animator & Animator::operator=(const Animator & snapshot) { - this->data = snapshot.data; - this->elapsed_time = snapshot.elapsed_time; - this->frame = snapshot.frame; - return *this; -} diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index d1f49c4..95539d3 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -108,12 +108,6 @@ private: //! Uses the spritesheet friend AnimatorSystem; - -protected: - virtual std::unique_ptr save() const; - Animator(const Animator &) = default; - virtual void restore(const Component & snapshot); - virtual Animator & operator=(const Animator &); }; } // namespace crepe -- cgit v1.2.3 From 8ea70b897805ff84113758d45a4c5c1a171a77bd Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 13:14:37 +0100 Subject: implement sprite replay --- src/crepe/api/Sprite.cpp | 15 +++++++++++++++ src/crepe/api/Sprite.h | 10 ++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 0107c7b..2919857 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -19,3 +19,18 @@ Sprite::Sprite(game_object_id_t id, const Asset & texture, const Sprite::Data & } Sprite::~Sprite() { dbg_trace(); } + +unique_ptr Sprite::save() const { + return unique_ptr(new Sprite(*this)); +} + +void Sprite::restore(const Component & snapshot) { + *this = static_cast(snapshot); +} + +Sprite & Sprite::operator=(const Sprite & snapshot) { + this->active = snapshot.active; + this->data = snapshot.data; + this->mask = snapshot.mask; + return *this; +} diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index a3fc319..3565bed 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -42,10 +42,10 @@ public: FlipSettings flip; //! Layer sorting level of the sprite - const int sorting_in_layer = 0; + int sorting_in_layer = 0; //! Order within the sorting layer - const int order_in_layer = 0; + int order_in_layer = 0; /** * \brief width and height of the sprite in game units @@ -119,6 +119,12 @@ private: //! 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 mask; + +protected: + virtual std::unique_ptr save() const; + Sprite(const Sprite &) = default; + virtual void restore(const Component & snapshot); + virtual Sprite & operator=(const Sprite &); }; } // namespace crepe -- cgit v1.2.3 From b92b3b830dc53ecc2accf8472a8e4ce8be2e19dc Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 14:49:09 +0100 Subject: `make format` --- game/Random.cpp | 1 - game/Random.h | 2 -- src/crepe/api/Sprite.cpp | 4 +--- 3 files changed, 1 insertion(+), 6 deletions(-) (limited to 'src/crepe/api') diff --git a/game/Random.cpp b/game/Random.cpp index 59be3c5..ace6245 100644 --- a/game/Random.cpp +++ b/game/Random.cpp @@ -25,4 +25,3 @@ unsigned Random::u(unsigned upper, unsigned lower) { unsigned x = rand() % range; return x + lower; } - diff --git a/game/Random.h b/game/Random.h index cf05e87..8af9669 100644 --- a/game/Random.h +++ b/game/Random.h @@ -6,6 +6,4 @@ public: static double d(double upper = 1.0, double lower = 0.0); static int i(int upper, int lower = 0); static unsigned u(unsigned upper, unsigned lower = 0); - }; - diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 2919857..3c77e2e 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -20,9 +20,7 @@ Sprite::Sprite(game_object_id_t id, const Asset & texture, const Sprite::Data & Sprite::~Sprite() { dbg_trace(); } -unique_ptr Sprite::save() const { - return unique_ptr(new Sprite(*this)); -} +unique_ptr Sprite::save() const { return unique_ptr(new Sprite(*this)); } void Sprite::restore(const Component & snapshot) { *this = static_cast(snapshot); -- cgit v1.2.3