[Scummvm-git-logs] scummvm master -> 8b460556aca362cfc125cf971292bf74e2a0b105
a-yyg
76591232+a-yyg at users.noreply.github.com
Mon Jul 12 10:24:58 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:
54cf566278 SAGA2: Make actorCount constant
8b460556ac SAGA2: Move _bandList construction to Saga2Engine
Commit: 54cf5662781ce6778ef54b8af8dabc19b0d8ce8d
https://github.com/scummvm/scummvm/commit/54cf5662781ce6778ef54b8af8dabc19b0d8ce8d
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-12T19:23:19+09:00
Commit Message:
SAGA2: Make actorCount constant
Changed paths:
engines/saga2/actor.cpp
engines/saga2/actor.h
engines/saga2/idtypes.h
engines/saga2/objects.cpp
engines/saga2/objproto.h
diff --git a/engines/saga2/actor.cpp b/engines/saga2/actor.cpp
index 8940261f00..7a47e694df 100644
--- a/engines/saga2/actor.cpp
+++ b/engines/saga2/actor.cpp
@@ -72,7 +72,6 @@ extern ProtoObj *objectProtos;
extern ActorProto *actorProtos;
extern Actor *actorList;
-extern int16 actorCount;
extern int32 actorListSize;
@@ -1046,6 +1045,7 @@ void Actor::init(
currentRecoveryPoints = 0;
leader = NULL;
followers = NULL;
+ _followersID = NoBand;
for (i = 0; i < ARMOR_COUNT; i++)
armorObjects[i] = Nothing;
currentTarget = NULL;
@@ -1113,6 +1113,7 @@ Actor::Actor(void) {
currentRecoveryPoints = 0;
leader = nullptr;
followers = nullptr;
+ _followersID = NoBand;
for (int i = 0; i < ARMOR_COUNT; i++)
armorObjects[i] = Nothing;
currentTarget = nullptr;
@@ -1181,6 +1182,7 @@ Actor::Actor(const ResourceActor &res) : GameObject(res) {
currentRecoveryPoints = 0;
leader = NULL;
followers = NULL;
+ _followersID = NoBand;
for (i = 0; i < ARMOR_COUNT; i++)
armorObjects[i] = Nothing;
currentTarget = NULL;
@@ -1242,6 +1244,7 @@ Actor::Actor(void **buf) : GameObject(buf) {
followers = a->followersID != NoBand
? getBandAddress(a->followersID)
: NULL;
+ _followersID = NoBand;
for (i = 0; i < ARMOR_COUNT; i++)
armorObjects[i] = a->armorObjects[i];
currentTarget = a->currentTargetID != Nothing
@@ -1320,10 +1323,10 @@ Actor::Actor(Common::InSaveFile *in) : GameObject(in) {
? (Actor *)GameObject::objectAddress(leaderID)
: nullptr;
- int followersID = in->readSint16LE();
+ _followersID = in->readSint16LE();
- followers = followersID != NoBand
- ? getBandAddress(followersID)
+ followers = _followersID != NoBand
+ ? getBandAddress(_followersID)
: nullptr;
for (int i = 0; i < ARRAYSIZE(armorObjects); ++i)
@@ -1380,7 +1383,7 @@ Actor::Actor(Common::InSaveFile *in) : GameObject(in) {
debugC(4, kDebugSaveload, "... recPointsPerUpdate = %d", recPointsPerUpdate);
debugC(4, kDebugSaveload, "... currentRecoveryPoints = %d", currentRecoveryPoints);
debugC(4, kDebugSaveload, "... leaderID = %d", leaderID);
- debugC(4, kDebugSaveload, "... followersID = %d", followersID);
+ debugC(4, kDebugSaveload, "... followersID = %d", _followersID);
// debugC(4, kDebugSaveload, "... armorObjects = %d", armorObjects);
debugC(4, kDebugSaveload, "... currentTargetID = %d", currentTargetID);
// debugC(4, kDebugSaveload, "... scriptVar = %d", scriptVar);
@@ -1605,7 +1608,7 @@ Actor *Actor::newActor(
int16 i;
// Search actor list for first scavangable actor
- for (i = playerActors; i < actorCount; i++) {
+ for (i = playerActors; i < kActorCount; i++) {
a = &actorList[i];
if ((a->flags & temporary)
@@ -1617,7 +1620,7 @@ Actor *Actor::newActor(
// REM: If things start getting really tight, we can
// start recycling common objects...
- if (i >= actorCount)
+ if (i >= kActorCount)
return nullptr;
} else {
actorLimboCount--;
@@ -3559,12 +3562,11 @@ void updateActorStates(void) {
static const int32 evalRateMask = evalRate - 1;
static int32 baseActorIndex = evalRateMask;
extern Actor *actorList;
- extern int16 actorCount;
int32 actorIndex;
actorIndex = baseActorIndex = (baseActorIndex + 1) & evalRateMask;
- while (actorIndex < actorCount) {
+ while (actorIndex < kActorCount) {
Actor *a = &actorList[actorIndex];
if (isWorld(a->IDParent()))
@@ -3574,7 +3576,7 @@ void updateActorStates(void) {
}
updatesViaScript = 0;
- for (actorIndex = 0; actorIndex < actorCount; actorIndex++) {
+ for (actorIndex = 0; actorIndex < kActorCount; actorIndex++) {
Actor *a = &actorList[actorIndex];
if (isWorld(a->IDParent()) && a->isActivated())
@@ -3649,12 +3651,9 @@ void initActors(void) {
if (resourceActorCount < 1)
error("Unable to load Actors");
- // Add extra space for alias actors
- actorCount = resourceActorCount + extraActors;
-
// Allocate memory for the actor list
- actorListSize = actorCount * sizeof(Actor);
- actorList = new Actor[actorCount]();
+ actorListSize = kActorCount * sizeof(Actor);
+ actorList = new Actor[kActorCount]();
if (!actorList)
error("Unable to load Actors");
@@ -3678,7 +3677,7 @@ void initActors(void) {
}
// Place all of the extra actors in actor limbo
- for (; i < actorCount; i++) {
+ for (; i < kActorCount; i++) {
Actor *a = &actorList[i];
new (a) Actor;
@@ -3703,7 +3702,7 @@ void saveActors(SaveFileConstructor &saveGame) {
// Add size of actor count
archiveBufSize += sizeof(int16);
- for (i = 0; i < actorCount; i++)
+ for (i = 0; i < kActorCount; i++)
archiveBufSize += actorList[i].archiveSize();
archiveBuffer = malloc(archiveBufSize);
@@ -3713,10 +3712,10 @@ void saveActors(SaveFileConstructor &saveGame) {
bufferPtr = (int16 *)archiveBuffer;
// Store the number of actors in the archive buffer
- *bufferPtr++ = actorCount;
+ *bufferPtr++ = kActorCount;
// Store the actor data in the archive buffer
- for (i = 0; i < actorCount; i++)
+ for (i = 0; i < kActorCount; i++)
bufferPtr = (int16 *)actorList[i].archive(bufferPtr);
// Write the archive buffer to the save file
@@ -3738,16 +3737,16 @@ void saveActors(Common::OutSaveFile *out) {
// Add size of actor count
archiveBufSize += sizeof(int16);
- for (int i = 0; i < actorCount; i++)
+ for (int i = 0; i < kActorCount; i++)
archiveBufSize += actorList[i].archiveSize();
out->write("ACTR", 4);
out->writeUint32LE(archiveBufSize);
- out->writeSint16LE(actorCount);
+ out->writeSint16LE(kActorCount);
- debugC(3, kDebugSaveload, "... actorCount = %d", actorCount);
+ debugC(3, kDebugSaveload, "... kActorCount = %d", kActorCount);
- for (int i = 0; i < actorCount; ++i)
+ for (int i = 0; i < kActorCount; ++i)
actorList[i].write(out);
}
@@ -3761,11 +3760,11 @@ void loadActors(SaveFileReader &saveGame) {
void *bufferPtr;
// Read in the actor count
- saveGame.read(&actorCount, sizeof(actorCount));
+ //saveGame.read(&actorCount, sizeof(kActorCount));
// Allocate the actor array
- actorListSize = actorCount * sizeof(Actor);
- actorList = new Actor[actorCount]();
+ actorListSize = kActorCount * sizeof(Actor);
+ actorList = new Actor[kActorCount]();
if (actorList == NULL)
error("Unable to load Actors");
@@ -3777,7 +3776,7 @@ void loadActors(SaveFileReader &saveGame) {
saveGame.read(archiveBuffer, archiveBufSize);
- for (i = 0, bufferPtr = archiveBuffer; i < actorCount; i++)
+ for (i = 0, bufferPtr = archiveBuffer; i < kActorCount; i++)
// Initilize actors with archive data
new (&actorList[i]) Actor(&bufferPtr);
@@ -3789,17 +3788,17 @@ void loadActors(Common::InSaveFile *in) {
debugC(2, kDebugSaveload, "Loading actors");
// Read in the actor count
- actorCount = in->readSint16LE();
+ in->readSint16LE();
- debugC(3, kDebugSaveload, "... actorCount = %d", actorCount);
+ debugC(3, kDebugSaveload, "... kActorCount = %d", kActorCount);
// Allocate the actor array
- actorListSize = actorCount * sizeof(Actor);
- actorList = new Actor[actorCount]();
+ actorListSize = kActorCount * sizeof(Actor);
+ actorList = new Actor[kActorCount]();
if (actorList == NULL)
error("Unable to load Actors");
- for (int i = 0; i < actorCount; i++)
+ for (int i = 0; i < kActorCount; i++)
// Initilize actors with archive data
new (&actorList[i]) Actor(in);
@@ -3812,7 +3811,7 @@ void cleanupActors(void) {
if (actorList != NULL) {
int16 i;
- for (i = 0; i < actorCount; i++)
+ for (i = 0; i < kActorCount; i++)
actorList[i].~Actor();
delete[] actorList;
diff --git a/engines/saga2/actor.h b/engines/saga2/actor.h
index b1a19f1a39..13d66908bf 100644
--- a/engines/saga2/actor.h
+++ b/engines/saga2/actor.h
@@ -700,6 +700,7 @@ public:
Actor *leader; // This actor's leader
Band *followers; // This actor's band of followers
+ BandID _followersID;
ObjectID armorObjects[ARMOR_COUNT]; // armor objects being worn
diff --git a/engines/saga2/idtypes.h b/engines/saga2/idtypes.h
index 433677f6b0..1baf637e33 100644
--- a/engines/saga2/idtypes.h
+++ b/engines/saga2/idtypes.h
@@ -259,6 +259,10 @@ enum {
kMaxWeapons = 256
};
+enum {
+ kActorCount = 575
+};
+
//
// Damage effects - these are the types of damage in the world
// Damage being defined as a change in effective vitality
diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index 32690d693e..d27395cd02 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -78,7 +78,6 @@ GameObject *objectList = nullptr; // list of all objects
const int16 objectCount = 4971; // count of objects
Actor *actorList = nullptr; // list of all actors
-int16 actorCount;
GameWorld *worldList = nullptr; // list of all worlds
int16 worldCount; // number of worlds
@@ -406,7 +405,7 @@ GameObject *GameObject::objectAddress(ObjectID id) {
return worldList != nullptr ? &worldList[id - WorldBaseID] : nullptr;
}
- if (id - ActorBaseID >= actorCount)
+ if (id - ActorBaseID >= kActorCount)
error("Invalid object ID: %d!", id);
return actorList != nullptr ? &actorList[id - ActorBaseID] : nullptr;
@@ -432,7 +431,7 @@ ObjectID GameObject::thisID(void) { // calculate our own id
if (id < objectCount) return id;
id = (Actor *)this - actorList;
- if (id < actorCount) return id + ActorBaseID;
+ if (id < kActorCount) return id + ActorBaseID;
id = (GameWorld *)this - worldList;
if (id < worldCount) return id + WorldBaseID;
@@ -3153,7 +3152,7 @@ void initObjects(void) {
// Make a pass over the actor list appending each actor to their
// parent's child list
- for (i = 0; i < actorCount; i++) {
+ for (i = 0; i < kActorCount; i++) {
Actor *a = &actorList[i];
if (a->_data.parentID == Nothing) {
@@ -4786,7 +4785,7 @@ void doBackgroundSimulation(void) {
// Calculate how many actors and/or objects we want to
// update in this cycle
objectUpdateCount = objectCount / objectCycleTime;
- actorUpdateCount = actorCount / actorCycleTime;
+ actorUpdateCount = kActorCount / actorCycleTime;
// do background processing on a few objects, based on clock time.
while (objectUpdateCount--) {
@@ -4826,7 +4825,7 @@ void doBackgroundSimulation(void) {
a = &actorList[actorIndex++];
// Wrap the counter around to the beginning if needed
- if (actorIndex >= actorCount) actorIndex = 0;
+ if (actorIndex >= kActorCount) actorIndex = 0;
// If actor is not deleted, then tell that actor to do
// a background update
diff --git a/engines/saga2/objproto.h b/engines/saga2/objproto.h
index 2a4d1de790..0c722c3253 100644
--- a/engines/saga2/objproto.h
+++ b/engines/saga2/objproto.h
@@ -43,8 +43,7 @@ class gameObject;
* ===================================================================== */
extern const int16 objectCount; // Number of elements in the object list
-extern int16 actorCount, // Number of elements in the actor list
- worldCount; // Number of elements in the world list
+extern int16 worldCount; // Number of elements in the world list
#define Permanent ((uint8)255)
@@ -59,7 +58,7 @@ inline bool isObject(ObjectID id) {
}
inline bool isActor(ObjectID id) {
- return (id >= ActorBaseID && id < ActorBaseID + actorCount);
+ return (id >= ActorBaseID && id < ActorBaseID + kActorCount);
}
inline bool isWorld(ObjectID id) {
Commit: 8b460556aca362cfc125cf971292bf74e2a0b105
https://github.com/scummvm/scummvm/commit/8b460556aca362cfc125cf971292bf74e2a0b105
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-12T19:23:19+09:00
Commit Message:
SAGA2: Move _bandList construction to Saga2Engine
Changed paths:
engines/saga2/band.cpp
engines/saga2/band.h
engines/saga2/saga2.cpp
diff --git a/engines/saga2/band.cpp b/engines/saga2/band.cpp
index 971c375c6a..fbcc122da3 100644
--- a/engines/saga2/band.cpp
+++ b/engines/saga2/band.cpp
@@ -33,63 +33,7 @@
namespace Saga2 {
-/* ===================================================================== *
- BandList class
- * ===================================================================== */
-
-const int kNumBands = 32;
-
-// Manages the memory used for the Band's. There will only be one
-// global instantiation of this class
-class BandList {
-public:
- Band *_list[kNumBands];
-
- // Constructor -- initial construction
- BandList(void);
-
- // Destructor
- ~BandList(void);
-
- // Reconstruct from an archive buffer
- void *restore(void *buf);
-
- void read(Common::InSaveFile *in);
-
- // Return the number of bytes necessary to archive this task list
- // in a buffer
- int32 archiveSize(void);
-
- // Create an archive of the task list in an archive buffer
- void *archive(void *buf);
-
- void write(Common::OutSaveFile *out);
-
- // Place a Band from the inactive list into the active
- // list.
- Band *newBand(void);
- Band *newBand(BandID id);
-
- void addBand(Band *band);
-
- // Place a Band back into the inactive list.
- void deleteBand(Band *p);
-
- // Return the specified Band's ID
- BandID getBandID(Band *b) {
- for (int i = 0; i < kNumBands; i++)
- if (_list[i] == b)
- return i;
-
- error("BandList::getBandID(): Unknown band");
- }
-
- // Return a pointer to a Band given a BandID
- Band *getBandAddress(BandID id) {
- assert(id >= 0 && id < kNumBands);
- return _list[id];
- }
-};
+extern Actor *actorList;
//----------------------------------------------------------------------
// BandList constructor -- simply place each element of the array in
@@ -312,7 +256,6 @@ Band *getBandAddress(BandID id) {
// Initialize the bandList
void initBands(void) {
- g_vm->_bandList = new BandList();
}
//----------------------------------------------------------------------
@@ -392,14 +335,24 @@ void loadBands(Common::InSaveFile *in, int32 chunkSize) {
// Reconstruct taskList from archived data
g_vm->_bandList = new BandList;
g_vm->_bandList->read(in);
+
+ // Reconstruct followers for actors
+ for (int i = 0; i < kActorCount; ++i) {
+ BandID id = actorList[i]._followersID;
+ actorList[i].followers = id != NoBand
+ ? getBandAddress(id)
+ : nullptr;
+ }
}
//----------------------------------------------------------------------
// Cleanup the bandList
void cleanupBands(void) {
- delete g_vm->_bandList;
- g_vm->_bandList = nullptr;
+ for (int i = 0; i < BandList::kNumBands; i++) {
+ if (g_vm->_bandList->_list[i])
+ delete g_vm->_bandList->_list[i];
+ }
}
/* ===================================================================== *
diff --git a/engines/saga2/band.h b/engines/saga2/band.h
index 34598478b3..a4300491ca 100644
--- a/engines/saga2/band.h
+++ b/engines/saga2/band.h
@@ -60,6 +60,66 @@ void loadBands(Common::InSaveFile *in, int32 chunkSize);
// Cleanup the band list
void cleanupBands(void);
+/* ===================================================================== *
+ BandList class
+ * ===================================================================== */
+
+// Manages the memory used for the Band's. There will only be one
+// global instantiation of this class
+class BandList {
+public:
+ enum {
+ kNumBands = 32
+ };
+
+ Band *_list[kNumBands];
+
+ // Constructor -- initial construction
+ BandList(void);
+
+ // Destructor
+ ~BandList(void);
+
+ // Reconstruct from an archive buffer
+ void *restore(void *buf);
+
+ void read(Common::InSaveFile *in);
+
+ // Return the number of bytes necessary to archive this task list
+ // in a buffer
+ int32 archiveSize(void);
+
+ // Create an archive of the task list in an archive buffer
+ void *archive(void *buf);
+
+ void write(Common::OutSaveFile *out);
+
+ // Place a Band from the inactive list into the active
+ // list.
+ Band *newBand(void);
+ Band *newBand(BandID id);
+
+ void addBand(Band *band);
+
+ // Place a Band back into the inactive list.
+ void deleteBand(Band *p);
+
+ // Return the specified Band's ID
+ BandID getBandID(Band *b) {
+ for (int i = 0; i < kNumBands; i++)
+ if (_list[i] == b)
+ return i;
+
+ error("BandList::getBandID(): Unknown band");
+ }
+
+ // Return a pointer to a Band given a BandID
+ Band *getBandAddress(BandID id) {
+ assert(id >= 0 && id < kNumBands);
+ return _list[id];
+ }
+};
+
/* ===================================================================== *
Band class
* ===================================================================== */
diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index 055a98bce0..25749b5cf8 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -35,11 +35,12 @@
#include "saga2/saga2.h"
#include "saga2/fta.h"
-#include "saga2/gdraw.h"
-#include "saga2/motion.h"
-#include "saga2/mouseimg.h"
+#include "saga2/band.h"
#include "saga2/contain.h"
+#include "saga2/gdraw.h"
#include "saga2/imagcach.h"
+#include "saga2/mouseimg.h"
+#include "saga2/motion.h"
namespace Saga2 {
@@ -75,6 +76,7 @@ Saga2Engine::Saga2Engine(OSystem *syst)
_imageCache = new CImageCache;
_mTaskList = new MotionTaskList;
+ _bandList = new BandList();
_edpList = nullptr;
_sdpList = nullptr;
@@ -90,6 +92,7 @@ Saga2Engine::~Saga2Engine() {
delete _rnd;
delete _imageCache;
delete _mTaskList;
+ delete _bandList;
}
Common::Error Saga2Engine::run() {
More information about the Scummvm-git-logs
mailing list