comparison engine/core/video/animation.cpp @ 150:6e7d228def30

Lazy loading for animations. Uses a Resource-Pointer class that behaves like a pointer to an IResource, but only loads the resource on demand. There's a slight change of API, which is already adapted to in the XML loaders. If you use Animation.addFrame directly, either adapt to the change or wait a few hours for a backwards compatibility solution.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 11 Oct 2008 12:03:59 +0000
parents 90005975cdbb
children 54bfd1015b35
comparison
equal deleted inserted replaced
149:823544621b5b 150:6e7d228def30
44 m_animation_endtime(-1), 44 m_animation_endtime(-1),
45 m_direction(0) { 45 m_direction(0) {
46 } 46 }
47 47
48 Animation::~Animation() { 48 Animation::~Animation() {
49 std::vector<FrameInfo>::const_iterator i(m_frames.begin()); 49 // std::vector<FrameInfo>::const_iterator i(m_frames.begin());
50 while (i != m_frames.end()) { 50 // while (i != m_frames.end()) {
51 i->img->decRef(); 51 // i->img->decRef();
52 i++; 52 // i++;
53 } 53 // }
54 } 54 }
55 55
56 void Animation::addFrame(Image* image, unsigned int duration) { 56 // void Animation::addFrame(Image* image, unsigned int duration) {
57 image->addRef(); 57 // addFrame(ResourcePtr(image),duration);
58 // }
58 59
60 void Animation::addFrame(ResourcePtr image, unsigned int duration) {
59 FrameInfo info; 61 FrameInfo info;
60 info.index = m_frames.size(); 62 info.index = m_frames.size();
61 info.duration = duration; 63 info.duration = duration;
62 info.img = image; 64 info.image = image;
63 m_frames.push_back(info); 65 m_frames.push_back(info);
64 66
65 std::map<unsigned int, FrameInfo>::const_iterator i(m_framemap.end()); 67 std::map<unsigned int, FrameInfo>::const_iterator i(m_framemap.end());
66 if (i == m_framemap.begin()) { 68 if (i == m_framemap.begin()) {
67 m_framemap[0] = info; 69 m_framemap[0] = info;
93 return true; 95 return true;
94 } 96 }
95 97
96 Image* Animation::getFrame(int index) { 98 Image* Animation::getFrame(int index) {
97 if (isValidIndex(index)) { 99 if (isValidIndex(index)) {
98 return m_frames[index].img; 100 return m_frames[index].image.get<Image>();
99 } else { 101 } else {
100 return NULL; 102 return NULL;
101 } 103 }
102 } 104 }
103 105