[Scummvm-cvs-logs] SF.net SVN: scummvm:[48340] scummvm/trunk/engines/teenagent

megath at users.sourceforge.net megath at users.sourceforge.net
Sat Mar 20 21:37:36 CET 2010


Revision: 48340
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48340&view=rev
Author:   megath
Date:     2010-03-20 20:37:36 +0000 (Sat, 20 Mar 2010)

Log Message:
-----------
ported all code to ScopedPtr

Modified Paths:
--------------
    scummvm/trunk/engines/teenagent/font.cpp
    scummvm/trunk/engines/teenagent/inventory.cpp
    scummvm/trunk/engines/teenagent/music.cpp
    scummvm/trunk/engines/teenagent/scene.cpp
    scummvm/trunk/engines/teenagent/teenagent.cpp

Modified: scummvm/trunk/engines/teenagent/font.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/font.cpp	2010-03-20 20:32:01 UTC (rev 48339)
+++ scummvm/trunk/engines/teenagent/font.cpp	2010-03-20 20:37:36 UTC (rev 48340)
@@ -25,6 +25,7 @@
 #include "teenagent/font.h"
 #include "teenagent/pack.h"
 #include "common/stream.h"
+#include "common/ptr.h"
 
 namespace TeenAgent {
 
@@ -35,14 +36,13 @@
 	delete[] data;
 	data = NULL;
 
-	Common::SeekableReadStream *s = pack.getStream(id);
-	if (s == NULL)
+	Common::ScopedPtr<Common::SeekableReadStream> s(pack.getStream(id));
+	if (!s)
 		error("loading font %d failed", id);
 
 	data = new byte[s->size()];
 	s->read(data, s->size());
 	debug(0, "font size: %d", s->size());
-	delete s;
 }
 
 uint Font::render(Graphics::Surface *surface, int x, int y, char c, byte color) {

Modified: scummvm/trunk/engines/teenagent/inventory.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/inventory.cpp	2010-03-20 20:32:01 UTC (rev 48339)
+++ scummvm/trunk/engines/teenagent/inventory.cpp	2010-03-20 20:37:36 UTC (rev 48340)
@@ -40,11 +40,11 @@
 	varia.open("varia.res");
 
 	{
-		Common::SeekableReadStream *s = varia.getStream(3);
-		assert(s != NULL);
+		Common::ScopedPtr<Common::SeekableReadStream> s(varia.getStream(3));
+		if (!s)
+			error("no inventory background");
 		debug(0, "loading inventory background...");
 		background.load(s, Surface::kTypeOns);
-		delete s;
 	}
 
 	uint32 items_size = varia.getSize(4);

Modified: scummvm/trunk/engines/teenagent/music.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/music.cpp	2010-03-20 20:32:01 UTC (rev 48339)
+++ scummvm/trunk/engines/teenagent/music.cpp	2010-03-20 20:37:36 UTC (rev 48340)
@@ -25,6 +25,7 @@
 
 #include "teenagent/music.h"
 #include "teenagent/resources.h"
+#include "common/ptr.h"
 
 namespace TeenAgent {
 
@@ -43,8 +44,8 @@
 bool MusicPlayer::load(int id) {
 	Resources *res = Resources::instance();
 
-	Common::SeekableReadStream *stream = res->mmm.getStream(id);
-	if (stream == NULL)
+	Common::ScopedPtr<Common::SeekableReadStream> stream(res->mmm.getStream(id));
+	if (!stream)
 		return false;
 
 	char header[4];
@@ -99,7 +100,6 @@
 			debug(0, "unhandled music command %02x", cmd);
 		}
 	}
-	delete stream;
 	_currRow = 0;
 	_id = id;
 	return true;

Modified: scummvm/trunk/engines/teenagent/scene.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/scene.cpp	2010-03-20 20:32:01 UTC (rev 48339)
+++ scummvm/trunk/engines/teenagent/scene.cpp	2010-03-20 20:37:36 UTC (rev 48340)
@@ -210,24 +210,22 @@
 	FilePack varia;
 	varia.open("varia.res");
 
-	Common::SeekableReadStream *s = varia.getStream(1);
-	if (s == NULL)
+	Common::ScopedPtr<Common::SeekableReadStream> s(varia.getStream(1));
+	if (!s)
 		error("invalid resource data");
 
 	teenagent.load(s, Animation::kTypeVaria);
 	if (teenagent.empty())
 		error("invalid mark animation");
 
-	delete s;
-	s = varia.getStream(2);
-	if (s == NULL)
+	s.reset(varia.getStream(2));
+	if (!s)
 		error("invalid resource data");
 
 	teenagent_idle.load(s, Animation::kTypeVaria);
 	if (teenagent_idle.empty())
 		error("invalid mark animation");
 
-	delete s;
 	varia.close();
 	loadObjectData();
 }
