 |
Gorgon Game Engine
|
Go to the documentation of this file.
6 #include "../Containers/Collection.h"
17 template<
class T_,
template<
class,
class,
class>
class A_,
class F_>
18 class basic_TextureAnimationProvider;
22 template<
class T__,
template<
class,
class,
class>
class A_,
class F_>
26 image(&image), duration(duration), start(start) { }
40 return start + duration;
44 bool IsIn(
unsigned time)
const override {
45 return time >= start && time < start + duration;
55 unsigned duration, start;
58 template<
class T_,
class P_,
class F_>
77 virtual bool Progress(
unsigned &leftover)
override;
80 return parent->GetDuration();
83 virtual GL::Texture
GetID()
const override {
84 if(current < (
unsigned)parent->GetCount())
85 return (*parent)[current].GetID();
86 else if(parent->GetCount())
87 return (*parent)[0].GetID();
95 if(current < (
unsigned)parent->GetCount())
96 return (*parent)[current].GetImageSize();
97 else if(parent->GetCount())
98 return (*parent)[0].GetImageSize();
106 if(current < (
unsigned)parent->GetCount())
107 return (*parent)[current].GetMode();
108 else if(parent->GetCount())
109 return (*parent)[0].GetMode();
117 if(current < (
unsigned)parent->GetCount())
118 return (*parent)[current].GetCoordinates();
119 else if(parent->GetCount())
120 return (*parent)[0].GetCoordinates();
136 template<
class T_,
template<
class,
class,
class>
class A_,
class F_>
139 using Iterator =
typename std::vector<basic_AnimationFrame<T_>>::iterator;
140 using ConstIterator =
typename std::vector<basic_AnimationFrame<T_>>::const_iterator;
155 auto ret =
new typename std::remove_reference<decltype(*
this)>::type(std::move(*
this));
187 return frames[0].GetImage().GetWidth();
195 return frames[0].GetImage().GetHeight();
203 return frames[0].GetImage().GetSize();
210 return (
int)
frames.size();
235 ASSERT(frame>=0 && frame<(
int)
frames.size(),
"Index out of bounds");
237 return frames[frame].GetImage();
247 if(f.GetEnd() >= time)
258 ASSERT(index>=0 && index<(
int)
frames.size(),
"Index out of bounds");
264 unsigned StartOf(
unsigned frame)
const override {
265 return frames[frame].GetStart();
275 ASSERT(frame>=0 && frame<
frames.size(),
"Index out of bounds");
277 return frames[frame].GetDuration();
298 void Add(
const F_ &frame) {
305 if(
dynamic_cast<const F_*
>(&frame) ==
nullptr)
306 throw std::runtime_error(
"Wrong frame type.");
308 Add(
dynamic_cast<const F_&
>(frame));
318 frames.insert(
frames.begin()+before, {image, duration, frames[before].GetStart()});
320 for(
unsigned i=before+1; i<
frames.size(); i++) {
337 frames.insert(
frames.begin()+before, {image, duration, frames[before].GetStart()});
339 for(
unsigned i=before+1; i<
frames.size(); i++) {
351 before += (int)
frames.size();
353 if((
unsigned)before >
frames.size()) before = (
int)
frames.size();
355 if((
unsigned)before ==
frames.size())
358 frame.start =
frames[before].start;
362 for(
unsigned i=before+1; i<
frames.size(); i++) {
371 if(
dynamic_cast<const F_*
>(&frame) ==
nullptr)
372 throw std::runtime_error(
"Wrong frame type.");
374 Insert(
dynamic_cast<const F_&
>(frame), before);
380 before += (int)
frames.size();
382 if((
unsigned)before >=
frames.size()) {
387 else if(index < (
unsigned)before) {
390 else if((
unsigned)before < index) {
402 ASSERT(frame>=0 && frame <
frames.size(),
"Index out of bounds");
445 std::vector<basic_AnimationFrame<T_>>
frames;
459 template<
class N_,
class R_ = T_>
460 typename std::enable_if<std::is_const<R_>::value,
void>::type
464 for(
auto &frame : other) {
465 Add(frame.GetImage(), frame.GetDuration());
466 Own(frame.GetImage());
475 template<
class T_,
class P_,
class F_>
477 if(!controller)
return false;
479 if(parent->GetCount()==0)
return false;
482 unsigned progress=controller->GetProgress();
485 if(controller->IsControlled()) {
486 if(progress>parent->GetDuration()) {
487 current=parent->GetCount()-1;
488 leftover=progress-parent->GetDuration();
493 current=parent->FrameIndexAt(progress);
499 current = parent->FrameIndexAt(progress % parent->GetDuration());
513 for(
int i=0; i<c; i++) {
virtual AnimationType & CreateAnimation(Gorgon::Animation::ControllerBase &controller) const override
Creates a new animation from this resource.
Definition: TextureAnimation.h:214
int GetHeight() const
Returns the size of the first image.
Definition: TextureAnimation.h:193
typename std::vector< basic_AnimationFrame< T_ > >::iterator Iterator
Definition: TextureAnimation.h:139
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
void MoveBefore(unsigned index, int before) override
Moves a frame that has the index before the given position.
Definition: TextureAnimation.h:378
Base(ControllerBase &controller)
Sets the controller for this animation to the given controller.
Definition: Animation.h:310
void Insert(T_ &&img, int before, unsigned duration=42)
Inserts the given image before the given frame.
Definition: TextureAnimation.h:328
basic_TextureAnimationProvider(const basic_TextureAnimationProvider &)=delete
basic_TextureAnimation(const ParentType &parent, Gorgon::Animation::ControllerBase &controller)
Creates a new image animation from the given parent.
Definition: TextureAnimation.h:65
void Add(const Gorgon::Animation::Frame &frame) override
Definition: TextureAnimation.h:304
void Prepare()
Definition: TextureAnimation.h:510
Definition: TextureAnimation.h:137
ColorMode
Color modes for images.
Definition: Color.h:16
virtual Geometry::Size GetImageSize() const override
Should return the size of the image stored in texture. Not the whole texture size.
Definition: TextureAnimation.h:94
basic_TextureAnimation(const ParentType &parent, bool create)
Creates a new image animation from the given parent.
Definition: TextureAnimation.h:69
Iterator end()
Returns an iterator to the end of the animation frames.
Definition: TextureAnimation.h:435
basic_TextureAnimation< T_, basic_TextureAnimationProvider< T_, A_, F_ >, F_ > AnimationType
Definition: TextureAnimation.h:141
virtual ~basic_TextureAnimationInjection()
Definition: TextureAnimation.h:13
unsigned GetDuration() const override
Returns the duration of this frame.
Definition: TextureAnimation.h:29
Controllers are required to progress animations.
Definition: Animation.h:65
virtual bool Progress(unsigned &leftover) override
This function should progress the animation.
Definition: TextureAnimation.h:476
void ReleaseAll()
Releases ownership of all images in the animation without destroying them.
Definition: TextureAnimation.h:415
Containers::Collection< T_ > destroylist
Definition: TextureAnimation.h:447
@ RGBA
32bit red, green, blue and alpha channel image. Red component is in the lowest byte order and
const F_ & FrameAt(int index) const override
Returns the frame at specific point.
Definition: TextureAnimation.h:257
~basic_TextureAnimationProvider()
Definition: TextureAnimation.h:172
int GetWidth() const
Returns the size of the first image.
Definition: TextureAnimation.h:185
bool IsIn(unsigned time) const override
Returns if the given time is within this frame.
Definition: TextureAnimation.h:44
Definition: TextureAnimation.h:21
void Insert(const Gorgon::Animation::Frame &frame, int before) override
Inserts the given image before the given frame.
Definition: TextureAnimation.h:370
virtual GL::Texture GetID() const override
Should return GL::Texture to be drawn. This could be 0 to denote no texture is to be used.
Definition: TextureAnimation.h:83
unsigned StartOf(unsigned frame) const override
Returns the starting time of the given frame.
Definition: TextureAnimation.h:264
typename std::vector< basic_AnimationFrame< T_ > >::const_iterator ConstIterator
Definition: TextureAnimation.h:140
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
unsigned GetStart() const override
Returns the starting time of this frame.
Definition: TextureAnimation.h:34
This class provides discrete and rectangular animation which is suitable for bitmap and texture anima...
Definition: Animations.h:71
void Add(T_ &&image, unsigned duration=42)
Adds the given image to the end of the animation.
Definition: TextureAnimation.h:291
P_ ParentType
Definition: TextureAnimation.h:61
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
virtual int GetCount() const =0
Returns number of frames.
virtual ColorMode GetMode() const override
Definition: TextureAnimation.h:105
T_ & GetImage() const
Returns the image for this frame.
Definition: TextureAnimation.h:49
basic_AnimationFrame(T_ &image, unsigned duration=42, unsigned start=0)
Definition: TextureAnimation.h:25
virtual ~basic_TextureAnimationInjection()
Definition: TextureAnimation.h:508
This is an interface for solid texture based image.
Definition: Drawables.h:511
unsigned CurrentFrame() const override
Returns the current frame.
Definition: TextureAnimation.h:127
basic_TextureAnimationProvider()=default
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
Collection is a container for reference typed objects.
Definition: Collection.h:21
This object contains an bitmap image.
Definition: Bitmap.h:25
Geometry::Size GetSize() const override
Returns the size of the first image.
Definition: TextureAnimation.h:201
unsigned GetEnd() const override
Returns the ending time of this frame.
Definition: TextureAnimation.h:39
virtual AnimationType & CreateAnimation(bool create=true) const override
Creates a new animation from this resource.
Definition: TextureAnimation.h:219
This class represents a 2D point.
Definition: Point.h:32
F_ FrameType
Definition: TextureAnimation.h:62
void Insert(T_ &image, int before, unsigned duration=42)
Inserts the given image before the given frame.
Definition: TextureAnimation.h:312
virtual auto MoveOutProvider() -> decltype(*this) override
Definition: TextureAnimation.h:154
void Remove(ConstIterator it)
Removes an image from the animation.
Definition: TextureAnimation.h:420
virtual void DeleteAnimation() const override
Deletes this animation object.
Definition: TextureAnimation.h:73
void Insert(const F_ &frm, int before)
Inserts the given image before the given frame.
Definition: TextureAnimation.h:347
A regular drawable animation.
Definition: Animations.h:14
static const unsigned NoFrame
This variable denotes that this animation has no frame at the moment.
Definition: Discrete.h:16
basic_TextureAnimationProvider & operator=(const basic_TextureAnimationProvider &)=delete
ConstIterator end() const
Returns an iterator to the end of the animation frames.
Definition: TextureAnimation.h:440
@ Graphics
Definition: Template.h:164
basic_TextureAnimationProvider(C_ &&other)
Definition: TextureAnimation.h:149
unsigned GetDuration() const override
Returns the duration of the animation.
Definition: TextureAnimation.h:269
basic_TextureAnimationProvider Duplicate() const
Definition: TextureAnimation.h:176
Definition: TextureAnimation.h:59
A discrete rectangular animation, this is most suitable for bitmap or texture animations.
Definition: Animations.h:24
unsigned FrameIndexAt(unsigned time) const
Returns which frame is at the given time.
Definition: TextureAnimation.h:242
Definition: TextureAnimation.h:11
virtual const Geometry::Pointf * GetCoordinates() const override
Should return the coordinates of the texture to be used.
Definition: TextureAnimation.h:116
ConstIterator begin() const
Returns an iterator to the beginning of the animation frames.
Definition: TextureAnimation.h:430
T_ & operator[](int frame) const
Returns the image at the given frame.
Definition: TextureAnimation.h:234
void Add(const F_ &frame)
Definition: TextureAnimation.h:298
F_ FrameType
Definition: TextureAnimation.h:142
ControllerBase * controller
Controller of this animation.
Definition: Animation.h:388
Iterator begin()
Returns an iterator to the beginning of the animation frames.
Definition: TextureAnimation.h:425
int GetCount() const override
Returns number of frames.
Definition: TextureAnimation.h:209
void Remove(unsigned frame) override
Removes an image from the animation.
Definition: TextureAnimation.h:401
void Own(T_ &image)
Owns the given image so that it would be destroyed with this animation.
Definition: TextureAnimation.h:396
unsigned duration
Definition: TextureAnimation.h:446
std::vector< basic_AnimationFrame< T_ > > frames
Definition: TextureAnimation.h:445
int GetDuration() const override
Returns the duration of the animation if it is a known apriori.
Definition: TextureAnimation.h:79
void Add(T_ &image, unsigned duration=42, bool own=false)
Adds the given image to the end of the animation.
Definition: TextureAnimation.h:281
T_ & ImageAt(unsigned time) const
Returns the image that is to be shown at the given time.
Definition: TextureAnimation.h:225
void Clear() override
Removes all images from the animation.
Definition: TextureAnimation.h:409
unsigned GetDuration(unsigned frame) const override
Returns the duration of the given frame.
Definition: TextureAnimation.h:274
This is the base class for a single frame in a discreet animation.
Definition: Discrete.h:20