26 #include <boost/lexical_cast.hpp>
32 #include "util/base/exception.h"
33 #include "util/time/timemanager.h"
35 #include "animation.h"
37 #include "util/structures/rect.h"
43 m_animation_endtime(-1),
54 info.index = m_frames.size();
55 info.duration = duration;
57 m_frames.push_back(info);
59 std::map<unsigned int, FrameInfo>::const_iterator i(m_framemap.end());
60 if (i == m_framemap.begin()) {
62 m_animation_endtime = duration;
65 unsigned int frametime = i->first + i->second.duration;
66 m_framemap[frametime] = info;
67 m_animation_endtime = frametime + duration;
74 if ((static_cast<int>(timestamp) <= m_animation_endtime) && (m_animation_endtime > 0)) {
75 std::map<unsigned int, FrameInfo>::const_iterator i(m_framemap.upper_bound(timestamp));
77 val = i->second.index;
82 bool Animation::isValidIndex(
int index)
const{
83 int size = m_frames.size();
84 return size > 0 && index >= 0 && index < size;
88 if (isValidIndex(index)) {
89 return m_frames[index].image.get<
Image>();
100 if (isValidIndex(index)) {
101 return m_frames[index].duration;
108 return m_frames.size();