@@ -336,10 +334,9 @@
 	if (ons_count > 0) {
 		ons = new Surface[ons_count];
 		for (uint32 i = 0; i < ons_count; ++i) {
-			Common::SeekableReadStream *s = res->ons.getStream(on_id[i]);
-			if (s != NULL) {
+			Common::ScopedPtr<Common::SeekableReadStream> s(res->ons.getStream(on_id[i]));
+			if (s) {
 				ons[i].load(s, Surface::kTypeOns);
-				delete s;
 			}
 		}
 	}
@@ -360,17 +357,13 @@
 		if (bxv == 0)
 			continue;
 
-		Common::SeekableReadStream *s = res->loadLan000(res_id);
-		if (s != NULL) {
+		Common::ScopedPtr<Common::SeekableReadStream> s(res->loadLan000(res_id));
+		if (s) {
 			animation[i].load(s, Animation::kTypeLan);
 			if (bxv != 0 && bxv != 0xff)
 				animation[i].id = bxv;
-			delete s;
 		}
-
-		//uint16 bp = res->dseg.get_word();
 	}
-
 }
 
 void Scene::init(int id, const Common::Point &pos) {
@@ -401,7 +394,7 @@
 		}
 	}
 
-	Common::SeekableReadStream *stream = res->on.getStream(id);
+	Common::ScopedPtr<Common::SeekableReadStream> stream(res->on.getStream(id));
 	int sub_hack = 0;
 	if (id == 7) { //something patched in the captains room
 		switch(res->dseg.get_byte(0xdbe6)) {
@@ -415,7 +408,6 @@
 		}
 	}
 	on.load(stream, SurfaceList::kTypeOn, sub_hack);
-	delete stream;
 
 	loadOns();
 	loadLans();
