mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 21:59:17 +00:00
SAGA2: Kill rmem and rserver
This commit is contained in:
parent
36ea80697b
commit
54d2e7ac11
@ -218,7 +218,7 @@ void CAutoMap::locateRegion(void) {
|
||||
}
|
||||
}
|
||||
|
||||
RDisposePtr(trRes);
|
||||
free(trRes);
|
||||
if (areaRes) auxResFile->disposeContext(areaRes);
|
||||
|
||||
baseCoords.u = centerCoords.u - summaryRadius;
|
||||
@ -568,7 +568,7 @@ int16 openAutoMap() {
|
||||
|
||||
unloadImageRes(closeBtnImage, numBtnImages);
|
||||
unloadImageRes(scrollBtnImage, 2);
|
||||
RDisposePtr(summaryData);
|
||||
free(summaryData);
|
||||
resFile->disposeContext(decRes);
|
||||
decRes = NULL;
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "saga2/band.h"
|
||||
#include "saga2/savefile.h"
|
||||
#include "saga2/dlist.h"
|
||||
#include "saga2/rmem.h"
|
||||
|
||||
namespace Saga2 {
|
||||
|
||||
@ -328,7 +327,7 @@ void saveBands(SaveFileConstructor &saveGame) {
|
||||
|
||||
archiveBufSize = bandList.archiveSize();
|
||||
|
||||
archiveBuffer = RNewPtr(archiveBufSize, NULL, "archive buffer");
|
||||
archiveBuffer = malloc(archiveBufSize);
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate band archive buffer");
|
||||
|
||||
@ -339,7 +338,7 @@ void saveBands(SaveFileConstructor &saveGame) {
|
||||
archiveBuffer,
|
||||
archiveBufSize);
|
||||
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -355,7 +354,7 @@ void loadBands(SaveFileReader &saveGame) {
|
||||
void *archiveBuffer;
|
||||
void *bufferPtr;
|
||||
|
||||
archiveBuffer = RNewPtr(saveGame.getChunkSize(), NULL, "archive buffer");
|
||||
archiveBuffer = malloc(saveGame.getChunkSize());
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate task archive buffer");
|
||||
|
||||
@ -368,7 +367,7 @@ void loadBands(SaveFileReader &saveGame) {
|
||||
new (&bandList) BandList;
|
||||
bandList.restore(bufferPtr);
|
||||
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -1822,7 +1822,7 @@ void saveContainerNodes(SaveFileConstructor &saveGame) {
|
||||
archiveBufSize += numNodes * ContainerNode::archiveSize();
|
||||
|
||||
// Allocate the archive buffer
|
||||
archiveBuffer = RNewPtr(archiveBufSize, NULL, "archive buffer");
|
||||
archiveBuffer = malloc(archiveBufSize);
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate ContainerNode archive buffer\n");
|
||||
|
||||
@ -1847,7 +1847,7 @@ void saveContainerNodes(SaveFileConstructor &saveGame) {
|
||||
archiveBufSize);
|
||||
|
||||
// Free the archive buffer
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
void loadContainerNodes(SaveFileReader &saveGame) {
|
||||
@ -1874,7 +1874,7 @@ void loadContainerNodes(SaveFileReader &saveGame) {
|
||||
|
||||
// Allocate archive buffer
|
||||
archiveBufSize = saveGame.bytesLeftInChunk();
|
||||
archiveBuffer = RNewPtr(archiveBufSize, NULL, "archive buffer");
|
||||
archiveBuffer = malloc(archiveBufSize);
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate ContainerNode archive buffer\n");
|
||||
|
||||
@ -1897,7 +1897,7 @@ void loadContainerNodes(SaveFileReader &saveGame) {
|
||||
assert(tempList.empty());
|
||||
|
||||
// Free the archive buffer
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
void cleanupContainerNodes(void) {
|
||||
|
@ -159,14 +159,12 @@ CDocument::CDocument(CDocumentAppearance &dApp,
|
||||
textSize = clamp(0, strlen(buffer), maxSize);
|
||||
|
||||
// set the original text pointer
|
||||
//origText = ( char * )RNewPtr( textSize + 1, NULL, "book original text buffer" );
|
||||
origText = new char[textSize + 1];
|
||||
|
||||
// and fill it
|
||||
strcpy(origText, buffer);
|
||||
|
||||
// make a working buffer
|
||||
//text = ( char * )RNewPtr( textSize + 1, NULL, "book work text buffer" );
|
||||
text = new char[textSize + 1];
|
||||
|
||||
// and fill it
|
||||
@ -205,25 +203,24 @@ CDocument::~CDocument(void) {
|
||||
|
||||
for (i = 0; i < maxPages; i++) {
|
||||
if (images[i]) {
|
||||
RDisposePtr(images[i]);
|
||||
free(images[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// get rid of the working text buffer
|
||||
if (text) {
|
||||
//RDisposePtr( text );
|
||||
delete text;
|
||||
delete[] text;
|
||||
text = NULL;
|
||||
}
|
||||
|
||||
if (origText) {
|
||||
//RDisposePtr( origText );
|
||||
delete origText;
|
||||
delete[] origText;
|
||||
origText = NULL;
|
||||
}
|
||||
|
||||
// get rid of the resource context
|
||||
if (illustrationCon) resFile->disposeContext(illustrationCon);
|
||||
if (illustrationCon)
|
||||
resFile->disposeContext(illustrationCon);
|
||||
}
|
||||
|
||||
void CDocument::deactivate(void) {
|
||||
|
@ -28,7 +28,6 @@
|
||||
#define SAGA2_FTA_H
|
||||
|
||||
#include "saga2/gpointer.h"
|
||||
#include "saga2/rmem.h"
|
||||
|
||||
namespace Saga2 {
|
||||
|
||||
@ -160,30 +159,12 @@ void WriteStatusF(int16 lin, const char *msg, ...);
|
||||
// File loading
|
||||
|
||||
void *LoadFile(char *filename); // load file into buffer
|
||||
RHANDLE LoadFileToHandle(char *filename); // load file into relocatable buf
|
||||
|
||||
// Resource loading
|
||||
|
||||
void *LoadResource(hResContext *con, uint32 id, const char desc[]);
|
||||
RHANDLE LoadResourceToHandle(hResContext *con, uint32 id, const char desc[]);
|
||||
Common::SeekableReadStream *loadResourceToStream(hResContext *con, uint32 id, const char desc[]);
|
||||
|
||||
// Asynchronous resource loading
|
||||
|
||||
void RequestResource(
|
||||
RHANDLE handle,
|
||||
int32 offset,
|
||||
int32 length,
|
||||
// Function to notify when request is done.
|
||||
void *notify = NULL,
|
||||
void *userData = NULL);
|
||||
|
||||
void syncResources(void);
|
||||
void *lockResource(RHANDLE h);
|
||||
void unlockResource(RHANDLE h);
|
||||
|
||||
void loadAsyncResources(void);
|
||||
|
||||
// Directory control
|
||||
|
||||
void restoreProgramDir(void); // chdir() to program directory
|
||||
@ -191,7 +172,6 @@ void restoreProgramDir(void); // chdir() to program directory
|
||||
// Memory allocation
|
||||
|
||||
void *mustAlloc(uint32 size, const char desc[]); // alloc 'size' bytes or fail
|
||||
RHANDLE mustAllocHandle(uint32 size, const char desc[]); // as above, but relocatable
|
||||
|
||||
// Returns Random Number
|
||||
|
||||
@ -250,8 +230,6 @@ extern bool gameRunning; // true while game running
|
||||
extern gDisplayPort mainPort; // main drawing port
|
||||
extern gMousePointer pointer; // the mouse pointer
|
||||
|
||||
extern RHeapPtr gameHeap; // memory heap for game
|
||||
|
||||
extern volatile int32 gameTime; // current timer
|
||||
|
||||
// Resource files
|
||||
|
@ -296,8 +296,6 @@ bool gTextBox::insertText(char *newText, int length) {
|
||||
currentLen[index] += (length - selWidth);
|
||||
fieldStrings[index][currentLen[index]] = '\0';
|
||||
|
||||
RMemIntegrity();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -334,8 +332,6 @@ void gTextBox::setText(char *newText) {
|
||||
cursorPos = anchorPos = 0;
|
||||
|
||||
if (window.isOpen()) drawContents();
|
||||
|
||||
RMemIntegrity();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -996,8 +992,6 @@ void gTextBox::drawContents(void) {
|
||||
|
||||
DisposeTempPort(tPort); // dispose of temporary pixelmap
|
||||
}
|
||||
|
||||
RMemIntegrity();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -1115,8 +1109,6 @@ void gTextBox::drawAll(gPort &port,
|
||||
|
||||
DisposeTempPort(tempPort); // dispose of temporary pixelmap
|
||||
}
|
||||
|
||||
RMemIntegrity();
|
||||
}
|
||||
|
||||
} // end of namespace Saga2
|
||||
|
@ -104,7 +104,7 @@ hResContext::~hResContext() {
|
||||
releaseIndexData();
|
||||
}
|
||||
|
||||
hResEntry *hResContext::findEntry(hResID id, RHANDLE **capture) {
|
||||
hResEntry *hResContext::findEntry(hResID id) {
|
||||
hResEntry *entry;
|
||||
int16 i;
|
||||
|
||||
@ -374,53 +374,6 @@ byte *hResContext::loadResource(hResID id, const char desc[], Common::String fil
|
||||
return res;
|
||||
}
|
||||
|
||||
RHANDLE hResContext::load(hResID id, const char desc[], bool async, bool cacheable) {
|
||||
hResEntry *entry;
|
||||
RHANDLE *capture;
|
||||
|
||||
if (!_valid)
|
||||
return nullptr;
|
||||
_bytecount = 0;
|
||||
_bytepos = 0;
|
||||
|
||||
if ((entry = findEntry(id, &capture)) == nullptr)
|
||||
return nullptr;
|
||||
|
||||
if (*capture != nullptr && **capture != nullptr) {
|
||||
entry->use();
|
||||
} else {
|
||||
if (*capture == nullptr)
|
||||
*capture = (RHANDLE)malloc(entry->size);
|
||||
|
||||
if (*capture == nullptr) return nullptr;
|
||||
|
||||
// If it's an external resource, then load synchronously
|
||||
|
||||
#ifdef WINKLUDGE
|
||||
async = false;
|
||||
#endif
|
||||
if (entry->isExternal() || async == false) {
|
||||
if (seek(id) && read(**capture, entry->size)) {
|
||||
entry->use();
|
||||
} else {
|
||||
free(*capture);
|
||||
*capture = nullptr;
|
||||
}
|
||||
|
||||
rest();
|
||||
} else {
|
||||
#ifndef WINKLUDGE
|
||||
RequestResource(*capture,
|
||||
entry->offset,
|
||||
entry->size);
|
||||
#endif
|
||||
entry->use();
|
||||
}
|
||||
}
|
||||
|
||||
return (*capture);
|
||||
}
|
||||
|
||||
byte *hResContext::loadIndexResource(int16 index, const char desc[], Common::String filename) {
|
||||
hResEntry *entry;
|
||||
entry = &_base[index];
|
||||
@ -455,63 +408,6 @@ byte *hResContext::loadIndexResource(int16 index, const char desc[], Common::Str
|
||||
return res;
|
||||
}
|
||||
|
||||
RHANDLE hResContext::loadIndex(int16 index, const char desc[], bool cacheable) {
|
||||
hResEntry *entry;
|
||||
RHANDLE *capture; //, _handle;
|
||||
|
||||
if (!_valid)
|
||||
return nullptr;
|
||||
_bytecount = 0;
|
||||
_bytepos = 0;
|
||||
|
||||
entry = &_base[index];
|
||||
|
||||
if (*capture != nullptr && **capture != nullptr) {
|
||||
entry->use();
|
||||
} else {
|
||||
if (*capture == nullptr)
|
||||
*capture = (RHANDLE)malloc(entry->size);
|
||||
|
||||
if (*capture == nullptr) return nullptr;
|
||||
|
||||
_res->_handle->seek(entry->resOffset(), SEEK_SET);
|
||||
|
||||
if (read(**capture, entry->size) == false) {
|
||||
free(*capture);
|
||||
*capture = nullptr;
|
||||
}
|
||||
entry->use();
|
||||
rest();
|
||||
}
|
||||
return (*capture);
|
||||
}
|
||||
|
||||
void hResContext::release(RHANDLE p) {
|
||||
_bytecount = 0;
|
||||
_bytepos = 0;
|
||||
|
||||
hResEntry *entry;
|
||||
RHANDLE *d;
|
||||
|
||||
if (_valid && p != nullptr) {
|
||||
entry = _base;
|
||||
|
||||
while (entry->id != BAD_ID) {
|
||||
if ((RHANDLE)p == *d) {
|
||||
|
||||
entry->abandon();
|
||||
if (!entry->isUsed()) {
|
||||
RDisposeHandle(p);
|
||||
*d = nullptr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
entry++;
|
||||
d++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hResContext::releaseIndexData() {
|
||||
debugC(4, kDebugResources, "releaseIndexData():");
|
||||
for (DataMap::iterator i = _indexData.begin(); i != _indexData.end(); ++i) {
|
||||
@ -619,21 +515,4 @@ void hResource::disposeContext(hResContext *con) {
|
||||
if (con) delete con;
|
||||
}
|
||||
|
||||
|
||||
/* ===================================================================== *
|
||||
Assorted functions
|
||||
* ===================================================================== */
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// For handles which have been purged, but the handle structure is
|
||||
// still hanging around, we can free the handle structure and
|
||||
// set the actual handle pointer to nullptr.
|
||||
|
||||
void washHandle(RHANDLE &handle) {
|
||||
if (handle != nullptr && *handle == nullptr) {
|
||||
RDisposeHandle(handle);
|
||||
handle = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace Saga2
|
||||
|
@ -29,8 +29,6 @@
|
||||
|
||||
#include "common/file.h"
|
||||
|
||||
#include "saga2/rmem.h"
|
||||
|
||||
namespace Saga2 {
|
||||
|
||||
|
||||
@ -132,7 +130,7 @@ protected:
|
||||
uint32 _bytecount;
|
||||
uint32 _bytepos;
|
||||
|
||||
hResEntry *findEntry(hResID id, RHANDLE **capture = NULL);
|
||||
hResEntry *findEntry(hResID id);
|
||||
Common::File *openExternal(Common::File *fh);
|
||||
|
||||
public:
|
||||
@ -169,11 +167,8 @@ public:
|
||||
bool skip(uint32 amount);
|
||||
bool get(hResID id, void *buffer, uint32 size);
|
||||
uint32 getSize(hResID id, const char desc[]);
|
||||
RHANDLE load(hResID id, const char [], bool async = false, bool cacheable = true);
|
||||
byte *loadResource(hResID id, const char desc[], Common::String filename = "");
|
||||
byte *loadIndexResource(int16 index, const char desc[], Common::String filename = "");
|
||||
RHANDLE loadIndex(int16 index, const char[], bool cacheable = true);
|
||||
void release(RHANDLE p);
|
||||
void releaseIndexData();
|
||||
Common::File *resFileHandle(void) {
|
||||
return _handle;
|
||||
@ -219,9 +214,6 @@ inline hResID RES_ID(uint8 a, uint8 b, uint8 c, uint8 d) {
|
||||
#define HRES_ID MKTAG('H','R','E','S')
|
||||
|
||||
|
||||
// Handle-washing function.
|
||||
void washHandle(RHANDLE &handle);
|
||||
|
||||
#ifdef _WIN32 // Set structure alignment packing value to 1 byte
|
||||
#pragma pack( pop )
|
||||
#endif
|
||||
|
@ -55,7 +55,7 @@ CImageNode::CImageNode(hResContext *con, uint32 resID) {
|
||||
|
||||
CImageNode::~CImageNode(void) {
|
||||
if (image) {
|
||||
RDisposePtr(image);
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -1458,7 +1458,7 @@ Thread::Thread(uint16 segNum, uint16 segOff, scriptCallFrame &args) {
|
||||
programCounter.segment = segNum;
|
||||
programCounter.offset = segOff;
|
||||
threadArgs = args;
|
||||
stackBase = (UBytePtr)malloc(stackSize);
|
||||
stackBase = (byte *)malloc(stackSize);
|
||||
stackPtr = stackBase + stackSize - initialStackFrameSize;
|
||||
((uint16 *)stackPtr)[0] = 0; // 0 args
|
||||
((uint16 *)stackPtr)[1] = 0; // dummy return address
|
||||
@ -1498,7 +1498,7 @@ Thread::Thread(void **buf) {
|
||||
|
||||
codeSeg = scriptRes->loadIndexResource(programCounter.segment, "saga code segment");
|
||||
|
||||
stackBase = (UBytePtr)malloc(stackSize);
|
||||
stackBase = (byte *)malloc(stackSize);
|
||||
stackPtr = stackBase + stackSize - stackOffset;
|
||||
|
||||
memcpy(stackPtr, bufferPtr, stackOffset);
|
||||
|
@ -367,7 +367,6 @@ void displayUpdate(void) {
|
||||
reDrawScreen();
|
||||
// Call asynchronous resource loader
|
||||
debugC(1, kDebugEventLoop, "EventLoop: resource update");
|
||||
loadAsyncResources();
|
||||
|
||||
//FIXME: Disabled for debug purposes. Enable and implement later.
|
||||
//audioEventLoop();
|
||||
@ -538,28 +537,6 @@ Common::SeekableReadStream *loadResourceToStream(hResContext *con, uint32 id, co
|
||||
return new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Loads a resource into a relocatable buffer and returns a handle
|
||||
|
||||
RHANDLE LoadResourceToHandle(hResContext *con, uint32 id, const char desc[]) {
|
||||
int32 size;
|
||||
RHANDLE buffer; // allocated buffer
|
||||
|
||||
debugC(3, kDebugResources, "LoadResourceToHandle(): Loading resource %d (%s, %s)", id, tag2str(id), desc);
|
||||
|
||||
size = con->size(id);
|
||||
if (size <= 0 || !con->seek(id)) {
|
||||
error("LoadResourceToHandle(): Error reading resource ID '%s'.", tag2str(id));
|
||||
}
|
||||
|
||||
// Allocate the buffer
|
||||
buffer = mustAllocHandle(size, desc);
|
||||
con->read(*buffer, size);
|
||||
con->rest();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
typedef hResource *pHResource;
|
||||
|
||||
inline char drive(char *path) {
|
||||
@ -958,17 +935,4 @@ void *mustAlloc(uint32 size, const char desc[]) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Allocates relocatable memory, or throws exception if allocation fails.
|
||||
|
||||
RHANDLE mustAllocHandle(uint32 size, const char desc[]) {
|
||||
void **ptr;
|
||||
|
||||
ptr = (void **)malloc(size);
|
||||
// REM: Before we give up completely, try unloading some things...
|
||||
if (ptr == NULL)
|
||||
error("Local handle allocation size %d bytes failed.", size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
} // end of namespace Saga2
|
||||
|
@ -58,8 +58,6 @@ MODULE_OBJS := \
|
||||
property.o \
|
||||
pt2angle.o \
|
||||
rect.o \
|
||||
rmem.o \
|
||||
rserver.o \
|
||||
saga2.o \
|
||||
sagafunc.o \
|
||||
savefile.o \
|
||||
|
@ -4973,7 +4973,7 @@ void saveMotionTasks(SaveFileConstructor &saveGame) {
|
||||
|
||||
archiveBufSize = mTaskList.archiveSize();
|
||||
|
||||
archiveBuffer = RNewPtr(archiveBufSize, NULL, "archive buffer");
|
||||
archiveBuffer = malloc(archiveBufSize);
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate motion task archive buffer");
|
||||
|
||||
@ -4984,7 +4984,7 @@ void saveMotionTasks(SaveFileConstructor &saveGame) {
|
||||
archiveBuffer,
|
||||
archiveBufSize);
|
||||
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -5000,7 +5000,7 @@ void loadMotionTasks(SaveFileReader &saveGame) {
|
||||
void *archiveBuffer;
|
||||
void *bufferPtr;
|
||||
|
||||
archiveBuffer = RNewPtr(saveGame.getChunkSize(), NULL, "archive buffer");
|
||||
archiveBuffer = malloc(saveGame.getChunkSize());
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate motion task archive buffer");
|
||||
|
||||
@ -5012,7 +5012,7 @@ void loadMotionTasks(SaveFileReader &saveGame) {
|
||||
// Reconstruct mTaskList from archived data
|
||||
new (&mTaskList) MotionTaskList(&bufferPtr);
|
||||
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -63,122 +63,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <class RESTYPE> class LoadOnCall {
|
||||
BitArray wanted;
|
||||
BitArray locked;
|
||||
BitArray recent;
|
||||
RESTYPE *handle;
|
||||
uint16 handles;
|
||||
uint32 tileID;
|
||||
RHANDLE(*loader)(hResID, bool);
|
||||
|
||||
RESTYPE rLoad(uint16 ind, bool asynch);
|
||||
void rFree(uint16);
|
||||
void rInit(uint16);
|
||||
|
||||
public:
|
||||
|
||||
LoadOnCall(uint16 newSize, RHANDLE(*loadfunction)(hResID, bool), uint32 newID) {
|
||||
tileID = newID;
|
||||
wanted.resize(newSize);
|
||||
locked.resize(newSize);
|
||||
recent.resize(newSize);
|
||||
handle = (RESTYPE *)malloc(sizeof(RESTYPE) * newSize);
|
||||
handles = newSize;
|
||||
loader = loadfunction;
|
||||
for (uint16 i = 0; i < newSize; i++)
|
||||
rInit(i);
|
||||
}
|
||||
|
||||
// destructor
|
||||
~LoadOnCall() {
|
||||
//if (handles) delete[] handle;
|
||||
}
|
||||
|
||||
RESTYPE operator[](uint32 ind) {
|
||||
// assert (ind<handles);
|
||||
if (!locked[ind]) handle[ind] = rLoad(ind, false);
|
||||
return handle[ind];
|
||||
}
|
||||
|
||||
void flush(void) {
|
||||
//recent.clearAll();
|
||||
for (uint16 i = 0; i < handles; i++)
|
||||
if ((locked[i]) && (!recent[i]))
|
||||
rFree(i);
|
||||
//locked|=recent;
|
||||
recent.clearAll();
|
||||
}
|
||||
|
||||
BitArray lockState(void) {
|
||||
return locked;
|
||||
}
|
||||
|
||||
BitArray wantState(void) {
|
||||
return wanted;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <class RESTYPE> RESTYPE LoadOnCall<RESTYPE>::rLoad(uint16 ind, bool asynch) {
|
||||
RESTYPE t;
|
||||
if (isValidPtr(handle[ind]) && locked[ind]) {
|
||||
RLockHandle((RHANDLE) handle[ind]);
|
||||
locked.Bit(ind, true);
|
||||
wanted.Bit(ind, false);
|
||||
recent.Bit(ind, true);
|
||||
return handle[ind];
|
||||
}
|
||||
if (isValidPtr(handle[ind]) && wanted[ind]) {
|
||||
// wait for handle
|
||||
RLockHandle((RHANDLE) handle[ind]);
|
||||
locked.Bit(ind, true);
|
||||
wanted.Bit(ind, false);
|
||||
recent.Bit(ind, true);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//t = (RESTYPE) tileRes->load( tileID + MKTAG( 0,0,0,bankNum ) );
|
||||
t = (RESTYPE) loader(tileID + MKTAG(0, 0, 0, ind), asynch);
|
||||
|
||||
locked.Bit(ind, !asynch);
|
||||
wanted.Bit(ind, asynch);
|
||||
recent.Bit(ind, true);
|
||||
|
||||
if (asynch) {
|
||||
handle[ind] = (RESTYPE) NULL;
|
||||
} else {
|
||||
if (t == NULL) {
|
||||
error("Resource %d could not load (Tile bank)", ind);
|
||||
}
|
||||
handle[ind] = t;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
template <class RESTYPE> void LoadOnCall<RESTYPE>::rFree(uint16 ind) {
|
||||
if (isValidPtr(handle[ind])) {
|
||||
RUnlockHandle((RHANDLE) handle[ind]);
|
||||
locked.Bit(ind, false);
|
||||
//recent.Bit(ind,false);
|
||||
// washHandle(handle[ind]);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RESTYPE> void LoadOnCall<RESTYPE>::rInit(uint16 ind) {
|
||||
RESTYPE t;
|
||||
if (!isValidPtr(handle[ind])) {
|
||||
t = (RESTYPE) loader(tileID + MKTAG(0, 0, 0, ind), false);
|
||||
handle[ind] = t;
|
||||
locked.Bit(ind, true);
|
||||
RUnlockHandle((RHANDLE) handle[ind]);
|
||||
locked.Bit(ind, false);
|
||||
recent.Bit(ind, false);
|
||||
}
|
||||
}
|
||||
|
||||
//typedef LoadOnCall<TileBankHandle> tileBankArray; //(64,tileResLoad);
|
||||
|
||||
} // end of namespace Saga2
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,322 +0,0 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* aint32 with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*
|
||||
* Based on the original sources
|
||||
* Faery Tale II -- The Halls of the Dead
|
||||
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
|
||||
*/
|
||||
|
||||
#ifndef SAGA2_RMEM_H
|
||||
#define SAGA2_RMEM_H
|
||||
|
||||
namespace Saga2 {
|
||||
|
||||
// memory block magic ID's
|
||||
#define RMEM_MAGIC_ID ('E' + 'O'*256)
|
||||
#define RMEM_FREED_ID ('O' + 'E'*256)
|
||||
#define RMEM_LEAK_ID ('O' + 'O'*256)
|
||||
#define RMEM_WALL_ID 0xAE
|
||||
|
||||
// Wiping allocated blocks
|
||||
#define RMEM_WIPE_ALLOC 1
|
||||
#define RMEM_ALLOC_WIPE_ID 0x90
|
||||
|
||||
// Wiping freed blocks
|
||||
#define RMEM_WIPE_FREE 1
|
||||
#define RMEM_FREE_WIPE_ID 0xCD
|
||||
|
||||
// Set this to 1 to display the memory blocks on the screen...
|
||||
#define RMEM_VISIBLE 0
|
||||
|
||||
// Wall Size
|
||||
#define RMEM_WALL_SIZE 8 // memory wall size around allocs
|
||||
#define RMEM_MUNG_ENABLE 1 // enable munging of free blocks
|
||||
|
||||
// enables the automatic setting to NULL of freed RPtrs
|
||||
#define RMEM_AUTO_NULL 1
|
||||
|
||||
// allows the global new and delete to be redirected into the heap
|
||||
#define RMEM_TRAP_NEW_DELETE 1
|
||||
// enables malloc and free macros
|
||||
#define RMEM_TRAP_MALLOC_FREE 1
|
||||
|
||||
// enable warnings about things that aren't cleaned up
|
||||
#define RMEM_WARN_LEAKS 1
|
||||
|
||||
|
||||
/* ===================================================================== *
|
||||
Common Memory Allocation Types
|
||||
Based on std.h types.
|
||||
* ====================================================================== */
|
||||
|
||||
typedef int8 *BytePtr,
|
||||
* *ByteHandle;
|
||||
|
||||
typedef uint8 *UBytePtr,
|
||||
* *UByteHandle;
|
||||
|
||||
typedef int16 *WordPtr,
|
||||
* *WordHandle;
|
||||
|
||||
typedef uint16 *UWordPtr,
|
||||
* *UWordHandle;
|
||||
|
||||
typedef int32 *LongPtr,
|
||||
* *LongHandle;
|
||||
|
||||
typedef uint32 *ULongPtr,
|
||||
* *ULongHandle;
|
||||
|
||||
typedef bool *BoolPtr,
|
||||
* *BoolHandle;
|
||||
|
||||
typedef void **RHANDLE;
|
||||
|
||||
/* ===================================================================== *
|
||||
Some other types
|
||||
* ====================================================================== */
|
||||
|
||||
typedef struct _RHeap RHeap,
|
||||
*RHeapPtr;
|
||||
|
||||
typedef struct _RHandle RHandle;
|
||||
|
||||
/* ===================================================================== *
|
||||
Basic functions
|
||||
* ===================================================================== */
|
||||
|
||||
// Allocate and deallocate a heap
|
||||
RHeapPtr _RNewHeap(uint8 *memory, int32 size);
|
||||
void _RDisposeHeap(RHeapPtr heap);
|
||||
|
||||
// Allocate and Deallocate a block of non-relocatable memory
|
||||
void *_RNewPtr(int32 size, RHeapPtr heap, const char []);
|
||||
void *_RNewClearPtr(int32 size, RHeapPtr heap, const char []);
|
||||
void _RVMMLockPtr(void *ptr);
|
||||
void _RVMMUnlockPtr(void *ptr);
|
||||
void _RDisposePtr(void *ptr);
|
||||
|
||||
// Allcate and Deallocate a block of relocatable memory
|
||||
RHANDLE _RNewHandle(int32 size, RHeapPtr heap, const char []);
|
||||
RHANDLE _RNewClearHandle(int32 size, RHeapPtr heap, const char []);
|
||||
void _RDisposeHandle(RHANDLE handle);
|
||||
|
||||
// Allocate and Deallocate a data associated with handle
|
||||
void *_RAllocHandleData(RHANDLE handle, int32 size, const char []);
|
||||
void _RDisposeHandleData(RHANDLE handle);
|
||||
|
||||
// Lock a handle (prevent from moving)
|
||||
void *_RLockHandle(RHANDLE handle);
|
||||
void _RUnlockHandle(RHANDLE handle);
|
||||
|
||||
// Get and Set the attributes of a handle
|
||||
//void RSetHandleFlags( void *handle, uint16 newflags );
|
||||
uint16 _RGetHandleFlags(RHANDLE handle);
|
||||
|
||||
// Set this handle as cacheable
|
||||
void _RCacheHandle(RHANDLE handle);
|
||||
|
||||
// Functions to mark a handle as "loading"
|
||||
void _RHandleStartLoading(RHANDLE handle);
|
||||
void _RHandleDoneLoading(RHANDLE handle);
|
||||
|
||||
// Return true if loaded data is valid
|
||||
bool _RHandleLoaded(RHANDLE handle);
|
||||
|
||||
// Return true if loaded data will be valid soon.
|
||||
bool _RHandleLoading(RHANDLE handle);
|
||||
|
||||
void RShowMem(void);
|
||||
RHeapPtr whichHeapPublic(void *ptr);
|
||||
RHeapPtr getHeap(void);
|
||||
|
||||
/* ===================================================================== *
|
||||
Advanced Functions (do not use in portable applications!)
|
||||
* ===================================================================== */
|
||||
|
||||
// Link a handle into a chain of handles
|
||||
void _RLinkHandle(RHandle *r, RHandle *prev);
|
||||
void _RDelinkHandle(RHandle *r);
|
||||
|
||||
// Get the size of the allocated block
|
||||
uint32 _RPtrSize(void *ptr);
|
||||
|
||||
// Get the size of the allocated block
|
||||
bool _RPtrVMMLocked(void *ptr);
|
||||
|
||||
// Test memory heap integrity
|
||||
bool _RMemIntegrity(void);
|
||||
|
||||
void heapCheck(void);
|
||||
void _RCheckPtr(void *ptr);
|
||||
|
||||
|
||||
/* ===================================================================== *
|
||||
Include logging routines
|
||||
* ===================================================================== */
|
||||
|
||||
//
|
||||
// Would the VMM be more effective if major memory
|
||||
// reorganizations were triggered by the application?
|
||||
// This would allow complete cleanups to be done
|
||||
// at times when the system was least stressed
|
||||
|
||||
//
|
||||
// The logging of memory actions is done in a
|
||||
// rather brute force manner. The original routines
|
||||
// have been renamed. Macros have been defined
|
||||
// to redirect those calls. If logging is not in use
|
||||
// the original calls will be run. When logging is
|
||||
// enabled routines are called which do the dumping.
|
||||
//
|
||||
|
||||
//
|
||||
// Using these routines:
|
||||
// To start logging memory manager calls use:
|
||||
// startLogging();
|
||||
// To pause/stop logging use:
|
||||
// stopLogging();
|
||||
// To resume a paused log use:
|
||||
// continueLogging();
|
||||
//
|
||||
|
||||
//
|
||||
// Logging options
|
||||
//
|
||||
// Routines Logged
|
||||
// All the RMEM.C routines which are public can
|
||||
// be logged.
|
||||
//
|
||||
// Log Elements
|
||||
// Module dump : shows what call is being made and
|
||||
// where in the source code it was called from
|
||||
// In : The values of the parameters on entry to
|
||||
// the routine
|
||||
// Out : The values of the parameters when returning
|
||||
// from the routine
|
||||
// Return : shows the value returned by the routine
|
||||
//
|
||||
//
|
||||
|
||||
#if DEBUG
|
||||
|
||||
|
||||
// Log file initialization / termination
|
||||
|
||||
void initRMemLogging(void);
|
||||
void startLog(char *filename);
|
||||
void startLogging(void);
|
||||
void continueLogging(void);
|
||||
void stopLogging(void);
|
||||
|
||||
//
|
||||
// These are the logging versions
|
||||
//
|
||||
|
||||
RHeapPtr logRNewHeap(uint8 *m, int32 s, const int l, const char f[]);
|
||||
void logRDisposeHeap(RHeapPtr h, const int l, const char f[]);
|
||||
void *logRNewPtr(int32 s, RHeapPtr h, const char desc[], const int l, const char f[]);
|
||||
void *logRNewClearPtr(int32 s, RHeapPtr h, const char desc[], const int l, const char f[]);
|
||||
void *logRDisposePtr(void *p, const int l, const char f[]);
|
||||
RHANDLE logRNewHandle(int32 s, RHeapPtr h, const char desc[], const int l, const char f[]);
|
||||
RHANDLE logRNewClearHandle(int32 s, RHeapPtr h, const char desc[], const int l, const char f[]);
|
||||
void logRDisposeHandle(RHANDLE h, const int l, const char f[]);
|
||||
void *logRAllocHandleData(RHANDLE h, int32 s, const char desc[], const int l, const char f[]);
|
||||
void logRDisposeHandleData(RHANDLE h, const int l, const char f[]);
|
||||
void *logRLockHandle(RHANDLE h, const int l, const char f[]);
|
||||
void logRUnlockHandle(RHANDLE h, const int l, const char f[]);
|
||||
uint16 logRGetHandleFlags(RHANDLE h, const int l, const char f[]);
|
||||
void logRCacheHandle(RHANDLE h, const int l, const char f[]);
|
||||
void logRHandleStartLoading(RHANDLE h, const int l, const char f[]);
|
||||
void logRHandleDoneLoading(RHANDLE h, const int l, const char f[]);
|
||||
bool logRHandleLoaded(RHANDLE h, const int l, const char f[]);
|
||||
bool logRHandleLoading(RHANDLE h, const int l, const char f[]);
|
||||
void logRLinkHandle(RHandle *r, RHandle *p, const int l, const char f[]);
|
||||
void logRDelinkHandle(RHandle *r, const int l, const char f[]);
|
||||
uint32 logRPtrSize(void *p, const int l, const char f[]);
|
||||
bool logRMemIntegrity(const int l, const char f[]);
|
||||
|
||||
//
|
||||
// These are the remapped memory management routines
|
||||
//
|
||||
|
||||
#define RNewHeap(m,s) (logRNewHeap(m,s,__LINE__,__FILE__))
|
||||
#define RDisposeHeap(h) (logRDisposeHeap(h,__LINE__,__FILE__))
|
||||
#define RNewPtr(s,h,d) (logRNewPtr(s,h,d,__LINE__,__FILE__))
|
||||
#define RNewClearPtr(s,h,d) (logRNewClearPtr(s,h,d,__LINE__,__FILE__))
|
||||
#if RMEM_AUTO_NULL
|
||||
#define RDisposePtr(p) (logRDisposePtr(p,__LINE__,__FILE__),p=NULL)
|
||||
#else
|
||||
#define RDisposePtr(p) (logRDisposePtr(p,__LINE__,__FILE__))
|
||||
#endif
|
||||
#define RNewHandle(s,h,d) (logRNewHandle(s,h,d,__LINE__,__FILE__))
|
||||
#define RNewClearHandle(s,h,d) (logRNewClearHandle(s,h,d,__LINE__,__FILE__))
|
||||
#define RDisposeHandle(h) (logRDisposeHandle(h,__LINE__,__FILE__))
|
||||
#define RAllocHandleData(h,s,d) (logRAllocHandleData(h,s,d,__LINE__,__FILE__))
|
||||
#define RDisposeHandleData(h) (logRDisposeHandleData(h,__LINE__,__FILE__))
|
||||
#define RLockHandle(h) (logRLockHandle(h,__LINE__,__FILE__))
|
||||
#define RUnlockHandle(h) (logRUnlockHandle(h,__LINE__,__FILE__))
|
||||
#define RGetHandleFlags(h) (logRGetHandleFlags(h,__LINE__,__FILE__))
|
||||
#define RCacheHandle(h) (logRCacheHandle(h,__LINE__,__FILE__))
|
||||
#define RHandleStartLoading(h) (logRHandleStartLoading(h,__LINE__,__FILE__))
|
||||
#define RHandleDoneLoading(h) (logRHandleDoneLoading(h,__LINE__,__FILE__))
|
||||
#define RHandleLoaded(h) (logRHandleLoaded(h,__LINE__,__FILE__))
|
||||
#define RHandleLoading(h) (logRHandleLoading(h,__LINE__,__FILE__))
|
||||
#define RLinkHandle(r,p) (logRLinkHandle(r,p,__LINE__,__FILE__))
|
||||
#define RDelinkHandle(r) (logRDelinkHandle(r,__LINE__,__FILE__))
|
||||
#define RPtrSize(p) (logRPtrSize(p,__LINE__,__FILE__))
|
||||
#define RMemIntegrity() (logRMemIntegrity(__LINE__,__FILE__))
|
||||
|
||||
#else // DEBUG
|
||||
|
||||
#define RNewHeap(m,s) (_RNewHeap(m,s))
|
||||
#define RDisposeHeap(h) (_RDisposeHeap(h))
|
||||
#define RNewPtr(s,h,d) (_RNewPtr(s,h,d))
|
||||
#define RNewClearPtr(s,h,d) (_RNewClearPtr(s,h,d))
|
||||
#if RMEM_AUTO_NULL
|
||||
typedef void *pVOID;
|
||||
#define RDisposePtr(p) (_RDisposePtr(p),p=NULL)
|
||||
#else
|
||||
#define RDisposePtr(p) (_RDisposePtr(p))
|
||||
#endif
|
||||
#define RNewHandle(s,h,d) (_RNewHandle(s,h,d))
|
||||
#define RNewClearHandle(s,h,d) (_RNewClearHandle(s,h,d))
|
||||
#define RDisposeHandle(h) (_RDisposeHandle(h))
|
||||
#define RAllocHandleData(h,s,d) (_RAllocHandleData(h,s,d))
|
||||
#define RDisposeHandleData(h) (_RDisposeHandleData(h))
|
||||
#define RLockHandle(h) (_RLockHandle(h))
|
||||
#define RUnlockHandle(h) (_RUnlockHandle(h))
|
||||
#define RGetHandleFlags(h) (_RGetHandleFlags(h))
|
||||
#define RCacheHandle(h) (_RCacheHandle(h))
|
||||
#define RHandleStartLoading(h) (_RHandleStartLoading(h))
|
||||
#define RHandleDoneLoading(h) (_RHandleDoneLoading(h))
|
||||
#define RHandleLoaded(h) (_RHandleLoaded(h))
|
||||
#define RHandleLoading(h) (_RHandleLoading(h))
|
||||
#define RLinkHandle(r,p) (_RLinkHandle(r,p))
|
||||
#define RDelinkHandle(r) (_RDelinkHandle(r))
|
||||
#define RPtrSize(p) (_RPtrSize(p))
|
||||
#define RMemIntegrity (_RMemIntegrity)
|
||||
|
||||
#endif // if/else DEBUG
|
||||
|
||||
} // end of namespace Saga2
|
||||
|
||||
#endif
|
@ -1,183 +0,0 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* aint32 with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*
|
||||
* Based on the original sources
|
||||
* Faery Tale II -- The Halls of the Dead
|
||||
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
|
||||
*/
|
||||
|
||||
#ifndef SAGA2_RMEMBASE_H
|
||||
#define SAGA2_RMEMBASE_H
|
||||
|
||||
namespace Saga2 {
|
||||
|
||||
/* ===================================================================== *
|
||||
Optional memory manager debugging settings
|
||||
Note that none of these has any effect if DEBUG is not 1
|
||||
* ====================================================================== */
|
||||
|
||||
// memory block magic ID's
|
||||
#define RMEM_MAGIC_ID ('E' + 'O'*256)
|
||||
#define RMEM_FREED_ID ('O' + 'E'*256)
|
||||
|
||||
// Wiping allocated blocks
|
||||
#define RMEM_WIPE_ALLOC 1
|
||||
#define RMEM_ALLOC_WIPE_ID 0x90
|
||||
|
||||
// Wiping freed blocks
|
||||
#define RMEM_WIPE_FREE 1
|
||||
#define RMEM_FREE_WIPE_ID 0xCD
|
||||
|
||||
// Set this to 1 to display the memory blocks on the screen...
|
||||
// (You will need to supply the display code)
|
||||
#define RMEM_VISIBLE 0
|
||||
|
||||
#define RMEM_WALL_SIZE 8 // memory wall size around allocs
|
||||
#define RMEM_MUNG_ENABLE 1 // enable munging of free blocks
|
||||
|
||||
|
||||
/* ===================================================================== *
|
||||
types
|
||||
* ====================================================================== */
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef struct RMemPrefix RMemPrefix;
|
||||
typedef struct RHandleBlock RHandleBlock;
|
||||
typedef struct RMemFreeBlock RMemFreeBlock;
|
||||
typedef struct RMemHeader RMemHeader;
|
||||
#endif
|
||||
|
||||
// Flags which apply to a memory block prefix
|
||||
enum memPrefixFlags {
|
||||
rMemRelocatable = (1 << 0), // block is of relocatable type
|
||||
rMemPurgeable = (1 << 1), // block is purgeable
|
||||
|
||||
// settable by appliprog
|
||||
// rMemUserFlags = (rMemPurgeable | rMemCacheable)
|
||||
|
||||
// A flag which indicates that the block is not
|
||||
// yet ready for use (mark as "loading");
|
||||
rMemLoading = (1 << 2),
|
||||
|
||||
// This flag indicates has been locked against VMM swapping
|
||||
// in addition to the internal memory locking
|
||||
|
||||
rMemVMMLocked = (1 << 3),
|
||||
};
|
||||
|
||||
|
||||
// ISSUE: For integration with the database functions, it would be
|
||||
// useful to add in a database key or resource ID number, so that the
|
||||
// database routines could search for this data in the cache. Note
|
||||
// however, that the search would still be linear, which might not be
|
||||
// the best method. There might be a way to combine the LRU algorithm
|
||||
// with some kind of hash chain, so that only a few cache entries
|
||||
// need be searched.
|
||||
|
||||
// RMemPrefix: This small structure precedes every allocated block
|
||||
|
||||
struct RMemPrefix {
|
||||
#if DEBUG
|
||||
int16 magic;
|
||||
#endif
|
||||
uint32 size; // length of this block, incl. prefix
|
||||
RHandle *handle; // back pointer to handle
|
||||
uint8 flags, // flags: purgeable, etc.
|
||||
lockNestCount; // nest count of locks
|
||||
#if DEBUG
|
||||
char description[16];
|
||||
#endif
|
||||
// 10 bytes ( + 18 if DEBUG )
|
||||
};
|
||||
|
||||
|
||||
|
||||
// A Memory Handle, which is an indirect reference to a block of memory.
|
||||
// This is used so that blocks of memory may be reorganized and compacted
|
||||
// while still keeping external references to the memory valid.
|
||||
// The handle has a DNode for two reasons: One, to keep a list of all
|
||||
// unused handles, and also to keep a least-recently-used list of all
|
||||
// purgeable handles.
|
||||
|
||||
struct _RHandle {
|
||||
RHandle *next, // next handle in chain
|
||||
*prev; // previous handle in chain
|
||||
void *data; // pointer to real data for handle
|
||||
// NULL if no data allocated
|
||||
// 12 bytes
|
||||
};
|
||||
|
||||
#define HandleBaseAddr(h) ((RHandle *)((uint8 *)(h) - offsetof( RHandle, data )))
|
||||
#define PrefixBaseAddr(d) ((RMemPrefix *)((uint8 *)(d) - prefixOffset))
|
||||
|
||||
// RHandleBlock: A block of memory handles. It's based on the DNode so that
|
||||
// blocks can be linked and delinked independently of the others.
|
||||
// This block is itself allocated as a non-relocatable block.
|
||||
|
||||
#define HANDLES_PER_BLOCK 64 // number of handles per block
|
||||
|
||||
struct RHandleBlock {
|
||||
RHandleBlock *next,
|
||||
*prev;
|
||||
|
||||
uint16 freeHandleCount; // number of handles in use
|
||||
RHandle *freeHandles; // the first free handle in block
|
||||
RHandle handles[HANDLES_PER_BLOCK]; // array of handles
|
||||
};
|
||||
|
||||
// An "RMemFreeBlock" keeps track of which areas are unused.
|
||||
|
||||
struct RMemFreeBlock {
|
||||
RMemFreeBlock *next; // pointer to next free block
|
||||
uint32 size; // size of this arena
|
||||
};
|
||||
|
||||
|
||||
// A "heap" consists of a linked lists of MemHeaders, such that
|
||||
// allocations within an Arena will be drawn from any of the
|
||||
// MemHeaders.
|
||||
|
||||
struct _RHeap {
|
||||
struct _RHeap *next; // pointer to next heap
|
||||
uint32 size, // size of memory space for heap
|
||||
free; // number of bytes of free memory
|
||||
uint8 *memory; // ptr to actual memory
|
||||
RMemFreeBlock *firstFree; // ptr to first free block
|
||||
RHandleBlock *handleBlocks; // list of blocks of handles
|
||||
RHandle *cacheHead, // list of allocations in the cache
|
||||
*cacheTail; // end of cache list
|
||||
};
|
||||
|
||||
/* Realm memory management functions:
|
||||
|
||||
RMemAvail...
|
||||
RMemCompact...
|
||||
|
||||
// database stuff...
|
||||
handle = RFindCacheItem( heap, keys?? );
|
||||
RSetCacheItem( handle, keys?? );
|
||||
|
||||
RGetResource( keys... );
|
||||
*/
|
||||
|
||||
} // end of namespace Saga2
|
||||
|
||||
#endif
|
@ -1,220 +0,0 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* aint32 with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*
|
||||
* Based on the original sources
|
||||
* Faery Tale II -- The Halls of the Dead
|
||||
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
|
||||
*/
|
||||
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL // FIXME: Remove
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
#include "saga2/std.h"
|
||||
#include "saga2/dlist.h"
|
||||
#include "saga2/ioerrors.h"
|
||||
#include "saga2/hresmgr.h"
|
||||
|
||||
namespace Saga2 {
|
||||
|
||||
class ResourceRequest;
|
||||
|
||||
class ResourceServer : public DList {
|
||||
HR_FILE *fHandle; // resource file handle
|
||||
int32 lastSeekPos; // where drive head is
|
||||
int32 actual; // bytes read so far
|
||||
|
||||
ResourceRequest *currentRequest;
|
||||
|
||||
public:
|
||||
ResourceServer(HR_FILE *); // constructor
|
||||
void service(void);
|
||||
};
|
||||
|
||||
class ResourceRequest : public DNode {
|
||||
public:
|
||||
RHANDLE handle; // where to put the data
|
||||
uint32 offset, // offset in file of data
|
||||
length; // desired length of data
|
||||
bool done; // true if load is finished
|
||||
void *userData; // for app use
|
||||
|
||||
// Function to notify when request is done.
|
||||
void (*notify)(ResourceRequest &);
|
||||
|
||||
ResourceRequest(DList &dl); // constructor
|
||||
};
|
||||
|
||||
/* ===================================================================== *
|
||||
Globals
|
||||
* ===================================================================== */
|
||||
|
||||
ResourceServer *resourceServer; // resource server ptr
|
||||
DList resourceRequestPool; // pool of messages
|
||||
|
||||
const int numResRequests = 32; // up to 32 messages allowed
|
||||
|
||||
/* ===================================================================== *
|
||||
Member Functions
|
||||
* ===================================================================== */
|
||||
ResourceServer::ResourceServer(HR_FILE *fh) {
|
||||
currentRequest = NULL;
|
||||
fHandle = fh; // file handle
|
||||
lastSeekPos = 0; // drive position
|
||||
}
|
||||
|
||||
const int loadQuanta = 0x4000; // 16K
|
||||
|
||||
void ResourceServer::service(void) {
|
||||
if (currentRequest == NULL) {
|
||||
currentRequest = (ResourceRequest *)remHead();
|
||||
|
||||
if (currentRequest == NULL) return;
|
||||
|
||||
// seek to position in file
|
||||
HR_SEEK(fHandle, currentRequest->offset, SEEK_SET);
|
||||
|
||||
// calculate final seek position
|
||||
lastSeekPos = currentRequest->offset + currentRequest->length;
|
||||
actual = 0; // bytes read so far
|
||||
}
|
||||
|
||||
if (currentRequest->length > 0 // while there's data to read
|
||||
&& *currentRequest->handle != NULL) { // and block not flushed
|
||||
int32 loadSize = MIN<uint>(currentRequest->length, loadQuanta);
|
||||
uint8 *buffer = (UBytePtr) * currentRequest->handle + actual;
|
||||
|
||||
// Read 16K worth of data, or however much is left.
|
||||
if (HR_READ(buffer, loadSize, 1, fHandle) != 1)
|
||||
error("Error reading resource");
|
||||
|
||||
buffer += loadSize;
|
||||
currentRequest->length -= loadSize;
|
||||
currentRequest->offset += loadSize;
|
||||
actual += loadSize;
|
||||
|
||||
#if DEBUG
|
||||
WriteStatusF(1, "Loaded: %8.8d", actual);
|
||||
#endif
|
||||
} else {
|
||||
currentRequest->done = true;
|
||||
resourceRequestPool.addTail(*currentRequest);
|
||||
currentRequest = NULL;
|
||||
|
||||
// Mark handle as ready for use.
|
||||
RHandleDoneLoading(currentRequest->handle); // mark handle as loaded
|
||||
|
||||
// Notify callback that resource is done loading
|
||||
if (currentRequest->notify)
|
||||
currentRequest->notify(*currentRequest);
|
||||
currentRequest->notify = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ResourceRequest::ResourceRequest(DList &dl) {
|
||||
notify = NULL;
|
||||
dl.addTail(*this);
|
||||
}
|
||||
|
||||
void RequestResource(
|
||||
RHANDLE handle,
|
||||
int32 offset,
|
||||
int32 length,
|
||||
// Function to notify when request is done.
|
||||
void *notify,
|
||||
void *userData) {
|
||||
ResourceRequest *rr;
|
||||
|
||||
// Try to get a resource request. If none are available,
|
||||
// then wait until one is avauilable.
|
||||
|
||||
for (;;) {
|
||||
rr = (ResourceRequest *)
|
||||
resourceRequestPool.remHead();
|
||||
|
||||
if (rr != NULL) break;
|
||||
|
||||
// Service resources until request is free
|
||||
resourceServer->service();
|
||||
}
|
||||
|
||||
RHandleStartLoading(handle);
|
||||
|
||||
rr->done = false;
|
||||
rr->handle = handle;
|
||||
rr->offset = offset;
|
||||
rr->length = length;
|
||||
rr->notify = (void (*)(ResourceRequest &))notify;
|
||||
rr->userData = userData;
|
||||
|
||||
resourceServer->addTail(*rr);
|
||||
}
|
||||
|
||||
void initServers(void) {
|
||||
warning("STUB: initServers()");
|
||||
#if 0
|
||||
int16 i;
|
||||
resourceServer = NEW_PRES ResourceServer(resFile->resFileHandle());
|
||||
if (resourceServer == NULL) {
|
||||
error("Unable to start up resource server!\n");
|
||||
}
|
||||
|
||||
for (i = 0; i < numResRequests; i++) {
|
||||
NEW_PRES ResourceRequest(resourceRequestPool);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void cleanupServers(void) {
|
||||
ResourceRequest *rr;
|
||||
if (resourceServer)
|
||||
delete resourceServer;
|
||||
resourceServer = NULL;
|
||||
while ((rr = (ResourceRequest *)resourceRequestPool.remHead()))
|
||||
delete rr;
|
||||
}
|
||||
|
||||
void loadAsyncResources(void) {
|
||||
debug(6, "STUB: loadAsyncResources()");
|
||||
|
||||
#if 0
|
||||
resourceServer->service();
|
||||
#endif
|
||||
}
|
||||
|
||||
void syncResources(void) {
|
||||
while (resourceServer->count() > 0)
|
||||
resourceServer->service();
|
||||
}
|
||||
|
||||
void *lockResource(RHANDLE h) {
|
||||
if (h && *h) {
|
||||
while (RHandleLoading(h)) resourceServer->service();
|
||||
return RLockHandle(h);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void unlockResource(RHANDLE handle) {
|
||||
RUnlockHandle(handle);
|
||||
}
|
||||
|
||||
} // end if namespace Saga2
|
@ -227,7 +227,7 @@ static void loadMagicData(void) {
|
||||
spellBook[rsi->spell].setupFromResource(rsi);
|
||||
SpellDisplayPrototypeList::sdpList.add(new SpellDisplayPrototype(rsi));
|
||||
|
||||
RDisposePtr(rsi);
|
||||
free(rsi);
|
||||
i++;
|
||||
}
|
||||
assert(i > 1);
|
||||
@ -248,7 +248,7 @@ static void loadMagicData(void) {
|
||||
if (rse->spell)
|
||||
spellBook[rse->spell].addEffect(rse);
|
||||
|
||||
RDisposePtr(rse);
|
||||
free(rse);
|
||||
i++;
|
||||
}
|
||||
assert(i > 1);
|
||||
|
@ -375,7 +375,7 @@ void saveTaskStacks(SaveFileConstructor &saveGame) {
|
||||
|
||||
archiveBufSize = stackList.archiveSize();
|
||||
|
||||
archiveBuffer = RNewPtr(archiveBufSize, NULL, "archive buffer");
|
||||
archiveBuffer = malloc(archiveBufSize);
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate task stack archive buffer");
|
||||
|
||||
@ -386,7 +386,7 @@ void saveTaskStacks(SaveFileConstructor &saveGame) {
|
||||
archiveBuffer,
|
||||
archiveBufSize);
|
||||
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -404,7 +404,7 @@ void loadTaskStacks(SaveFileReader &saveGame) {
|
||||
void *bufferPtr;
|
||||
|
||||
archiveBufSize = saveGame.getChunkSize();
|
||||
archiveBuffer = RNewPtr(archiveBufSize, NULL, "archive buffer");
|
||||
archiveBuffer = malloc(archiveBufSize);
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate task stack archive buffer");
|
||||
|
||||
@ -419,7 +419,7 @@ void loadTaskStacks(SaveFileReader &saveGame) {
|
||||
|
||||
assert(bufferPtr == &((char *)archiveBuffer)[archiveBufSize]);
|
||||
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -671,7 +671,7 @@ void saveTasks(SaveFileConstructor &saveGame) {
|
||||
|
||||
archiveBufSize = taskList.archiveSize();
|
||||
|
||||
archiveBuffer = RNewPtr(archiveBufSize, NULL, "archive buffer");
|
||||
archiveBuffer = malloc(archiveBufSize);
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate task archive buffer");
|
||||
|
||||
@ -686,7 +686,7 @@ void saveTasks(SaveFileConstructor &saveGame) {
|
||||
archiveBuffer,
|
||||
archiveBufSize);
|
||||
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -704,7 +704,7 @@ void loadTasks(SaveFileReader &saveGame) {
|
||||
void *bufferPtr;
|
||||
|
||||
archiveBufSize = saveGame.getChunkSize();
|
||||
archiveBuffer = RNewPtr(archiveBufSize, NULL, "archive buffer");
|
||||
archiveBuffer = malloc(archiveBufSize);
|
||||
if (archiveBuffer == NULL)
|
||||
error("Unable to allocate task archive buffer");
|
||||
|
||||
@ -719,7 +719,7 @@ void loadTasks(SaveFileReader &saveGame) {
|
||||
|
||||
assert(bufferPtr == &((char *)archiveBuffer)[archiveBufSize]);
|
||||
|
||||
RDisposePtr(archiveBuffer);
|
||||
free(archiveBuffer);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -860,7 +860,7 @@ struct WorldMapData {
|
||||
MetaTileList *metaList; // MetaTile list
|
||||
TileRefPtr activeItemData; // ActiveItem tileRefs
|
||||
ActiveItemList *activeItemList; // ActiveItem list
|
||||
UWordPtr assocList; // Associations
|
||||
uint16 *assocList; // Associations
|
||||
RipTableIDPtr ripTableIDList; // MetaTile object ripping
|
||||
|
||||
ActiveItem *instHash[513]; // ActiveItem hash table
|
||||
|
@ -63,8 +63,6 @@ void RHeapsAMess(void);
|
||||
|
||||
void freeAllTileBanks(void) {
|
||||
tileImageBanks.flush();
|
||||
tileImageBanks.flush();
|
||||
RHeapsAMess();
|
||||
}
|
||||
|
||||
void unlockAllTileBanks(void) {
|
||||
|
@ -684,16 +684,6 @@ void TileModeSetup(void) {
|
||||
|
||||
lastUpdateTime = gameTime;
|
||||
|
||||
#if DEBUG*0
|
||||
debugMap.size.x = 64;
|
||||
debugMap.size.y = 200;
|
||||
|
||||
debugMap.data = (uint8 *)RNewPtr(debugMap.bytes(), NULL);
|
||||
if (debugMap.data == NULL) {
|
||||
fatal("Unable to allocate memory for debug map\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
setCurrentWorld(WorldBaseID);
|
||||
setCurrentMap(currentWorld->mapNum);
|
||||
}
|
||||
|
@ -174,12 +174,10 @@ TERMINATOR(termResourceFiles) {
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
INITIALIZER(initResourceServers) {
|
||||
initServers();
|
||||
return true;
|
||||
}
|
||||
|
||||
TERMINATOR(termResourceServers) {
|
||||
cleanupServers(); // cleanup async servers
|
||||
}
|
||||
|
||||
|
||||
@ -480,10 +478,6 @@ INITIALIZER(initTop) {
|
||||
|
||||
TERMINATOR(termTop) {
|
||||
mainDisable();
|
||||
RMemFastCleanup();
|
||||
#ifdef _WIN32
|
||||
//pWindow->RestoreDisplay();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // end of namespace Saga2
|
||||
|
@ -165,7 +165,7 @@ void loadPalettes(void) {
|
||||
|
||||
void cleanupPalettes(void) {
|
||||
if (noonPalette) {
|
||||
RDisposeHandle((RHANDLE) noonPalette);
|
||||
free(noonPalette);
|
||||
noonPalette = nullptr;
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ void createPalette(
|
||||
int i;
|
||||
uint32 fadeProgress = (elapsedTime << 8) / totalTime_;
|
||||
|
||||
for (i = 0; i < elementsof(newP->entry); i++) {
|
||||
for (i = 0; i < (long)elementsof(newP->entry); i++) {
|
||||
gPaletteEntry *srcPal = &srcP->entry[i];
|
||||
gPaletteEntry *dstPal = &dstP->entry[i];
|
||||
gPaletteEntry *curPal = &newP->entry[i];
|
||||
|
Loading…
Reference in New Issue
Block a user