[Scummvm-git-logs] scummvm master -> 68b08bf030c5359d5a6d33c5dd6aa8cead791069
a-yyg
76591232+a-yyg at users.noreply.github.com
Mon Jul 19 09:28:55 UTC 2021
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
46673c7924 SAGA2: Fix Sensor deletion on remove
68b08bf030 SAGA2: Fix pointer arithmetics in objects.cpp
Commit: 46673c7924bc60a6905899d235c9f4f3fd66f53b
https://github.com/scummvm/scummvm/commit/46673c7924bc60a6905899d235c9f4f3fd66f53b
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-19T18:27:42+09:00
Commit Message:
SAGA2: Fix Sensor deletion on remove
Changed paths:
engines/saga2/objects.cpp
engines/saga2/sensor.cpp
engines/saga2/sensor.h
diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index cd16212f56..b9a347bbc6 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -2024,11 +2024,11 @@ void GameObject::removeSensor(SensorID id) {
for (Common::List<Sensor *>::iterator it = sensorList->_list.begin(); it != sensorList->_list.end(); ++it) {
if ((*it)->thisID() == id) {
// Remove the sensor, then delete it
- sensorList->_list.remove(*it);
+ (*it)->_active = false;
+ sensorList->_list.erase(it);
// If the list is now empty, delete it
if (sensorList->_list.empty()) {
- deleteSensorList(sensorList);
delete sensorList;
}
@@ -2047,10 +2047,8 @@ void GameObject::removeAllSensors(void) {
// Get this object's sensor list
if ((sensorList = fetchSensorList(this)) != nullptr) {
// Iterate through the sensors
- for (Common::List<Sensor *>::iterator it = sensorList->_list.begin(); it != sensorList->_list.end(); ++it) {
- deleteSensor(*it);
+ for (Common::List<Sensor *>::iterator it = sensorList->_list.begin(); it != sensorList->_list.end(); ++it)
delete *it;
- }
deleteSensorList(sensorList);
delete sensorList;
diff --git a/engines/saga2/sensor.cpp b/engines/saga2/sensor.cpp
index 7c95fa0a1a..eaf5b4a5ce 100644
--- a/engines/saga2/sensor.cpp
+++ b/engines/saga2/sensor.cpp
@@ -139,9 +139,16 @@ void writeSensor(Sensor *sensor, Common::MemoryWriteStreamDynamic *out) {
//----------------------------------------------------------------------
void checkSensors(void) {
+ Common::Array<Sensor *> deadSensors;
+
for (Common::List<Sensor *>::iterator it = g_vm->_sensorList.begin(); it != g_vm->_sensorList.end(); ++it) {
Sensor *sensor = *it;
+ if (sensor->_active == false) {
+ deadSensors.push_back(sensor);
+ continue;
+ }
+
if (--sensor->checkCtr <= 0) {
assert(sensor->checkCtr == 0);
@@ -163,6 +170,9 @@ void checkSensors(void) {
sensor->checkCtr = sensorCheckRate;
}
}
+
+ for (uint i = 0; i < deadSensors.size(); ++i)
+ delete deadSensors[i];
}
//----------------------------------------------------------------------
@@ -247,6 +257,9 @@ void saveSensors(Common::OutSaveFile *outS) {
// Archive all sensors
for (Common::List<Sensor *>::iterator it = g_vm->_sensorList.begin(); it != g_vm->_sensorList.end(); ++it) {
+ if ((*it)->_active == false)
+ continue;
+
debugC(3, kDebugSaveload, "Saving Sensor %d", getSensorID(*it));
out->writeSint16LE((*it)->checkCtr);
debugC(3, kDebugSaveload, "... ctr = %d", (*it)->checkCtr);
@@ -329,10 +342,14 @@ SensorList::SensorList(Common::InSaveFile *in) {
obj = GameObject::objectAddress(id);
newSensorList(this);
+
+ debugC(4, kDebugSaveload, "... objID = %d", id);
}
void SensorList::write(Common::MemoryWriteStreamDynamic *out) {
out->writeUint16LE(obj->thisID());
+
+ debugC(4, kDebugSaveload, "... objID = %d", obj->thisID());
}
/* ===================================================================== *
@@ -354,6 +371,10 @@ Sensor::Sensor(Common::InSaveFile *in, int16 ctr) {
range = in->readSint16LE();
newSensor(this, ctr);
+
+ debugC(4, kDebugSaveload, "... objID = %d", objID);
+ debugC(4, kDebugSaveload, "... id = %d", id);
+ debugC(4, kDebugSaveload, "... range = %d", range);
}
//----------------------------------------------------------------------
@@ -368,6 +389,10 @@ void Sensor::write(Common::MemoryWriteStreamDynamic *out) {
// Store the range
out->writeSint16LE(range);
+
+ debugC(4, kDebugSaveload, "... objID = %d", obj->thisID());
+ debugC(4, kDebugSaveload, "... id = %d", id);
+ debugC(4, kDebugSaveload, "... range = %d", range);
}
/* ===================================================================== *
diff --git a/engines/saga2/sensor.h b/engines/saga2/sensor.h
index 78f1cba75a..236f9babc0 100644
--- a/engines/saga2/sensor.h
+++ b/engines/saga2/sensor.h
@@ -115,15 +115,15 @@ public:
public:
// Constructor -- initial construction
SensorList(GameObject *o) : obj(o) {
- debugC(1, kDebugSensors, "Adding SensorList %p to %p (%s)",
- (void *)this, (void *)o, o->objName());
newSensorList(this);
+ debugC(1, kDebugSensors, "Adding SensorList %p to %d (%s) (total %d)",
+ (void *)this, o->thisID(), o->objName(), _list.size());
}
~SensorList() {
- debugC(1, kDebugSensors, "Deleting SensorList %p of %p (%s)",
- (void *)this, (void *)obj, obj->objName());
deleteSensorList(this);
+ debugC(1, kDebugSensors, "Deleting SensorList %p of %d (%s) (total %d)",
+ (void *)this, obj->thisID(), obj->objName(), _list.size());
}
SensorList(Common::InSaveFile *in);
@@ -152,22 +152,25 @@ public:
int16 range;
int16 checkCtr;
+ bool _active;
public:
// Constructor -- initial construction
- Sensor(GameObject *o, SensorID sensorID, int16 rng) : obj(o), id(sensorID), range(rng) {
- debugC(1, kDebugSensors, "Adding Sensor %p to %p (%s)",
- (void *)this, (void *)o, o->objName());
+ Sensor(GameObject *o, SensorID sensorID, int16 rng) : obj(o), id(sensorID), range(rng), _active(true) {
newSensor(this);
+ SensorList *sl = fetchSensorList(o);
+ debugC(1, kDebugSensors, "Adding Sensor %p to %d (%s) (list = %p, total = %d)",
+ (void *)this, o->thisID(), o->objName(), (void *)sl, (sl != nullptr) ? sl->_list.size() : -1);
}
Sensor(Common::InSaveFile *in, int16 ctr);
// Virtural destructor
virtual ~Sensor(void) {
- debugC(1, kDebugSensors, "Deleting Sensor %p to %p (%s)",
- (void *)this, (void *)obj, obj->objName());
deleteSensor(this);
+ SensorList *sl = fetchSensorList(obj);
+ debugC(1, kDebugSensors, "Deleting Sensor %p of %d (%s) (list = %p, total = %d)",
+ (void *)this, obj->thisID(), obj->objName(), (void *)sl, (sl != nullptr) ? sl->_list.size() : -1);
}
virtual void write(Common::MemoryWriteStreamDynamic *out);
Commit: 68b08bf030c5359d5a6d33c5dd6aa8cead791069
https://github.com/scummvm/scummvm/commit/68b08bf030c5359d5a6d33c5dd6aa8cead791069
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-19T18:27:42+09:00
Commit Message:
SAGA2: Fix pointer arithmetics in objects.cpp
Changed paths:
engines/saga2/actor.cpp
engines/saga2/objects.cpp
engines/saga2/objects.h
diff --git a/engines/saga2/actor.cpp b/engines/saga2/actor.cpp
index dc6de16758..f8a920235b 100644
--- a/engines/saga2/actor.cpp
+++ b/engines/saga2/actor.cpp
@@ -3516,6 +3516,8 @@ void initActors(void) {
// Initialize the actors with the resource data
new (a) Actor(resourceActorList[i]);
+
+ actorList[i]._index = i + ActorBaseID;
}
// Place all of the extra actors in actor limbo
@@ -3523,6 +3525,8 @@ void initActors(void) {
Actor *a = &actorList[i];
new (a) Actor;
+
+ actorList[i]._index = i + ActorBaseID;
}
actorList[0].disposition = dispositionPlayer + 0;
@@ -3558,10 +3562,12 @@ void loadActors(Common::InSaveFile *in) {
if (actorList == NULL)
error("Unable to load Actors");
- for (int i = 0; i < kActorCount; i++)
+ for (int i = 0; i < kActorCount; i++) {
// Initilize actors with archive data
new (&actorList[i]) Actor(in);
+ actorList[i]._index = i + ActorBaseID;
+ }
}
//-------------------------------------------------------------------
diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index b9a347bbc6..5fca782a89 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -201,6 +201,7 @@ GameObject::GameObject(void) {
memset(&_data.reserved, 0, sizeof(_data.reserved));
_data.obj = this;
+ _index = 0;
}
//-----------------------------------------------------------------------
@@ -225,12 +226,14 @@ GameObject::GameObject(const ResourceGameObject &res) {
memset(&_data.reserved, 0, sizeof(_data.reserved));
_data.obj = this;
+ _index = 0;
}
GameObject::GameObject(Common::InSaveFile *in) {
debugC(3, kDebugSaveload, "Loading object %d", thisID());
read(in, false);
+ _index = 0;
}
void GameObject::read(Common::InSaveFile *in, bool expandProto) {
@@ -328,18 +331,33 @@ void GameObject::write(Common::MemoryWriteStreamDynamic *out, bool expandProto)
// Same as above but use object addresses instead of ID's
bool isObject(GameObject *obj) {
- return (obj >= objectList
- && (uint8 *)obj < (uint8 *)objectList + objectListSize);
+ if (obj == nullptr)
+ return false;
+
+ if (obj->_index >= objectCount)
+ return false;
+
+ return (&objectList[obj->_index] == obj);
}
bool isActor(GameObject *obj) {
- return (obj >= actorList
- && (uint8 *)obj < (uint8 *)actorList + actorListSize);
+ if (obj == nullptr)
+ return false;
+
+ if (obj->_index >= kActorCount + ActorBaseID || obj->_index < ActorBaseID)
+ return false;
+
+ return (&actorList[obj->_index - ActorBaseID] == obj);
}
bool isWorld(GameObject *obj) {
- return (obj >= worldList
- && (uint8 *)obj < (uint8 *)worldList + worldListSize);
+ if (obj == nullptr)
+ return false;
+
+ if (obj->_index >= (uint)worldCount + WorldBaseID || obj->_index < WorldBaseID)
+ return false;
+
+ return (&worldList[obj->_index - WorldBaseID] == obj);
}
// returns the address of the object based on the ID, and this
@@ -380,18 +398,7 @@ uint16 GameObject::containmentSet(void) {
// Calculates the ID of an object, given it's (implicit) address
ObjectID GameObject::thisID(void) { // calculate our own id
- ObjectID id;
-
- id = (GameObject *)this - objectList;
- if (id < objectCount) return id;
-
- id = (Actor *)this - actorList;
- if (id < kActorCount) return id + ActorBaseID;
-
- id = (GameWorld *)this - worldList;
- if (id < worldCount) return id + WorldBaseID;
-
- return Nothing;
+ return _index;
}
// Since Worlds have more than one object chain, we need a function
@@ -2772,6 +2779,8 @@ void initWorlds(void) {
GameWorld *gw = &worldList[i];
new (gw) GameWorld(i);
+
+ worldList[i]._index = i + WorldBaseID;
}
currentWorld = &worldList[0];
@@ -2820,9 +2829,12 @@ void loadWorlds(Common::InSaveFile *in) {
debugC(3, kDebugSaveload, "... currentWorldID = %d", currentWorldID);
- for (int i = 0; i < worldCount; ++i)
+ for (int i = 0; i < worldCount; ++i) {
new (&worldList[i]) GameWorld(in);
+ worldList[i]._index = i + WorldBaseID;
+ }
+
// Reset the current world
currentWorld = (GameWorld *)GameObject::objectAddress(currentWorldID);
setCurrentMap(currentWorld->mapNum);
@@ -2905,6 +2917,8 @@ void initObjects(void) {
else
// Initialize the objects with the resource data
new (obj) GameObject(resourceObjectList[i]);
+
+ objectList[i]._index = i;
}
for (; i < objectCount; i++) {
@@ -2912,6 +2926,8 @@ void initObjects(void) {
// Use the default constructor for the extra actors
new (obj) GameObject;
+
+ objectList[i]._index = i;
}
// Go through the object list and initialize all objects.
@@ -2999,6 +3015,7 @@ void loadObjects(Common::InSaveFile *in) {
for (int i = 0; i < objectCount; i++) {
objectList[i].read(in, true);
in->readUint16LE();
+ objectList[i]._index = i;
}
}
diff --git a/engines/saga2/objects.h b/engines/saga2/objects.h
index 605eb1029f..0b6526faf6 100644
--- a/engines/saga2/objects.h
+++ b/engines/saga2/objects.h
@@ -173,6 +173,7 @@ protected:
ProtoObj *prototype; // object that defines our behavior
public:
ObjectData _data;
+ uint _index;
// Default constructor
GameObject(void);
More information about the Scummvm-git-logs
mailing list