diff 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
line wrap: on
line diff
--- a/engine/core/video/animation.cpp	Sat Oct 11 06:23:45 2008 +0000
+++ b/engine/core/video/animation.cpp	Sat Oct 11 12:03:59 2008 +0000
@@ -46,20 +46,22 @@
 		}
 	
 	Animation::~Animation() {
-		std::vector<FrameInfo>::const_iterator i(m_frames.begin());
-		while (i != m_frames.end()) {
-			i->img->decRef();
-			i++;
-		}
+// 		std::vector<FrameInfo>::const_iterator i(m_frames.begin());
+// 		while (i != m_frames.end()) {
+// 			i->img->decRef();
+// 			i++;
+// 		}
 	}
 	
-	void Animation::addFrame(Image* image, unsigned int duration) {
-		image->addRef();
+// 	void Animation::addFrame(Image* image, unsigned int duration) {
+// 		addFrame(ResourcePtr(image),duration);
+// 	}
 
+	void Animation::addFrame(ResourcePtr image, unsigned int duration) {
 		FrameInfo info;
 		info.index = m_frames.size();
 		info.duration = duration;
-		info.img = image;
+		info.image = image;
 		m_frames.push_back(info);
 
 		std::map<unsigned int, FrameInfo>::const_iterator i(m_framemap.end());
@@ -95,7 +97,7 @@
 
 	Image* Animation::getFrame(int index) {
 		if (isValidIndex(index)) {
-			return m_frames[index].img;
+			return m_frames[index].image.get<Image>();
 		} else {
 			return NULL;
 		}