SAGA2: Move _bandList construction to Saga2Engine

This commit is contained in:
a/ 2021-07-12 19:22:53 +09:00
parent 54cf566278
commit 8b460556ac
3 changed files with 79 additions and 63 deletions

View File

@ -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];
}
}
/* ===================================================================== *

View File

@ -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
* ===================================================================== */

View File

@ -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() {