aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/teenagent/font.cpp6
-rw-r--r--engines/teenagent/inventory.cpp6
-rw-r--r--engines/teenagent/music.cpp6
-rw-r--r--engines/teenagent/scene.cpp36
-rw-r--r--engines/teenagent/teenagent.cpp31
5 files changed, 35 insertions, 50 deletions
diff --git a/engines/teenagent/font.cpp b/engines/teenagent/font.cpp
index bd7f40fcbb..7d252f59e8 100644
--- a/engines/teenagent/font.cpp
+++ b/engines/teenagent/font.cpp
@@ -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 @@ void Font::load(const Pack &pack, int id) {
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) {
diff --git a/engines/teenagent/inventory.cpp b/engines/teenagent/inventory.cpp
index ebefa9dd8c..3e04dcdd7e 100644
--- a/engines/teenagent/inventory.cpp
+++ b/engines/teenagent/inventory.cpp
@@ -40,11 +40,11 @@ void Inventory::init(TeenAgentEngine *engine) {
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);
diff --git a/engines/teenagent/music.cpp b/engines/teenagent/music.cpp
index daab75c145..395b2546b9 100644
--- a/engines/teenagent/music.cpp
+++ b/engines/teenagent/music.cpp
@@ -25,6 +25,7 @@
#include "teenagent/music.h"
#include "teenagent/resources.h"
+#include "common/ptr.h"
namespace TeenAgent {
@@ -43,8 +44,8 @@ MusicPlayer::~MusicPlayer() {
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 @@ bool MusicPlayer::load(int id) {
debug(0, "unhandled music command %02x", cmd);
}
}
- delete stream;
_currRow = 0;
_id = id;
return true;
diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp
index 32cedfcc07..b406bcc00a 100644
--- a/engines/teenagent/scene.cpp
+++ b/engines/teenagent/scene.cpp
@@ -210,24 +210,22 @@ void Scene::init(TeenAgentEngine *engine, OSystem *system) {
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 @@ void Scene::loadOns() {
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 @@ void Scene::loadLans() {
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 @@ void Scene::init(int id, const Common::Point &pos) {
}
}
- 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 @@ void Scene::init(int id, const Common::Point &pos) {
}
}
on.load(stream, SurfaceList::kTypeOn, sub_hack);
- delete stream;
loadOns();
loadLans();
@@ -433,27 +425,25 @@ void Scene::init(int id, const Common::Point &pos) {
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) {
diff --git a/engines/teenagent/teenagent.cpp b/engines/teenagent/teenagent.cpp
index 7d98a47f28..f2c765d4d9 100644
--- a/engines/teenagent/teenagent.cpp
+++ b/engines/teenagent/teenagent.cpp
@@ -190,11 +190,12 @@ void TeenAgentEngine::deinit() {
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 @@ Common::Error TeenAgentEngine::loadGameState(int slot) {
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::loadGameState(int slot) {
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 @@ Common::Error TeenAgentEngine::saveGameState(int slot, const char *desc) {
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 @@ bool TeenAgentEngine::showLogo() {
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 @@ bool TeenAgentEngine::showLogo() {
}
_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 @@ bool TeenAgentEngine::showMetropolis() {
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);