@@ -433,27 +425,25 @@
 void Scene::playAnimation(byte idx, uint id, bool loop, bool paused, bool ignore) {
 	debug(0, "playAnimation(%u, %u, loop:%s, paused:%s, ignore:%s)", idx, id, loop?"true":"false", paused?"true":"false", ignore?"true":"false");
 	assert(idx < 4);
-	Common::SeekableReadStream *s = Resources::instance()->loadLan(id + 1);
-	if (s == NULL)
+	Common::ScopedPtr<Common::SeekableReadStream> s(Resources::instance()->loadLan(id + 1));
+	if (!s)
 		error("playing animation %u failed", id);
 
 	custom_animation[idx].load(s);
 	custom_animation[idx].loop = loop;
 	custom_animation[idx].paused = paused;
 	custom_animation[idx].ignore = ignore;
-	delete s;
 }
 
 void Scene::playActorAnimation(uint id, bool loop, bool ignore) {
 	debug(0, "playActorAnimation(%u, loop:%s, ignore:%s)", id, loop?"true":"false", ignore?"true":"false");
-	Common::SeekableReadStream *s = Resources::instance()->loadLan(id + 1);
-	if (s == NULL)
+	Common::ScopedPtr<Common::SeekableReadStream> s(Resources::instance()->loadLan(id + 1));
+	if (!s)
 		error("playing animation %u failed", id);
 
 	actor_animation.load(s);
 	actor_animation.loop = loop;
 	actor_animation.ignore = ignore;
-	delete s;
 }
 
 Animation * Scene::getAnimation(byte slot) {

Modified: scummvm/trunk/engines/teenagent/teenagent.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/teenagent.cpp	2010-03-20 20:32:01 UTC (rev 48339)
+++ scummvm/trunk/engines/teenagent/teenagent.cpp	2010-03-20 20:37:36 UTC (rev 48340)
@@ -190,11 +190,12 @@
 
 Common::Error TeenAgentEngine::loadGameState(int slot) {
 	debug(0, "loading from slot %d", slot);
-	Common::InSaveFile *in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%02d", slot));
-	if (in == NULL)
-		in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%d", slot));
+	Common::ScopedPtr<Common::InSaveFile> 
+		in(_saveFileMan->openForLoading(Common::String::printf("teenagent.%02d", slot)));
+	if (!in)
+		in.reset(_saveFileMan->openForLoading(Common::String::printf("teenagent.%d", slot)));
 
-	if (in == NULL)
+	if (!in)
 		return Common::kReadPermissionDenied;
 
 	Resources *res = Resources::instance();
@@ -203,12 +204,9 @@
 	char data[0x777a];
 	in->seek(0);
 	if (in->read(data, 0x777a) != 0x777a) {
-		delete in;
 		return Common::kReadingFailed;
 	}
 
-	delete in;
-
 	memcpy(res->dseg.ptr(0x6478), data, sizeof(data));
 
 	scene->clear();
@@ -228,8 +226,8 @@
 
 Common::Error TeenAgentEngine::saveGameState(int slot, const char *desc) {
 	debug(0, "saving to slot %d", slot);
-	Common::OutSaveFile *out = _saveFileMan->openForSaving(Common::String::printf("teenagent.%02d", slot));
-	if (out == NULL)
+	Common::ScopedPtr<Common::OutSaveFile> out(_saveFileMan->openForSaving(Common::String::printf("teenagent.%02d", slot)));
+	if (!out)
 		return Common::kWritingFailed;
 
 	Resources *res = Resources::instance();
@@ -243,9 +241,8 @@
 	out->write(res->dseg.ptr(0x6478), 0x777a);
 	if (!Graphics::saveThumbnail(*out))
 		warning("saveThumbnail failed");
-	out->finalize();
-	delete out;
 
+	out->finalize();
 	return Common::kNoError;
 }
 
@@ -279,8 +276,8 @@
 	byte bg[0xfa00];
 	byte palette[0x400];
 
-	Common::SeekableReadStream *frame = logo.getStream(1);
-	if (frame == NULL)
+	Common::ScopedPtr<Common::SeekableReadStream> frame(logo.getStream(1));
+	if (!frame)
 		return true;
 
 	frame->read(bg, sizeof(bg));
@@ -305,13 +302,12 @@
 			}
 			_system->copyRectToScreen(bg, 320, 0, 0, 320, 200);
 
-			frame = logo.getStream(i);
-			if (frame == NULL)
+			frame.reset(logo.getStream(i));
+			if (!frame)
 				return true;
 
 			Surface s;
 			s.load(frame, Surface::kTypeOns);
-			delete frame;
 			if (s.empty())
 				return true;
 
@@ -333,14 +329,13 @@
 	byte palette[0x400];
 	memset(palette, 0, sizeof(palette));
 	{
-		Common::SeekableReadStream *s = varia.getStream(5);
+		Common::ScopedPtr<Common::SeekableReadStream> s(varia.getStream(5));
 		for(uint c = 0; c < 0x400; c += 4) {
 			s->read(palette + c, 3);
 			palette[c] *= 4;
 			palette[c + 1] *= 4;
 			palette[c + 2] *= 4;
 		}
-		delete s;
 	}
 
 	_system->setPalette(palette, 0, 0x100);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list