mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-21 09:26:26 +00:00
SAGA2: Fix Sensor deletion on remove
This commit is contained in:
parent
b146f200bf
commit
46673c7924
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/* ===================================================================== *
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user