aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/agi/agi.cpp4
-rw-r--r--engines/agi/agi.h7
-rw-r--r--engines/agi/objects.cpp32
3 files changed, 9 insertions, 34 deletions
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index 55872940f5..3f98a1d4be 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -214,7 +214,7 @@ int AgiEngine::agiDeinit() {
agiUnloadResources(); // unload resources in memory
_loader->unloadResource(RESOURCETYPE_LOGIC, 0);
ec = _loader->deinit();
- unloadObjects();
+ _objects.clear();
_words->unloadDictionary();
clearImageStack();
@@ -386,8 +386,6 @@ AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBas
memset(&_stringdata, 0, sizeof(struct StringData));
- _objects = NULL;
-
_restartGame = false;
_firstSlot = 0;
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 2294593427..02a406e6e9 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -31,6 +31,7 @@
#include "common/rect.h"
#include "common/rendermode.h"
#include "common/stack.h"
+#include "common/str.h"
#include "common/system.h"
#include "engines/engine.h"
@@ -354,7 +355,7 @@ struct AgiControllerKeyMapping {
struct AgiObject {
int location;
- char *name;
+ Common::String name;
};
struct AgiDir {
@@ -763,7 +764,7 @@ private:
int _firstSlot;
public:
- AgiObject *_objects; // objects in the game
+ Common::Array<AgiObject> _objects; // objects in the game
StringData _stringdata;
@@ -852,14 +853,12 @@ public:
int showObjects();
int loadObjects(const char *fname);
int loadObjects(Common::File &fp);
- void unloadObjects();
const char *objectName(uint16 objectNr);
int objectGetLocation(uint16 objectNr);
void objectSetLocation(uint16 objectNr, int);
private:
int decodeObjects(uint8 *mem, uint32 flen);
int readObjects(Common::File &fp, int flen);
- int allocObjects(int);
// Logic
public:
diff --git a/engines/agi/objects.cpp b/engines/agi/objects.cpp
index b6c628c32d..3a7bfc98f6 100644
--- a/engines/agi/objects.cpp
+++ b/engines/agi/objects.cpp
@@ -26,20 +26,12 @@
namespace Agi {
-int AgiEngine::allocObjects(int n) {
- if ((_objects = (AgiObject *)calloc(n, sizeof(struct AgiObject))) == NULL)
- return errNotEnoughMemory;
-
- return errOK;
-}
-
int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) {
unsigned int i, so, padsize, spos;
padsize = _game.gameFlags & ID_AMIGA ? 4 : 3;
_game.numObjects = 0;
- _objects = NULL;
// check if first pointer exceeds file size
// if so, its encrypted, else it is not
@@ -60,8 +52,7 @@ int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) {
_game.numObjects = READ_LE_UINT16(mem) / padsize;
debugC(5, kDebugLevelResources, "num_objects = %d (padsize = %d)", _game.numObjects, padsize);
- if (allocObjects(_game.numObjects) != errOK)
- return errNotEnoughMemory;
+ _objects.resize(_game.numObjects);
// build the object list
spos = getVersion() >= 0x2000 ? padsize : 0;
@@ -72,15 +63,15 @@ int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) {
offset = READ_LE_UINT16(mem + so) + spos;
if ((uint) offset < flen) {
- _objects[i].name = (char *)strdup((const char *)mem + offset);
+ _objects[i].name = (const char *)mem + offset;
} else {
warning("object %i name beyond object filesize (%04x > %04x)", i, offset, flen);
- _objects[i].name = strdup("");
+ _objects[i].name.clear();
}
// Don't show the invalid "?" object in ego's inventory in the fanmade
// game Beyond the Titanic 2 (bug #3116541).
- if (!strcmp(_objects[i].name, "?") && _objects[i].location == EGO_OWNED)
+ if (_objects[i].name == "?" && _objects[i].location == EGO_OWNED)
_objects[i].location = 0;
}
debug(0, "Reading objects: %d objects read.", _game.numObjects);
@@ -131,19 +122,6 @@ int AgiEngine::readObjects(Common::File &fp, int flen) {
return errOK;
}
-void AgiEngine::unloadObjects() {
- unsigned int i;
-
- if (_objects != NULL) {
- for (i = 0; i < _game.numObjects; i++) {
- free(_objects[i].name);
- _objects[i].name = NULL;
- }
- free(_objects);
- _objects = NULL;
- }
-}
-
void AgiEngine::objectSetLocation(uint16 objectNr, int i) {
if (objectNr >= _game.numObjects) {
warning("AgiEngine::objectSetLocation: Can't access object %d.\n", objectNr);
@@ -165,7 +143,7 @@ const char *AgiEngine::objectName(uint16 objectNr) {
warning("AgiEngine::objectName: Can't access object %d.\n", objectNr);
return "";
}
- return _objects[objectNr].name;
+ return _objects[objectNr].name.c_str();
}
} // End of namespace Agi