aboutsummaryrefslogtreecommitdiff
path: root/sword2
diff options
context:
space:
mode:
authorTorbjörn Andersson2003-11-03 07:47:42 +0000
committerTorbjörn Andersson2003-11-03 07:47:42 +0000
commitb3b0118292df23a5d4bf0e9b32a56fb4ddfba1ea (patch)
treedf5851f12ebb885d05db421078980e122698243e /sword2
parent0ece8aab8b03e0aead5f18e33797ec85294bf158 (diff)
downloadscummvm-rg350-b3b0118292df23a5d4bf0e9b32a56fb4ddfba1ea.tar.gz
scummvm-rg350-b3b0118292df23a5d4bf0e9b32a56fb4ddfba1ea.tar.bz2
scummvm-rg350-b3b0118292df23a5d4bf0e9b32a56fb4ddfba1ea.zip
The resource and memory managers are now created dynamically.
Renamed the resource manager's open/close methods openResource() and closeResource() to avoid confusion. (It was I who originally shortened their names to open() and close(), but I've changed my mind now.) Moved more stuff into Sword2Engine. svn-id: r11088
Diffstat (limited to 'sword2')
-rw-r--r--sword2/anims.cpp44
-rw-r--r--sword2/build_display.cpp94
-rw-r--r--sword2/console.cpp24
-rw-r--r--sword2/controls.cpp38
-rw-r--r--sword2/debug.cpp14
-rw-r--r--sword2/defs.h2
-rw-r--r--sword2/driver/d_draw.cpp2
-rw-r--r--sword2/function.cpp16
-rw-r--r--sword2/icons.cpp18
-rw-r--r--sword2/layers.cpp28
-rw-r--r--sword2/logic.cpp24
-rw-r--r--sword2/maketext.cpp38
-rw-r--r--sword2/mem_view.cpp12
-rw-r--r--sword2/memory.cpp17
-rw-r--r--sword2/memory.h41
-rw-r--r--sword2/mouse.cpp48
-rw-r--r--sword2/protocol.cpp108
-rw-r--r--sword2/protocol.h20
-rw-r--r--sword2/resman.cpp146
-rw-r--r--sword2/resman.h10
-rw-r--r--sword2/router.cpp14
-rw-r--r--sword2/save_rest.cpp208
-rw-r--r--sword2/save_rest.h8
-rw-r--r--sword2/scroll.cpp61
-rw-r--r--sword2/scroll.h3
-rw-r--r--sword2/sound.cpp173
-rw-r--r--sword2/sound.h30
-rw-r--r--sword2/speech.cpp66
-rw-r--r--sword2/startup.cpp24
-rw-r--r--sword2/sword2.cpp60
-rw-r--r--sword2/sword2.h96
-rw-r--r--sword2/tony_gsdk.cpp7
-rw-r--r--sword2/walker.cpp36
33 files changed, 769 insertions, 761 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp
index b84778c6b6..1b14ca409a 100644
--- a/sword2/anims.cpp
+++ b/sword2/anims.cpp
@@ -117,11 +117,11 @@ int32 Logic::animate(int32 *params, bool reverse) {
// if the resource number is within range & it's not
// a null resource
- if (res_man.Res_check_valid(res)) {
+ if (res_man->Res_check_valid(res)) {
// Open the resource. Can close it immediately.
// We've got a pointer to the header.
- head = (_standardHeader *) res_man.open(res);
- res_man.close(res);
+ head = (_standardHeader *) res_man->openResource(res);
+ res_man->closeResource(res);
// if it's not an animation file
if (head->fileType != ANIMATION_FILE) {
@@ -151,7 +151,7 @@ int32 Logic::animate(int32 *params, bool reverse) {
#endif
// open anim file
- anim_file = res_man.open(res);
+ anim_file = res_man->openResource(res);
#ifdef _SWORD2_DEBUG
// check this this resource is actually an animation file!
@@ -161,7 +161,7 @@ int32 Logic::animate(int32 *params, bool reverse) {
#endif
// point to anim header
- anim_head = FetchAnimHeader(anim_file);
+ anim_head = g_sword2->fetchAnimHeader(anim_file);
/* #ifdef _SWORD2_DEBUG
// check there's at least one frame
@@ -190,8 +190,8 @@ int32 Logic::animate(int32 *params, bool reverse) {
// frame of the anim.
// open anim file and point to anim header
- anim_file = res_man.open(ob_graphic->anim_resource);
- anim_head = FetchAnimHeader(anim_file);
+ anim_file = res_man->openResource(ob_graphic->anim_resource);
+ anim_head = g_sword2->fetchAnimHeader(anim_file);
if (reverse)
ob_graphic->anim_pc--;
@@ -210,7 +210,7 @@ int32 Logic::animate(int32 *params, bool reverse) {
}
// close the anim file
- res_man.close(ob_graphic->anim_resource);
+ res_man->closeResource(ob_graphic->anim_resource);
// check if we want the script to loop back & call this function again
return ob_logic->looping ? IR_REPEAT : IR_STOP;
@@ -274,7 +274,7 @@ int32 Logic::fnSetFrame(int32 *params) {
// open the resource (& check it's valid)
- anim_file = res_man.open(res);
+ anim_file = res_man->openResource(res);
#ifdef _SWORD2_DEBUG
// check this this resource is actually an animation file!
@@ -284,7 +284,7 @@ int32 Logic::fnSetFrame(int32 *params) {
#endif
// set up pointer to the animation header
- anim_head = FetchAnimHeader(anim_file);
+ anim_head = g_sword2->fetchAnimHeader(anim_file);
/* #ifdef _SWORD2_DEBUG
// check there's at least one frame
@@ -304,7 +304,7 @@ int32 Logic::fnSetFrame(int32 *params) {
// Close the anim file and drop out of script
- res_man.close(ob_graphic->anim_resource);
+ res_man->closeResource(ob_graphic->anim_resource);
return IR_CONT;
}
@@ -497,11 +497,11 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {
local_text = _sequenceTextList[line].textNumber & 0xffff;
// open text resource & get the line
- text = FetchTextLine(res_man.open(text_res), local_text);
+ text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text);
wavId = (int32) READ_LE_UINT16(text);
// now ok to close the text file
- res_man.close(text_res);
+ res_man->closeResource(text_res);
// 1st word of text line is the official line number
debug(5,"(%d) SEQUENCE TEXT: %s", READ_LE_UINT16(text), text + 2);
@@ -523,7 +523,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {
File fp;
- sprintf(speechFile, "speech%d.clu", res_man.whichCd());
+ sprintf(speechFile, "speech%d.clu", res_man->whichCd());
if (fp.open(speechFile))
fp.close();
else
@@ -540,7 +540,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {
if (gui->_subtitles || !speechRunning) {
// open text resource & get the line
- text = FetchTextLine(res_man.open(text_res), local_text);
+ text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text);
// make the sprite
// 'text+2' to skip the first 2 bytes which form the
// line reference number
@@ -554,7 +554,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {
_sequenceTextList[line].text_mem = fontRenderer.makeTextSprite(text + 2, 600, 255, g_sword2->_speechFontId, 1);
// ok to close the text resource now
- res_man.close(text_res);
+ res_man->closeResource(text_res);
} else {
_sequenceTextList[line].text_mem = NULL;
sequenceText[line]->textSprite = NULL;
@@ -572,7 +572,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {
// if we've made a text sprite for this line...
if (_sequenceTextList[line].text_mem) {
- memory.lockMemory(_sequenceTextList[line].text_mem);
+ memory->lockMemory(_sequenceTextList[line].text_mem);
// now fill out the _spriteInfo structure in the
// _movieTextObjectStructure
@@ -611,7 +611,7 @@ void Logic::clearSequenceSpeech(_movieTextObject *sequenceText[]) {
// free up the mem block containing this text sprite
if (_sequenceTextList[line].text_mem)
- memory.freeMemory(_sequenceTextList[line].text_mem);
+ memory->freeMemory(_sequenceTextList[line].text_mem);
// free up the mem block containing this speech sample
if (_sequenceTextList[line].speech_mem)
@@ -631,7 +631,7 @@ int32 Logic::fnSmackerLeadIn(int32 *params) {
// params: 0 id of lead-in music
- leadIn = res_man.open(params[0]);
+ leadIn = res_man->openResource(params[0]);
#ifdef _SWORD2_DEBUG
header = (_standardHeader *) leadIn;
@@ -646,7 +646,7 @@ int32 Logic::fnSmackerLeadIn(int32 *params) {
if (rv)
debug(5, "SFX ERROR: playFx() returned %.8x", rv);
- res_man.close(params[0]);
+ res_man->closeResource(params[0]);
// fade out any music that is currently playing
fnStopMusic(NULL);
@@ -706,7 +706,7 @@ int32 Logic::fnPlaySequence(int32 *params) {
// open the lead-out music resource, if there is one
if (_smackerLeadOut) {
- leadOut = res_man.open(_smackerLeadOut);
+ leadOut = res_man->openResource(_smackerLeadOut);
#ifdef _SWORD2_DEBUG
header = (_standardHeader *) leadOut;
@@ -738,7 +738,7 @@ int32 Logic::fnPlaySequence(int32 *params) {
// close the lead-out music resource
if (_smackerLeadOut) {
- res_man.close(_smackerLeadOut);
+ res_man->closeResource(_smackerLeadOut);
_smackerLeadOut = 0;
}
diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp
index dc15bbc843..aa734d71e6 100644
--- a/sword2/build_display.cpp
+++ b/sword2/build_display.cpp
@@ -72,44 +72,44 @@ void Sword2Engine::buildDisplay(void) {
// first background parallax + related anims
// open the screen resource
- file = res_man.open(_thisScreen.background_layer_id);
+ file = res_man->openResource(_thisScreen.background_layer_id);
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
if (screenLayerTable->bg_parallax[0]) {
- g_display->renderParallax(FetchBackgroundParallaxLayer(file, 0), 0);
+ g_display->renderParallax(fetchBackgroundParallaxLayer(file, 0), 0);
// release the screen resource before cacheing
// the sprites
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
sendBackPar0Frames();
} else {
// release the screen resource
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
}
// second background parallax + related anims
// open the screen resource
- file = res_man.open(_thisScreen.background_layer_id);
+ file = res_man->openResource(_thisScreen.background_layer_id);
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
if (screenLayerTable->bg_parallax[1]) {
- g_display->renderParallax(FetchBackgroundParallaxLayer(file, 1), 1);
+ g_display->renderParallax(fetchBackgroundParallaxLayer(file, 1), 1);
// release the screen resource before cacheing
// the sprites
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
sendBackPar1Frames();
} else {
// release the screen resource
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
}
// normal backround layer (just the one!)
// open the screen resource
- file = res_man.open(_thisScreen.background_layer_id);
- g_display->renderParallax(FetchBackgroundLayer(file), 2);
+ file = res_man->openResource(_thisScreen.background_layer_id);
+ g_display->renderParallax(fetchBackgroundLayer(file), 2);
// release the screen resource
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
// sprites & layers
@@ -121,35 +121,35 @@ void Sword2Engine::buildDisplay(void) {
// first foreground parallax + related anims
// open the screen resource
- file = res_man.open(_thisScreen.background_layer_id);
+ file = res_man->openResource(_thisScreen.background_layer_id);
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
if (screenLayerTable->fg_parallax[0]) {
- g_display->renderParallax(FetchForegroundParallaxLayer(file, 0), 3);
+ g_display->renderParallax(fetchForegroundParallaxLayer(file, 0), 3);
// release the screen resource before cacheing
// the sprites
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
sendForePar0Frames();
} else {
// release the screen resource
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
}
// second foreground parallax + related anims
// open the screen resource
- file = res_man.open(_thisScreen.background_layer_id);
+ file = res_man->openResource(_thisScreen.background_layer_id);
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
if (screenLayerTable->fg_parallax[1]) {
- g_display->renderParallax(FetchForegroundParallaxLayer(file, 1), 4);
+ g_display->renderParallax(fetchForegroundParallaxLayer(file, 1), 4);
// release the screen resource before cacheing
// the sprites
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
sendForePar1Frames();
} else {
// release the screen resource
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
}
// walkgrid, mouse & player markers & mouse area
@@ -251,7 +251,7 @@ void Sword2Engine::displayMsg(uint8 *text, int time) {
g_display->fadeUp();
- memory.freeMemory(text_spr);
+ memory->freeMemory(text_spr);
g_display->waitForFade();
@@ -356,10 +356,10 @@ void Sword2Engine::processLayer(uint32 layer_number) {
uint32 current_layer_area = 0;
// file points to 1st byte in the layer file
- file = res_man.open(_thisScreen.background_layer_id);
+ file = res_man->openResource(_thisScreen.background_layer_id);
// point to layer header
- layer_head = FetchLayerHeader(file,layer_number);
+ layer_head = fetchLayerHeader(file,layer_number);
spriteInfo.x = layer_head->x;
spriteInfo.y = layer_head->y;
@@ -381,7 +381,7 @@ void Sword2Engine::processLayer(uint32 layer_number) {
_largestLayerArea = current_layer_area;
sprintf(_largestLayerInfo,
"largest layer: %s layer(%d) is %dx%d",
- FetchObjectName(_thisScreen.background_layer_id),
+ fetchObjectName(_thisScreen.background_layer_id),
layer_number, layer_head->width, layer_head->height);
}
@@ -389,7 +389,7 @@ void Sword2Engine::processLayer(uint32 layer_number) {
if (rv)
error("Driver Error %.8x in Process_layer(%d)", rv, layer_number);
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
}
void Sword2Engine::processImage(buildit *build_unit) {
@@ -404,11 +404,11 @@ void Sword2Engine::processImage(buildit *build_unit) {
uint32 current_sprite_area = 0;
// open anim resource file & point to base
- file = res_man.open(build_unit->anim_resource);
+ file = res_man->openResource(build_unit->anim_resource);
- anim_head = FetchAnimHeader(file);
- cdt_entry = FetchCdtEntry(file, build_unit->anim_pc);
- frame_head = FetchFrameHeader(file, build_unit->anim_pc);
+ anim_head = fetchAnimHeader(file);
+ cdt_entry = fetchCdtEntry(file, build_unit->anim_pc);
+ frame_head = fetchFrameHeader(file, build_unit->anim_pc);
// so that 0-colour is transparent
spriteType = RDSPR_TRANS;
@@ -477,7 +477,7 @@ void Sword2Engine::processImage(buildit *build_unit) {
_largestSpriteArea = current_sprite_area;
sprintf(_largestSpriteInfo,
"largest sprite: %s frame(%d) is %dx%d",
- FetchObjectName(build_unit->anim_resource),
+ fetchObjectName(build_unit->anim_resource),
build_unit->anim_pc,
frame_head->width,
frame_head->height);
@@ -507,18 +507,18 @@ void Sword2Engine::processImage(buildit *build_unit) {
// #ifdef _SWORD2_DEBUG
// if (frame_head->width <= 1) {
-// debug(5, "WARNING: 1-pixel-wide frame found in %s (%d)", FetchObjectName(build_unit->anim_resource), build_unit->anim_resource);
+// debug(5, "WARNING: 1-pixel-wide frame found in %s (%d)", fetchObjectName(build_unit->anim_resource), build_unit->anim_resource);
// }
// #endif
rv = g_display->drawSprite(&spriteInfo);
if (rv)
error("Driver Error %.8x with sprite %s (%d) in processImage",
- rv, FetchObjectName(build_unit->anim_resource),
+ rv, fetchObjectName(build_unit->anim_resource),
build_unit->anim_resource);
// release the anim resource
- res_man.close(build_unit->anim_resource);
+ res_man->closeResource(build_unit->anim_resource);
}
void Sword2Engine::resetRenderLists(void) {
@@ -580,11 +580,11 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) {
assert(ob_graph->anim_resource);
- file = res_man.open(ob_graph->anim_resource);
+ file = res_man->openResource(ob_graph->anim_resource);
- anim_head = FetchAnimHeader(file);
- cdt_entry = FetchCdtEntry(file, ob_graph->anim_pc);
- frame_head = FetchFrameHeader(file, ob_graph->anim_pc);
+ anim_head = fetchAnimHeader(file);
+ cdt_entry = fetchCdtEntry(file, ob_graph->anim_pc);
+ frame_head = fetchFrameHeader(file, ob_graph->anim_pc);
// update player graphic details for on-screen debug info
if (ID == CUR_PLAYER_ID) {
@@ -690,7 +690,7 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) {
}
// close animation file
- res_man.close(ob_graph->anim_resource);
+ res_man->closeResource(ob_graph->anim_resource);
}
int32 Logic::fnRegisterFrame(int32 *params) {
@@ -764,17 +764,17 @@ void Sword2Engine::startNewPalette(void) {
g_display->waitForFade();
// open the screen file
- screenFile = res_man.open(_thisScreen.background_layer_id);
+ screenFile = res_man->openResource(_thisScreen.background_layer_id);
- g_display->updatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(screenFile));
+ g_display->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(screenFile));
- g_display->setPalette(0, 256, FetchPalette(screenFile), RDPAL_FADE);
+ g_display->setPalette(0, 256, fetchPalette(screenFile), RDPAL_FADE);
// indicating that it's a screen palette
_lastPaletteRes = 0;
// close screen file
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
// start fade up
g_display->fadeUp();
@@ -872,7 +872,7 @@ void Sword2Engine::setFullPalette(int32 palRes) {
// non-zero: set palette to this separate palette file
if (palRes) {
// open the palette file
- head = (_standardHeader *) res_man.open(palRes);
+ head = (_standardHeader *) res_man->openResource(palRes);
assert(head->fileType == PALETTE_FILE);
@@ -898,21 +898,21 @@ void Sword2Engine::setFullPalette(int32 palRes) {
}
// close palette file
- res_man.close(palRes);
+ res_man->closeResource(palRes);
} else {
// 0: set palette to current screen palette
if (_thisScreen.background_layer_id) {
// open the screen file
- file = res_man.open(_thisScreen.background_layer_id);
- g_display->updatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(file));
+ file = res_man->openResource(_thisScreen.background_layer_id);
+ g_display->updatePaletteMatchTable((uint8 *) fetchPaletteMatchTable(file));
- g_display->setPalette(0, 256, FetchPalette(file), RDPAL_INSTANT);
+ g_display->setPalette(0, 256, fetchPalette(file), RDPAL_INSTANT);
// indicating that it's a screen palette
_lastPaletteRes = 0;
// close screen file
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
} else
error("setFullPalette(0) called, but no current screen available!");
}
diff --git a/sword2/console.cpp b/sword2/console.cpp
index e37faf2784..20465e9a79 100644
--- a/sword2/console.cpp
+++ b/sword2/console.cpp
@@ -182,7 +182,7 @@ bool Debugger::Cmd_Help(int argc, const char **argv) {
}
bool Debugger::Cmd_Mem(int argc, const char **argv) {
- memory.displayMemory();
+ memory->displayMemory();
return true;
}
@@ -192,7 +192,7 @@ bool Debugger::Cmd_Tony(int argc, const char **argv) {
}
bool Debugger::Cmd_Res(int argc, const char **argv) {
- res_man.printConsoleClusters();
+ res_man->printConsoleClusters();
return true;
}
@@ -262,7 +262,7 @@ bool Debugger::Cmd_ResLook(int argc, const char **argv) {
if (argc != 2)
DebugPrintf("Usage: %s number\n", argv[0]);
else
- res_man.examine(atoi(argv[1]));
+ res_man->examine(atoi(argv[1]));
return true;
}
@@ -280,13 +280,13 @@ bool Debugger::Cmd_Kill(int argc, const char **argv) {
if (argc != 2)
DebugPrintf("Usage: %s number\n", argv[0]);
else
- res_man.kill(atoi(argv[1]));
+ res_man->kill(atoi(argv[1]));
return true;
}
bool Debugger::Cmd_Nuke(int argc, const char **argv) {
DebugPrintf("Killing all resources except variable file and player object\n");
- res_man.killAll(true);
+ res_man->killAll(true);
return true;
}
@@ -319,7 +319,7 @@ bool Debugger::Cmd_Rect(int argc, const char **argv) {
}
bool Debugger::Cmd_Clear(int argc, const char **argv) {
- res_man.killAllObjects(true);
+ res_man->killAllObjects(true);
return true;
}
@@ -361,7 +361,7 @@ bool Debugger::Cmd_ListSaveGames(int argc, const char **argv) {
uint8 description[SAVE_DESCRIPTION_LEN];
// if there is a save game print the name
- if (GetSaveDescription(i, description) == SR_OK)
+ if (g_sword2->getSaveDescription(i, description) == SR_OK)
DebugPrintf("%d: \"%s\"\n", i, description);
}
@@ -405,7 +405,7 @@ bool Debugger::Cmd_SaveGame(int argc, const char **argv) {
}
slotNo = atoi(argv[1]);
- rv = SaveGame(slotNo, (uint8 *) description);
+ rv = g_sword2->saveGame(slotNo, (uint8 *) description);
if (rv == SR_OK)
DebugPrintf("Saved game \"%s\" to file \"savegame.%.3d\"\n", description, slotNo);
@@ -434,10 +434,10 @@ bool Debugger::Cmd_RestoreGame(int argc, const char **argv) {
}
slotNo = atoi(argv[1]);
- rv = RestoreGame(slotNo);
+ rv = g_sword2->restoreGame(slotNo);
if (rv == SR_OK) {
- GetSaveDescription(slotNo, description);
+ g_sword2->getSaveDescription(slotNo, description);
DebugPrintf("Restored game \"%s\" from file \"savegame.%.3d\"\n", description, slotNo);
} else if (rv == SR_ERR_FILEOPEN)
DebugPrintf("ERROR: Cannot open file \"savegame.%.3d\"\n", slotNo);
@@ -686,8 +686,8 @@ bool Debugger::Cmd_Events(int argc, const char **argv) {
uint32 target = g_sword2->_eventList[i].id;
uint32 script = g_sword2->_eventList[i].interact_id;
- DebugPrintf("slot %d: id = %s (%d)\n", i, FetchObjectName(target), target);
- DebugPrintf(" script = %s (%d) pos %d\n", FetchObjectName(script / 65536), script / 65536, script % 65536);
+ DebugPrintf("slot %d: id = %s (%d)\n", i, g_sword2->fetchObjectName(target), target);
+ DebugPrintf(" script = %s (%d) pos %d\n", g_sword2->fetchObjectName(script / 65536), script / 65536, script % 65536);
}
}
diff --git a/sword2/controls.cpp b/sword2/controls.cpp
index 3ac0455ea2..3a93a3b410 100644
--- a/sword2/controls.cpp
+++ b/sword2/controls.cpp
@@ -64,14 +64,14 @@ private:
public:
FontRendererGui(int fontId) : _fontId(fontId) {
- uint8 *font = res_man.open(fontId);
+ uint8 *font = res_man->openResource(fontId);
_frameHeader *head;
_spriteInfo sprite;
sprite.type = RDSPR_NOCOMPRESSION | RDSPR_TRANS;
for (int i = 0; i < SIZE_OF_CHAR_SET; i++) {
- head = (_frameHeader *) FetchFrameHeader(font, i);
+ head = (_frameHeader *) g_sword2->fetchFrameHeader(font, i);
sprite.data = (uint8 *) (head + 1);
sprite.w = head->width;
sprite.h = head->height;
@@ -80,7 +80,7 @@ public:
_glyph[i]._height = head->height;
}
- res_man.close(fontId);
+ res_man->closeResource(fontId);
}
~FontRendererGui() {
@@ -89,7 +89,7 @@ public:
}
void fetchText(int textId, char *buf) {
- uint8 *data = FetchTextLine(res_man.open(textId / SIZE), textId & 0xffff);
+ uint8 *data = g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff);
int i;
for (i = 0; data[i + 2]; i++) {
@@ -98,7 +98,7 @@ public:
}
buf[i] = 0;
- res_man.close(textId / SIZE);
+ res_man->closeResource(textId / SIZE);
}
int getTextWidth(char *text) {
@@ -251,11 +251,11 @@ void Widget::createSurfaceImage(int state, uint32 res, int x, int y, uint32 pc)
uint32 spriteType = RDSPR_TRANS;
// open anim resource file, point to base
- file = res_man.open(res);
+ file = res_man->openResource(res);
- anim_head = FetchAnimHeader(file);
- cdt_entry = FetchCdtEntry(file, pc);
- frame_head = FetchFrameHeader(file, pc);
+ anim_head = g_sword2->fetchAnimHeader(file);
+ cdt_entry = g_sword2->fetchCdtEntry(file, pc);
+ frame_head = g_sword2->fetchFrameHeader(file, pc);
// If the frame is flipped. (Only really applicable to frames using
// offsets.)
@@ -296,7 +296,7 @@ void Widget::createSurfaceImage(int state, uint32 res, int x, int y, uint32 pc)
_surfaces[state]._original = true;
// Release the anim resource
- res_man.close(res);
+ res_man->closeResource(res);
};
void Widget::linkSurfaceImage(Widget *from, int state, int x, int y) {
@@ -1086,7 +1086,7 @@ public:
fr = _fr1;
}
- if (GetSaveDescription(gui->_baseSlot + i, description) == SR_OK) {
+ if (g_sword2->getSaveDescription(gui->_baseSlot + i, description) == SR_OK) {
slot->setText(fr, gui->_baseSlot + i, (char *) description);
slot->setClickable(true);
} else {
@@ -1247,7 +1247,7 @@ public:
_editBuffer[_editPos] = 0;
- uint32 rv = SaveGame(_selectedSlot, (uint8 *) &_editBuffer[_firstPos]);
+ uint32 rv = g_sword2->saveGame(_selectedSlot, (uint8 *) &_editBuffer[_firstPos]);
if (rv != SR_OK) {
uint32 textId;
@@ -1261,11 +1261,11 @@ public:
break;
}
- saveLoadError((char*) (FetchTextLine(res_man.open(textId / SIZE), textId & 0xffff) + 2));
+ saveLoadError((char*) (g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff) + 2));
result = 0;
}
} else {
- uint32 rv = RestoreGame(_selectedSlot);
+ uint32 rv = g_sword2->restoreGame(_selectedSlot);
if (rv != SR_OK) {
uint32 textId;
@@ -1282,7 +1282,7 @@ public:
break;
}
- saveLoadError((char *) (FetchTextLine(res_man.open(textId / SIZE), textId & 0xffff) + 2));
+ saveLoadError((char *) (g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff) + 2));
result = 0;
} else {
// Prime system with a game cycle
@@ -1428,7 +1428,7 @@ void Gui::restartControl(void) {
}
// Stop music instantly!
- Kill_music();
+ g_sword2->killMusic();
//in case we were dead - well we're not anymore!
DEAD = 0;
@@ -1442,12 +1442,12 @@ void Gui::restartControl(void) {
// remove all resources from memory, including player object and
// global variables
- res_man.removeAll();
+ res_man->removeAll();
// reopen global variables resource & send address to interpreter -
// it won't be moving
- g_logic.setGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
- res_man.close(1);
+ g_logic.setGlobalInterpreterVariables((int32 *) (res_man->openResource(1) + sizeof(_standardHeader)));
+ res_man->closeResource(1);
DEMO = temp_demo_flag;
diff --git a/sword2/debug.cpp b/sword2/debug.cpp
index 8ef22a9f24..e60e6ef797 100644
--- a/sword2/debug.cpp
+++ b/sword2/debug.cpp
@@ -178,7 +178,7 @@ void Debugger::buildDebugText(void) {
if (CLICKED_ID)
sprintf(buf, "last click at %d,%d (id %d: %s)",
MOUSE_X, MOUSE_Y, CLICKED_ID,
- FetchObjectName(CLICKED_ID));
+ g_sword2->fetchObjectName(CLICKED_ID));
else
sprintf(buf, "last click at %d,%d (---)",
MOUSE_X, MOUSE_Y);
@@ -190,7 +190,7 @@ void Debugger::buildDebugText(void) {
g_display->_mouseX + g_sword2->_thisScreen.scroll_offset_x,
g_display->_mouseY + g_sword2->_thisScreen.scroll_offset_y,
g_sword2->_mouseTouching,
- FetchObjectName(g_sword2->_mouseTouching));
+ g_sword2->fetchObjectName(g_sword2->_mouseTouching));
else
sprintf(buf, "mouse %d,%d (not touching)",
g_display->_mouseX + g_sword2->_thisScreen.scroll_offset_x,
@@ -205,7 +205,7 @@ void Debugger::buildDebugText(void) {
sprintf(buf, "player %d,%d %s (%d) #%d/%d",
g_sword2->_thisScreen.player_feet_x,
g_sword2->_thisScreen.player_feet_y,
- FetchObjectName(_playerGraphic.anim_resource),
+ g_sword2->fetchObjectName(_playerGraphic.anim_resource),
_playerGraphic.anim_resource,
_playerGraphic.anim_pc,
_playerGraphicNoFrames);
@@ -271,7 +271,7 @@ void Debugger::buildDebugText(void) {
if (speechScriptWaiting) {
sprintf(buf, "script waiting for %s (%d)",
- FetchObjectName(speechScriptWaiting),
+ g_sword2->fetchObjectName(speechScriptWaiting),
speechScriptWaiting);
makeDebugTextBlock(buf, 0, 90);
}
@@ -281,7 +281,7 @@ void Debugger::buildDebugText(void) {
showVarPos = 115; // y-coord for first showVar
// res 1 is the global variables resource
- varTable = (int32 *) (res_man.open(1) + sizeof(_standardHeader));
+ varTable = (int32 *) (res_man->openResource(1) + sizeof(_standardHeader));
for (showVarNo = 0; showVarNo < MAX_SHOWVARS; showVarNo++) {
varNo = _showVar[showVarNo]; // get variable number
@@ -296,12 +296,12 @@ void Debugger::buildDebugText(void) {
}
}
- res_man.close(1); // close global variables resource
+ res_man->closeResource(1); // close global variables resource
// memory indicator - this should come last, to show all the
// sprite blocks above!
- memory.memoryString(buf);
+ memory->memoryString(buf);
makeDebugTextBlock(buf, 0, 0);
}
}
diff --git a/sword2/defs.h b/sword2/defs.h
index 93e35d8abb..aa8f9d3c99 100644
--- a/sword2/defs.h
+++ b/sword2/defs.h
@@ -29,7 +29,7 @@
// global variable references
// NB. 4 * <number from linc's Global Variables list>
-#define VAR(n) (*(uint32 *) (res_man._resList[1]->ad + sizeof(_standardHeader) + 4 * (n)))
+#define VAR(n) (*(uint32 *) (res_man->_resList[1]->ad + sizeof(_standardHeader) + 4 * (n)))
#define ID VAR(0)
#define RESULT VAR(1)
diff --git a/sword2/driver/d_draw.cpp b/sword2/driver/d_draw.cpp
index 44069de1c5..407697439a 100644
--- a/sword2/driver/d_draw.cpp
+++ b/sword2/driver/d_draw.cpp
@@ -158,7 +158,7 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu
g_display->createSurface(&msgSprite, &msgSurface);
g_display->drawSurface(&msgSprite, msgSurface);
g_display->deleteSurface(msgSurface);
- memory.freeMemory(data);
+ memory->freeMemory(data);
// In case the cutscene has a long lead-in, start just before
// the first line of text.
diff --git a/sword2/function.cpp b/sword2/function.cpp
index 012a1da211..c4699398ce 100644
--- a/sword2/function.cpp
+++ b/sword2/function.cpp
@@ -99,8 +99,8 @@ int32 Logic::fnPreLoad(int32 *params) {
// params: 0 resource to preload
- res_man.open(params[0]);
- res_man.close(params[0]);
+ res_man->openResource(params[0]);
+ res_man->closeResource(params[0]);
return IR_CONT;
}
@@ -337,8 +337,8 @@ int32 Logic::fnDisplayMsg(int32 *params) {
// +2 to skip the encoded text number in the first 2 chars; 3 is
// duration in seconds
- g_sword2->displayMsg(FetchTextLine(res_man.open(text_res), local_text) + 2, 3);
- res_man.close(text_res);
+ g_sword2->displayMsg(g_sword2->fetchTextLine(res_man->openResource(text_res), local_text) + 2, 3);
+ res_man->closeResource(text_res);
g_sword2->removeMsg();
return IR_CONT;
@@ -353,20 +353,20 @@ int32 Logic::fnResetGlobals(int32 *params) {
int32 size;
uint32 *globals;
- size = res_man.fetchLen(1);
+ size = res_man->fetchLen(1);
size -= sizeof(_standardHeader);
debug(5, "globals size: %d", size);
- globals = (uint32 *) ((uint8 *) res_man.open(1) + sizeof(_standardHeader));
+ globals = (uint32 *) ((uint8 *) res_man->openResource(1) + sizeof(_standardHeader));
// blank each global variable
memset(globals, 0, size);
- res_man.close(1);
+ res_man->closeResource(1);
// all objects but george
- res_man.killAllObjects(false);
+ res_man->killAllObjects(false);
// FOR THE DEMO - FORCE THE SCROLLING TO BE RESET!
// - this is taken from fnInitBackground
diff --git a/sword2/icons.cpp b/sword2/icons.cpp
index 3fa3bd9416..f8513a654b 100644
--- a/sword2/icons.cpp
+++ b/sword2/icons.cpp
@@ -87,9 +87,9 @@ void Sword2Engine::buildMenu(void) {
// Call menu builder script which will register all carried menu
// objects. Run the 'build_menu' script in the 'menu_master' object
- head = res_man.open(MENU_MASTER_OBJECT);
+ head = res_man->openResource(MENU_MASTER_OBJECT);
g_logic.runScript((char*) head, (char*) head, &null_pc);
- res_man.close(MENU_MASTER_OBJECT);
+ res_man->closeResource(MENU_MASTER_OBJECT);
// Compare new with old. Anything in master thats not in new gets
// removed from master - if found in new too, remove from temp
@@ -191,7 +191,7 @@ void Sword2Engine::buildMenu(void) {
icon_coloured = true;
}
- icon = res_man.open(_masterMenuList[j].icon_resource) + sizeof(_standardHeader);
+ icon = res_man->openResource(_masterMenuList[j].icon_resource) + sizeof(_standardHeader);
// The coloured icon is stored directly after the
// greyed out one.
@@ -200,7 +200,7 @@ void Sword2Engine::buildMenu(void) {
icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP);
g_display->setMenuIcon(RDMENU_BOTTOM, j, icon);
- res_man.close(res);
+ res_man->closeResource(res);
} else {
// no icon here
g_display->setMenuIcon(RDMENU_BOTTOM, j, NULL);
@@ -227,17 +227,17 @@ void Sword2Engine::buildSystemMenu(void) {
// build them all high in full colour - when one is clicked on all the
// rest will grey out
- for (int j = 0; j < ARRAYSIZE(icon_list); j++) {
- icon = res_man.open(icon_list[j]) + sizeof(_standardHeader);
+ for (int i = 0; i < ARRAYSIZE(icon_list); i++) {
+ icon = res_man->openResource(icon_list[i]) + sizeof(_standardHeader);
// The only case when an icon is grayed is when the player
// is dead. Then SAVE is not available.
- if (!DEAD || icon_list[j] != SAVE_ICON)
+ if (!DEAD || icon_list[i] != SAVE_ICON)
icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP);
- g_display->setMenuIcon(RDMENU_TOP, j, icon);
- res_man.close(icon_list[j]);
+ g_display->setMenuIcon(RDMENU_TOP, i, icon);
+ res_man->closeResource(icon_list[i]);
}
g_display->showMenu(RDMENU_TOP);
diff --git a/sword2/layers.cpp b/sword2/layers.cpp
index 4e345601b8..3130825d18 100644
--- a/sword2/layers.cpp
+++ b/sword2/layers.cpp
@@ -34,7 +34,7 @@
#include "sword2/logic.h"
#include "sword2/protocol.h"
#include "sword2/resman.h"
-#include "sword2/sound.h" // for Clear_fx_queue() called from fnInitBackground()
+#include "sword2/sound.h" // for clearFxQueue() called from fnInitBackground()
namespace Sword2 {
@@ -55,10 +55,10 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) {
uint8 *file;
uint32 rv;
- debug(5, "CHANGED TO LOCATION \"%s\"", FetchObjectName(res));
+ debug(5, "CHANGED TO LOCATION \"%s\"", fetchObjectName(res));
// stop all fx & clears the queue
- Clear_fx_queue();
+ clearFxQueue();
#ifdef _SWORD2_DEBUG
debug(5, "fnInitBackground(%d)", res);
@@ -92,9 +92,9 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) {
// each cycle
// file points to 1st byte in the layer file
- file = res_man.open(_thisScreen.background_layer_id);
+ file = res_man->openResource(_thisScreen.background_layer_id);
- screen_head = FetchScreenHeader(file);
+ screen_head = fetchScreenHeader(file);
//set number of special sort layers
_thisScreen.number_of_layers = screen_head->noLayers;
@@ -109,7 +109,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) {
if (screen_head->noLayers) {
for (int i = 0; i < screen_head->noLayers; i++) {
// get layer header for layer i
- layer = FetchLayerHeader(file, i);
+ layer = fetchLayerHeader(file, i);
// add into the sort list
@@ -174,7 +174,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) {
spriteInfo.scaledHeight = 0;
spriteInfo.type = 0;
spriteInfo.blend = 0;
- spriteInfo.data = FetchShadingMask(file);
+ spriteInfo.data = fetchShadingMask(file);
spriteInfo.colourTable = 0;
rv = g_display->openLightMask(&spriteInfo);
@@ -189,7 +189,7 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) {
}
// close the screen file
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
setUpBackgroundLayers();
@@ -211,9 +211,9 @@ void Sword2Engine::setUpBackgroundLayers(void) {
// open resource & set pointers to headers
// file points to 1st byte in the layer file
- file = res_man.open(_thisScreen.background_layer_id);
+ file = res_man->openResource(_thisScreen.background_layer_id);
- screen_head = FetchScreenHeader(file);
+ screen_head = fetchScreenHeader(file);
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
@@ -221,26 +221,26 @@ void Sword2Engine::setUpBackgroundLayers(void) {
for (i = 0; i < 2; i++) {
if (screenLayerTable->bg_parallax[i])
- g_display->initialiseBackgroundLayer(FetchBackgroundParallaxLayer(file, i));
+ g_display->initialiseBackgroundLayer(fetchBackgroundParallaxLayer(file, i));
else
g_display->initialiseBackgroundLayer(NULL);
}
// Normal backround layer
- g_display->initialiseBackgroundLayer(FetchBackgroundLayer(file));
+ g_display->initialiseBackgroundLayer(fetchBackgroundLayer(file));
// Foreground parallax layers
for (i = 0; i < 2; i++) {
if (screenLayerTable->fg_parallax[i])
- g_display->initialiseBackgroundLayer(FetchForegroundParallaxLayer(file, i));
+ g_display->initialiseBackgroundLayer(fetchForegroundParallaxLayer(file, i));
else
g_display->initialiseBackgroundLayer(NULL);
}
// close the screen file
- res_man.close(_thisScreen.background_layer_id);
+ res_man->closeResource(_thisScreen.background_layer_id);
}
}
diff --git a/sword2/logic.cpp b/sword2/logic.cpp
index f7f8e41df2..51346af950 100644
--- a/sword2/logic.cpp
+++ b/sword2/logic.cpp
@@ -60,7 +60,7 @@ int Logic::processSession(void) {
// processing on the current list
while (_pc != 0xffffffff) {
- head = (_standardHeader*) res_man.open(run_list);
+ head = (_standardHeader*) res_man->openResource(run_list);
if (head->fileType != RUN_LIST)
error("Logic_engine %d not a run_list", run_list);
@@ -74,7 +74,7 @@ int Logic::processSession(void) {
// release the list again so it can float in memory - at this
// point not one thing should be locked
- res_man.close(run_list);
+ res_man->closeResource(run_list);
debug(5, "%d", ID);
@@ -84,7 +84,7 @@ int Logic::processSession(void) {
return 0;
}
- head = (_standardHeader*) res_man.open(ID);
+ head = (_standardHeader*) res_man->openResource(ID);
if (head->fileType != GAME_OBJECT)
error("Logic_engine %d not an object", ID);
@@ -130,7 +130,7 @@ int Logic::processSession(void) {
raw_data_ad = (char*) head;
- far_head = (_standardHeader*) res_man.open(script / SIZE);
+ far_head = (_standardHeader*) res_man->openResource(script / SIZE);
if (far_head->fileType != GAME_OBJECT && far_head->fileType != SCREEN_MANAGER)
error("Logic_engine %d not a far object (its a %d)", script / SIZE, far_head->fileType);
@@ -145,7 +145,7 @@ int Logic::processSession(void) {
ret = runScript(raw_script_ad, raw_data_ad, &_curObjectHub->script_pc[LEVEL]);
// close foreign object again
- res_man.close(script / SIZE);
+ res_man->closeResource(script / SIZE);
// reset to us for service script
raw_script_ad = raw_data_ad;
@@ -201,7 +201,7 @@ int Logic::processSession(void) {
// and that's it so close the object resource
- res_man.close(ID);
+ res_man->closeResource(ID);
}
// leaving a room so remove all ids that must reboot correctly
@@ -238,7 +238,7 @@ void Logic::expressChangeSession(uint32 sesh_id) {
router.clearWalkGridList();
// stops all fx & clears the queue
- Clear_fx_queue();
+ g_sword2->clearFxQueue();
// free all the route memory blocks from previous game
router.freeAllRouteMem();
@@ -339,17 +339,17 @@ void Logic::examineRunList(void) {
if (_currentRunList) {
// open and lock in place
- game_object_list = (uint32 *) (res_man.open(_currentRunList) + sizeof(_standardHeader));
+ game_object_list = (uint32 *) (res_man->openResource(_currentRunList) + sizeof(_standardHeader));
Debug_Printf("Runlist number %d\n", _currentRunList);
for (int i = 0; game_object_list[i]; i++) {
- file_header = (_standardHeader *) res_man.open(game_object_list[i]);
+ file_header = (_standardHeader *) res_man->openResource(game_object_list[i]);
Debug_Printf("%d %s\n", game_object_list[i], file_header->name);
- res_man.close(game_object_list[i]);
+ res_man->closeResource(game_object_list[i]);
}
- res_man.close(_currentRunList);
+ res_man->closeResource(_currentRunList);
} else
Debug_Printf("No run list set\n");
}
@@ -430,7 +430,7 @@ int32 Logic::fnAddToKillList(int32 *params) {
void Logic::processKillList(void) {
for (uint32 i = 0; i < _kills; i++)
- res_man.remove(_objectKillList[i]);
+ res_man->remove(_objectKillList[i]);
_kills = 0;
}
diff --git a/sword2/maketext.cpp b/sword2/maketext.cpp
index 4d11be3975..5ebb58eb62 100644
--- a/sword2/maketext.cpp
+++ b/sword2/maketext.cpp
@@ -54,7 +54,7 @@
#include "sword2/header.h"
#include "sword2/maketext.h"
#include "sword2/memory.h"
-#include "sword2/protocol.h" // for FetchFrameHeader()
+#include "sword2/protocol.h" // for fetchFrameHeader()
#include "sword2/resman.h"
#include "sword2/sword2.h"
@@ -94,7 +94,7 @@ mem* FontRenderer::makeTextSprite(uint8 *sentence, uint16 maxWidth, uint8 pen, u
// allocate memory for array of lineInfo structures
- line = memory.allocMemory(MAX_LINES * sizeof(LineInfo), MEM_locked, UID_temp);
+ line = memory->allocMemory(MAX_LINES * sizeof(LineInfo), MEM_locked, UID_temp);
// get details of sentence breakdown into array of LineInfo structures
// and get the no of lines involved
@@ -107,7 +107,7 @@ mem* FontRenderer::makeTextSprite(uint8 *sentence, uint16 maxWidth, uint8 pen, u
textSprite = buildTextSprite(sentence, fontRes, pen, (LineInfo *) line->ad, noOfLines);
// free up the lineInfo array now
- memory.freeMemory(line);
+ memory->freeMemory(line);
return textSprite;
}
@@ -220,7 +220,7 @@ mem* FontRenderer::buildTextSprite(uint8 *sentence, uint32 fontRes, uint8 pen, L
// allocate memory for sprite, and lock it ready for use
// NB. 'textSprite' is the given pointer to the handle to be used
- textSprite = memory.allocMemory(sizeof(_frameHeader) + sizeOfSprite, MEM_locked, UID_text_sprite);
+ textSprite = memory->allocMemory(sizeof(_frameHeader) + sizeOfSprite, MEM_locked, UID_text_sprite);
// the handle (*textSprite) now points to UNMOVABLE memory block
// set up the frame header
@@ -244,7 +244,7 @@ mem* FontRenderer::buildTextSprite(uint8 *sentence, uint32 fontRes, uint8 pen, L
memset(linePtr, NO_COL, sizeOfSprite);
// open font file
- charSet = res_man.open(fontRes);
+ charSet = res_man->openResource(fontRes);
// fill sprite with characters, one line at a time
@@ -278,10 +278,10 @@ mem* FontRenderer::buildTextSprite(uint8 *sentence, uint32 fontRes, uint8 pen, L
}
// close font file
- res_man.close(fontRes);
+ res_man->closeResource(fontRes);
// unlock the sprite memory block, so it's movable
- memory.floatMemory(textSprite);
+ memory->floatMemory(textSprite);
return textSprite;
}
@@ -295,14 +295,14 @@ uint16 FontRenderer::charWidth(uint8 ch, uint32 fontRes) {
uint16 width;
// open font file
- charSet = res_man.open(fontRes);
+ charSet = res_man->openResource(fontRes);
// move to approp. sprite (header)
charFrame = findChar(ch, charSet);
width = charFrame->width;
// close font file
- res_man.close(fontRes);
+ res_man->closeResource(fontRes);
// return its width
return width;
@@ -317,14 +317,14 @@ uint16 FontRenderer::charHeight(uint32 fontRes) {
uint16 height;
// open font file
- charSet = res_man.open(fontRes);
+ charSet = res_man->openResource(fontRes);
// assume all chars the same height, i.e. FIRST_CHAR is as good as any
charFrame = findChar(FIRST_CHAR, charSet);
height = charFrame->height;
// close font file
- res_man.close(fontRes);
+ res_man->closeResource(fontRes);
// return its height
return height;
@@ -338,7 +338,7 @@ _frameHeader* FontRenderer::findChar(uint8 ch, uint8 *charSet) {
if (ch < FIRST_CHAR)
ch = DUD;
- return FetchFrameHeader(charSet, ch - FIRST_CHAR);
+ return g_sword2->fetchFrameHeader(charSet, ch - FIRST_CHAR);
}
// Copies a character sprite from 'charPtr' to the sprite buffer at 'spritePtr'
@@ -538,7 +538,7 @@ void FontRenderer::killTextBloc(uint32 bloc_number) {
if (_blocList[bloc_number].text_mem) {
// release the floating memory and mark it as free
- memory.freeMemory(_blocList[bloc_number].text_mem);
+ memory->freeMemory(_blocList[bloc_number].text_mem);
_blocList[bloc_number].text_mem = 0;
} else {
// illegal kill - stop the system
@@ -564,14 +564,14 @@ void Sword2Engine::initialiseFontResourceFlags(void) {
uint8 language;
// open the text resource
- textFile = res_man.open(TEXT_RES);
+ textFile = res_man->openResource(TEXT_RES);
// If language is Polish or Finnish it requires alternate fonts.
// Otherwise, use regular fonts
// get the text line (& skip the 2 chars containing the wavId)
- textLine = FetchTextLine(textFile, SAVE_LINE_NO) + 2;
+ textLine = fetchTextLine(textFile, SAVE_LINE_NO) + 2;
// "talenna" Finnish for "save"
// "zapisz" Polish for "save"
@@ -590,10 +590,10 @@ void Sword2Engine::initialiseFontResourceFlags(void) {
// Get the text line - skip the 2 chars containing the wavId
- if (g_sword2->_features & GF_DEMO)
- textLine = FetchTextLine(textFile, 451) + 2;
+ if (_features & GF_DEMO)
+ textLine = fetchTextLine(textFile, 451) + 2;
else
- textLine = FetchTextLine(textFile, 54) + 2;
+ textLine = fetchTextLine(textFile, 54) + 2;
// According to the GetNameFunction(), which was never called and has
// therefore been removed, the name of the game is:
@@ -606,7 +606,7 @@ void Sword2Engine::initialiseFontResourceFlags(void) {
g_display->setWindowName((char *) textLine);
// now ok to close the text file
- res_man.close(TEXT_RES);
+ res_man->closeResource(TEXT_RES);
}
// called from the above function, and also from console.cpp
diff --git a/sword2/mem_view.cpp b/sword2/mem_view.cpp
index 43befd36b5..80081023b5 100644
--- a/sword2/mem_view.cpp
+++ b/sword2/mem_view.cpp
@@ -44,9 +44,9 @@ void MemoryManager::displayMemory(void) {
j = _baseMemBlock;
do {
if (_memList[j].uid < 65536) {
- file_header = (_standardHeader*) res_man.open(_memList[j].uid);
+ file_header = (_standardHeader*) res_man->openResource(_memList[j].uid);
// close immediately so give a true count
- res_man.close(_memList[j].uid);
+ res_man->closeResource(_memList[j].uid);
debug(5, "view %d", _memList[j].uid);
@@ -73,10 +73,10 @@ void MemoryManager::displayMemory(void) {
_memList[j].size / 1024,
(_memList[j].size * 100) / _totalFreeMemory,
_memList[j].uid,
- res_man.fetchCluster(_memList[j].uid),
+ res_man->fetchCluster(_memList[j].uid),
file_header->name,
- res_man.fetchAge(_memList[j].uid),
- res_man.fetchCount(_memList[j].uid));
+ res_man->fetchAge(_memList[j].uid),
+ res_man->fetchCount(_memList[j].uid));
} else
Debug_Printf(" %d is an illegal resource\n", _memList[j].uid);
} else {
@@ -160,7 +160,7 @@ void MemoryManager::memoryString(char *string) {
sprintf(string,
"locked(%u)+float(%u)+free(%u) = %u/%u blocks (%u%% used)(cur %uk)",
mem_locked, mem_floating, mem_free, blocksUsed, MAX_mem_blocks,
- percent, (res_man.fetchUsage() / 1024));
+ percent, (res_man->fetchUsage() / 1024));
}
} // End of namespace Sword2
diff --git a/sword2/memory.cpp b/sword2/memory.cpp
index c3268af953..bc7ee94345 100644
--- a/sword2/memory.cpp
+++ b/sword2/memory.cpp
@@ -17,9 +17,6 @@
* $Header$
*/
-// FIXME: We should investigate which problem all this memory managing stuff
-// is trying to solve. I'm not convinced that it's really needed.
-
// memory manager
// - "remember, it's not good to leave memory locked for a moment longer
// than necessary" Tony
@@ -45,17 +42,13 @@
namespace Sword2 {
-MemoryManager memory;
+MemoryManager *memory;
#define MEMORY_POOL (1024 * 12000)
// #define MEMDEBUG 1
-void MemoryManager::exit(void) {
- free(_freeMemman);
-}
-
-void MemoryManager::init(void) {
+MemoryManager::MemoryManager(void) {
uint32 j;
uint8 *memory_base;
@@ -91,6 +84,10 @@ void MemoryManager::init(void) {
_baseMemBlock = 0; // for now
}
+MemoryManager::~MemoryManager(void) {
+ free(_freeMemman);
+}
+
mem *MemoryManager::lowLevelAlloc(uint32 size, uint32 type, uint32 unique_id) {
// allocate a block of memory - locked or float
@@ -472,7 +469,7 @@ mem *MemoryManager::allocMemory(uint32 size, uint32 type, uint32 unique_id) {
while (virtualDefrag(size)) {
// trash the oldest closed resource
- if (!res_man.helpTheAgedOut()) {
+ if (!res_man->helpTheAgedOut()) {
error("alloc ran out of memory: size=%d type=%d unique_id=%d", size, type, unique_id);
}
}
diff --git a/sword2/memory.h b/sword2/memory.h
index 8030269539..b3fe7f1afd 100644
--- a/sword2/memory.h
+++ b/sword2/memory.h
@@ -34,10 +34,12 @@ typedef struct {
uint8 *ad;
} mem;
-#define MEM_null 0 // null
-#define MEM_free 1
-#define MEM_locked 2
-#define MEM_float 3
+enum {
+ MEM_null = 0, // null
+ MEM_free = 1,
+ MEM_locked = 2,
+ MEM_float = 3
+};
//---------------------------------------
// MEMORY BLOCKS
@@ -48,17 +50,19 @@ typedef struct {
// highest recorded value from the on-screen info
//---------------------------------------
-#define UID_memman 0xffffffff
-#define UID_NULL 0xfffffffe // FREE
-#define UID_font 0xfffffffd
-#define UID_temp 0xfffffffc
-#define UID_decompression_buffer 0xfffffffb
-#define UID_shrink_buffer 0xfffffffa
-#define UID_con_sprite 0xfffffff9
-#define UID_text_sprite 0xfffffff8
-#define UID_walk_anim 0xfffffff7
-#define UID_savegame_buffer 0xfffffff6
-#define UID_restoregame_buffer 0xfffffff5
+enum {
+ UID_memman = 0xffffffff,
+ UID_NULL = 0xfffffffe, // FREE
+ UID_font = 0xfffffffd,
+ UID_temp = 0xfffffffc,
+ UID_decompression_buffer = 0xfffffffb,
+ UID_shrink_buffer = 0xfffffffa,
+ UID_con_sprite = 0xfffffff9,
+ UID_text_sprite = 0xfffffff8,
+ UID_walk_anim = 0xfffffff7,
+ UID_savegame_buffer = 0xfffffff6,
+ UID_restoregame_buffer = 0xfffffff5
+};
class MemoryManager {
private:
@@ -88,8 +92,9 @@ public:
mem _memList[MAX_mem_blocks];
uint32 _baseMemBlock;
- void init(void);
- void exit(void);
+ MemoryManager(void);
+ ~MemoryManager(void);
+
mem *allocMemory(uint32 size, uint32 type, uint32 unique_id);
void freeMemory(mem *block);
void floatMemory(mem *block);
@@ -100,7 +105,7 @@ public:
void memoryString(char *string);
};
-extern MemoryManager memory;
+extern MemoryManager *memory;
} // End of namespace Sword2
diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp
index 4ad19930e4..a4fd99af90 100644
--- a/sword2/mouse.cpp
+++ b/sword2/mouse.cpp
@@ -163,28 +163,28 @@ void Sword2Engine::systemMenuMouse(void) {
for (j = 0; j < ARRAYSIZE(icon_list); j++) {
// change all others to grey
if (j != hit) {
- icon = res_man.open(icon_list[j]) + sizeof(_standardHeader);
+ icon = res_man->openResource(icon_list[j]) + sizeof(_standardHeader);
g_display->setMenuIcon(RDMENU_TOP, j, icon);
- res_man.close( icon_list[j] );
+ res_man->closeResource(icon_list[j]);
}
}
g_sound->pauseFx();
// NB. Need to keep a safe copy of
- // 'looping_music_id' for savegame & for
+ // '_loopingMusicId' for savegame & for
// playing when returning from control panels
// because control panel music will overwrite
// it!
- safe_looping_music_id = looping_music_id;
+ safe_looping_music_id = _loopingMusicId;
pars[0] = 221; // SystemM234 (M234.wav)
pars[1] = FX_LOOP;
g_logic.fnPlayMusic(pars);
// restore proper looping_music_id
- looping_music_id = safe_looping_music_id;
+ _loopingMusicId = safe_looping_music_id;
// clear the screen & set up the new palette
// for the menus
@@ -251,8 +251,8 @@ void Sword2Engine::systemMenuMouse(void) {
// NB. This will also start music required
// when a game has been restored
- if (looping_music_id) {
- pars[0] = looping_music_id;
+ if (_loopingMusicId) {
+ pars[0] = _loopingMusicId;
pars[1] = FX_LOOP;
g_logic.fnPlayMusic(pars);
@@ -323,7 +323,7 @@ void Sword2Engine::dragMouse(void) {
setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);
- debug(5, "USED \"%s\" ICON ON %s", FetchObjectName(OBJECT_HELD), FetchObjectName(CLICKED_ID));
+ debug(5, "USED \"%s\" ICON ON %s", fetchObjectName(OBJECT_HELD), fetchObjectName(CLICKED_ID));
// Hide menu - back to normal menu mode
@@ -368,7 +368,7 @@ void Sword2Engine::dragMouse(void) {
noHuman();
- debug(5, "USED \"%s\" ICON ON \"%s\" ICON", FetchObjectName(OBJECT_HELD), FetchObjectName(COMBINE_BASE));
+ debug(5, "USED \"%s\" ICON ON \"%s\" ICON", fetchObjectName(OBJECT_HELD), fetchObjectName(COMBINE_BASE));
}
// refresh the menu
@@ -420,7 +420,7 @@ void Sword2Engine::menuMouse(void) {
EXIT_CLICK_ID = 0;
- debug(5, "RIGHT-CLICKED ON \"%s\" ICON", FetchObjectName(OBJECT_HELD));
+ debug(5, "RIGHT-CLICKED ON \"%s\" ICON", fetchObjectName(OBJECT_HELD));
setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT);
@@ -629,11 +629,11 @@ void Sword2Engine::normalMouse(void) {
setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);
if (OBJECT_HELD)
- debug(5, "USED \"%s\" ICON ON %s", FetchObjectName(OBJECT_HELD), FetchObjectName(CLICKED_ID));
+ debug(5, "USED \"%s\" ICON ON %s", fetchObjectName(OBJECT_HELD), fetchObjectName(CLICKED_ID));
else if (LEFT_BUTTON)
- debug(5, "LEFT-CLICKED ON %s", FetchObjectName(CLICKED_ID));
+ debug(5, "LEFT-CLICKED ON %s", fetchObjectName(CLICKED_ID));
else // RIGHT BUTTON
- debug(5, "RIGHT-CLICKED ON %s", FetchObjectName(CLICKED_ID));
+ debug(5, "RIGHT-CLICKED ON %s", fetchObjectName(CLICKED_ID));
}
}
}
@@ -694,7 +694,7 @@ void Sword2Engine::mouseOnOff(void) {
setLuggage(_currentLuggageResource);
}
} else
- error("ERROR: mouse.pointer==0 for object %d (%s) - update logic script!", _mouseTouching, FetchObjectName(_mouseTouching));
+ error("ERROR: mouse.pointer==0 for object %d (%s) - update logic script!", _mouseTouching, fetchObjectName(_mouseTouching));
} else if (_oldMouseTouching && !_mouseTouching) {
// the cursor has moved off something - reset cursor to
// normal pointer
@@ -741,8 +741,8 @@ void Sword2Engine::setMouse(uint32 res) {
_mousePointerRes = res;
if (res) {
- icon = res_man.open(res) + sizeof(_standardHeader);
- len = res_man._resList[res]->size - sizeof(_standardHeader);
+ icon = res_man->openResource(res) + sizeof(_standardHeader);
+ len = res_man->_resList[res]->size - sizeof(_standardHeader);
// don't pulse the normal pointer - just do the regular anim
// loop
@@ -752,7 +752,7 @@ void Sword2Engine::setMouse(uint32 res) {
else
g_display->setMouseAnim(icon, len, RDMOUSE_FLASH);
- res_man.close(res);
+ res_man->closeResource(res);
} else {
// blank cursor
g_display->setMouseAnim(NULL, 0, 0);
@@ -766,12 +766,12 @@ void Sword2Engine::setLuggage(uint32 res) {
_realLuggageItem = res;
if (res) {
- icon = res_man.open(res) + sizeof(_standardHeader);
- len = res_man._resList[res]->size - sizeof(_standardHeader);
+ icon = res_man->openResource(res) + sizeof(_standardHeader);
+ len = res_man->_resList[res]->size - sizeof(_standardHeader);
g_display->setLuggageAnim(icon, len);
- res_man.close(res);
+ res_man->closeResource(res);
} else
g_display->setLuggageAnim(NULL, 0);
}
@@ -960,7 +960,7 @@ void Sword2Engine::createPointerText(uint32 text_id, uint32 pointer_res) {
local_text = text_id & 0xffff;
// open text file & get the line
- text = FetchTextLine(res_man.open(text_res), local_text);
+ text = fetchTextLine(res_man->openResource(text_res), local_text);
// 'text+2' to skip the first 2 bytes which form the
// line reference number
@@ -973,7 +973,7 @@ void Sword2Engine::createPointerText(uint32 text_id, uint32 pointer_res) {
_speechFontId, justification);
// now ok to close the text file
- res_man.close(text_res);
+ res_man->closeResource(text_res);
}
}
}
@@ -1135,12 +1135,12 @@ int32 Logic::fnAddHuman(int32 *params) {
// stops all fx & clears the queue - eg. when leaving a
// location
- Clear_fx_queue();
+ g_sword2->clearFxQueue();
// Trash all object resources so they load in fresh & restart
// their logic scripts
- res_man.killAllObjects(false);
+ res_man->killAllObjects(false);
g_display->setPalette(0, 1, black, RDPAL_INSTANT);
}
diff --git a/sword2/protocol.cpp b/sword2/protocol.cpp
index c01e3f7a91..39ecb39827 100644
--- a/sword2/protocol.cpp
+++ b/sword2/protocol.cpp
@@ -28,10 +28,12 @@
namespace Sword2 {
-// Returns a pointer to the first palette entry, given the pointer to the
-// start of the screen file.
+/**
+ * Returns a pointer to the first palette entry, given the pointer to the start
+ * of the screen file.
+ */
-uint8 *FetchPalette(uint8 *screenFile) {
+uint8 *Sword2Engine::fetchPalette(uint8 *screenFile) {
uint8 *palette;
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
@@ -50,35 +52,41 @@ uint8 *FetchPalette(uint8 *screenFile) {
return palette;
}
-// Returns a pointer to the start of the palette match table, given the
-// pointer to the start of the screen file.
+/**
+ * Returns a pointer to the start of the palette match table, given the pointer
+ * to the start of the screen file.
+ */
-uint8 *FetchPaletteMatchTable(uint8 *screenFile) {
+uint8 *Sword2Engine::fetchPaletteMatchTable(uint8 *screenFile) {
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
return (uint8 *) mscreenHeader + mscreenHeader->paletteTable;
}
-// Returns a pointer to the screen header, given the pointer to the start of
-// the screen file.
+/**
+ * Returns a pointer to the screen header, given the pointer to the start of
+ * the screen file.
+ */
-_screenHeader *FetchScreenHeader(uint8 *screenFile) {
+_screenHeader *Sword2Engine::fetchScreenHeader(uint8 *screenFile) {
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
_screenHeader *screenHeader = (_screenHeader*) ((uint8 *) mscreenHeader + mscreenHeader->screen);
return screenHeader;
}
-// Returns a pointer to the requested layer header, given the pointer to the
-// start of the screen file. Drops out if the requested layer number exceeds
-// the number of layers on this screen.
+/**
+ * Returns a pointer to the requested layer header, given the pointer to the
+ * start of the screen file. Drops out if the requested layer number exceeds
+ * the number of layers on this screen.
+ */
-_layerHeader *FetchLayerHeader(uint8 *screenFile, uint16 layerNo) { // Chris 04Oct96
+_layerHeader *Sword2Engine::fetchLayerHeader(uint8 *screenFile, uint16 layerNo) {
#ifdef _SWORD2_DEBUG
- _screenHeader *screenHead = FetchScreenHeader(screenFile);
+ _screenHeader *screenHead = fetchScreenHeader(screenFile);
if (layerNo > screenHead->noLayers - 1)
- error("FetchLayerHeader(%d) invalid layer number!", layerNo);
+ error("fetchLayerHeader(%d) invalid layer number!", layerNo);
#endif
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
@@ -88,76 +96,86 @@ _layerHeader *FetchLayerHeader(uint8 *screenFile, uint16 layerNo) { // Chris 04O
return layerHeader;
}
-// Returns a pointer to the start of the shading mask, given the pointer to
-// the start of the screen file.
+/**
+ * Returns a pointer to the start of the shading mask, given the pointer to the
+ * start of the screen file.
+ */
-uint8 *FetchShadingMask(uint8 *screenFile) {
+uint8 *Sword2Engine::fetchShadingMask(uint8 *screenFile) {
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
return (uint8 *) mscreenHeader + mscreenHeader->maskOffset;
}
-// Returns a pointer to the anim header, given the pointer to the start of
-// the anim file.
+/**
+ * Returns a pointer to the anim header, given the pointer to the start of the
+ * anim file.
+ */
-_animHeader *FetchAnimHeader(uint8 *animFile) {
+_animHeader *Sword2Engine::fetchAnimHeader(uint8 *animFile) {
return (_animHeader *) (animFile + sizeof(_standardHeader));
}
-// Returns a pointer to the requested frame number's cdtEntry, given the
-// pointer to the start of the anim file. Drops out if the requested frame
-// number exceeds the number of frames in this anim.
+/**
+ * Returns a pointer to the requested frame number's cdtEntry, given the
+ * pointer to the start of the anim file. Drops out if the requested frame
+ * number exceeds the number of frames in this anim.
+ */
-_cdtEntry *FetchCdtEntry(uint8 *animFile, uint16 frameNo) {
- _animHeader *animHead = FetchAnimHeader(animFile);
+_cdtEntry *Sword2Engine::fetchCdtEntry(uint8 *animFile, uint16 frameNo) {
+ _animHeader *animHead = fetchAnimHeader(animFile);
#ifdef _SWORD2_DEBUG
if (frameNo > animHead->noAnimFrames - 1)
- error("FetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
+ error("fetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
#endif
return (_cdtEntry *) ((uint8 *) animHead + sizeof(_animHeader) + frameNo * sizeof(_cdtEntry));
}
-// Returns a pointer to the requested frame number's header, given the
-// pointer to the start of the anim file. Drops out if the requested frame
-// number exceeds the number of frames in this anim
+/**
+ * Returns a pointer to the requested frame number's header, given the pointer
+ * to the start of the anim file. Drops out if the requested frame number
+ * exceeds the number of frames in this anim
+ */
-_frameHeader *FetchFrameHeader(uint8 *animFile, uint16 frameNo) {
+_frameHeader *Sword2Engine::fetchFrameHeader(uint8 *animFile, uint16 frameNo) {
// required address = (address of the start of the anim header) + frameOffset
- return (_frameHeader *) (animFile + sizeof(_standardHeader) + FetchCdtEntry(animFile, frameNo)->frameOffset);
+ return (_frameHeader *) (animFile + sizeof(_standardHeader) + fetchCdtEntry(animFile, frameNo)->frameOffset);
}
-// Returns a pointer to the requested parallax layer data.
+/**
+ * Returns a pointer to the requested parallax layer data.
+ */
-_parallax *FetchBackgroundParallaxLayer(uint8 *screenFile, int layer) {
+_parallax *Sword2Engine::fetchBackgroundParallaxLayer(uint8 *screenFile, int layer) {
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
#ifdef _SWORD2_DEBUG
if (mscreenHeader->bg_parallax[layer] == 0)
- error("FetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer);
+ error("fetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer);
#endif
return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->bg_parallax[layer]);
}
-_parallax *FetchBackgroundLayer(uint8 *screenFile) {
+_parallax *Sword2Engine::fetchBackgroundLayer(uint8 *screenFile) {
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
#ifdef _SWORD2_DEBUG
if (mscreenHeader->screen == 0)
- error("FetchBackgroundLayer (%d) - No background layer exists");
+ error("fetchBackgroundLayer (%d) - No background layer exists");
#endif
return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->screen + sizeof(_screenHeader));
}
-_parallax *FetchForegroundParallaxLayer(uint8 *screenFile, int layer) {
+_parallax *Sword2Engine::fetchForegroundParallaxLayer(uint8 *screenFile, int layer) {
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
#ifdef _SWORD2_DEBUG
if (mscreenHeader->fg_parallax[layer] == 0)
- error("FetchForegroundParallaxLayer(%d) - No parallax layer exists", layer);
+ error("fetchForegroundParallaxLayer(%d) - No parallax layer exists", layer);
#endif
return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->fg_parallax[layer]);
@@ -165,7 +183,7 @@ _parallax *FetchForegroundParallaxLayer(uint8 *screenFile, int layer) {
uint8 errorLine[128];
-uint8 *FetchTextLine(uint8 *file, uint32 text_line) {
+uint8 *Sword2Engine::fetchTextLine(uint8 *file, uint32 text_line) {
_standardHeader *fileHeader;
uint32 *point;
@@ -182,7 +200,7 @@ uint8 *FetchTextLine(uint8 *file, uint32 text_line) {
return errorLine;
}
- //point to the lookup table
+ // point to the lookup table
point = (uint32 *) text_header + 1;
return (uint8 *) (file + READ_LE_UINT32(point + text_line));
@@ -191,7 +209,7 @@ uint8 *FetchTextLine(uint8 *file, uint32 text_line) {
// Used for testing text & speech (see fnISpeak in speech.cpp)
-uint8 CheckTextLine(uint8 *file, uint32 text_line) {
+uint8 Sword2Engine::checkTextLine(uint8 *file, uint32 text_line) {
_textHeader *text_header = (_textHeader *) (file + sizeof(_standardHeader));
// out of range => invalid
@@ -202,11 +220,11 @@ uint8 CheckTextLine(uint8 *file, uint32 text_line) {
return 1;
}
-uint8 *FetchObjectName(int32 resourceId) {
+uint8 *Sword2Engine::fetchObjectName(int32 resourceId) {
_standardHeader *header;
- header = (_standardHeader *) res_man.open(resourceId);
- res_man.close(resourceId);
+ header = (_standardHeader *) res_man->openResource(resourceId);
+ res_man->closeResource(resourceId);
// note this pointer is no longer valid, but it should be ok until
// another resource is opened!
diff --git a/sword2/protocol.h b/sword2/protocol.h
index e6ceb9f365..9addc1984e 100644
--- a/sword2/protocol.h
+++ b/sword2/protocol.h
@@ -22,27 +22,7 @@
#ifndef _PROTOCOL
#define _PROTOCOL
-#include "sword2/driver/driver96.h"
-#include "sword2/header.h"
-
namespace Sword2 {
-
-uint8 *FetchPalette(uint8 *screenFile);
-_screenHeader *FetchScreenHeader(uint8 *screenFile);
-_layerHeader *FetchLayerHeader(uint8 *screenFile, uint16 layerNo);
-uint8 *FetchShadingMask(uint8 *screenFile);
-
-_animHeader *FetchAnimHeader(uint8 *animFile);
-_cdtEntry *FetchCdtEntry(uint8 *animFile, uint16 frameNo);
-_frameHeader *FetchFrameHeader(uint8 *animFile, uint16 frameNo);
-_parallax *FetchBackgroundParallaxLayer(uint8 *screenFile, int layer);
-_parallax *FetchBackgroundLayer(uint8 *screenFile);
-_parallax *FetchForegroundParallaxLayer(uint8 *screenFile, int layer);
-uint8 *FetchTextLine(uint8 *file, uint32 text_line);
-uint8 CheckTextLine(uint8 *file, uint32 text_line);
-uint8 *FetchPaletteMatchTable(uint8 *screenFile);
-uint8 *FetchObjectName(int32 resourceId);
-
} // End of namespace Sword2
#endif
diff --git a/sword2/resman.cpp b/sword2/resman.cpp
index 38768db7fd..79cf76d7a6 100644
--- a/sword2/resman.cpp
+++ b/sword2/resman.cpp
@@ -33,7 +33,7 @@
#include "sword2/mouse.h" // for system setMouse & setLuggage routines
#include "sword2/protocol.h"
#include "sword2/resman.h"
-#include "sword2/sound.h" // for Clear_fx_queue() called from cacheNewCluster()
+#include "sword2/sound.h" // for clearFxQueue() called from cacheNewCluster()
#include "sword2/router.h"
namespace Sword2 {
@@ -54,7 +54,7 @@ namespace Sword2 {
#define BUFFERSIZE 4096
-ResourceManager res_man; //declare the object global
+ResourceManager *res_man; // declare the object global
// ---------------------------------------------------------------------------
//
@@ -64,11 +64,13 @@ ResourceManager res_man; //declare the object global
//
// ---------------------------------------------------------------------------
-#define BOTH 0x0 // Cluster is on both CDs
-#define CD1 0x1 // Cluster is on CD1 only
-#define CD2 0x2 // Cluster is on CD2 only
-#define LOCAL_CACHE 0x4 // Cluster is cached on HDD
-#define LOCAL_PERM 0x8 // Cluster is on HDD.
+enum {
+ BOTH = 0x0, // Cluster is on both CDs
+ CD1 = 0x1, // Cluster is on CD1 only
+ CD2 = 0x2, // Cluster is on CD2 only
+ LOCAL_CACHE = 0x4, // Cluster is cached on HDD
+ LOCAL_PERM = 0x8 // Cluster is on HDD.
+};
#if !defined(__GNUC__)
#pragma START_PACK_STRUCTS
@@ -83,9 +85,7 @@ struct _cd_inf {
#pragma END_PACK_STRUCTS
#endif
-// FIXME: Should init() / exit() be moved to constructor / destructor instead?
-
-void ResourceManager::init(void) {
+ResourceManager::ResourceManager(void) {
// We read in the resource info which tells us the names of the
// resource cluster files ultimately, although there might be groups
// within the clusters at this point it makes no difference. We only
@@ -106,7 +106,7 @@ void ResourceManager::init(void) {
end = file.size();
//get some space for the incoming resource file - soon to be trashed
- temp = memory.allocMemory(end, MEM_locked, UID_temp);
+ temp = memory->allocMemory(end, MEM_locked, UID_temp);
if (file.read(temp->ad, end) != end) {
file.close();
@@ -208,7 +208,7 @@ void ResourceManager::init(void) {
}
_resTime = 1; //cannot start at 0
- memory.freeMemory(temp); //get that memory back
+ memory->freeMemory(temp); //get that memory back
// FIXME: Is this really needed?
@@ -235,7 +235,7 @@ void ResourceManager::init(void) {
file.close();
}
-void ResourceManager::exit(void) {
+ResourceManager::~ResourceManager(void) {
// free up our mallocs
free(_resList);
free(_age);
@@ -428,11 +428,11 @@ void convertEndian(uint8 *file, uint32 len) {
}
}
-uint8 *ResourceManager::open(uint32 res) {
+uint8 *ResourceManager::openResource(uint32 res) {
// returns ad of resource. Loads if not in memory
// retains a count
// resource can be aged out of memory if count = 0
- // the resource is locked while count != 0 i.e. until a res_close is
+ // the resource is locked while count != 0 i.e. until a closeResource is
// called
File file;
@@ -528,13 +528,13 @@ uint8 *ResourceManager::open(uint32 res) {
// ok, we know the length so try and allocate the memory
// if it can't then old files will be ditched until it works
- _resList[res] = memory.allocMemory(len, MEM_locked, res);
+ _resList[res] = memory->allocMemory(len, MEM_locked, res);
// now load the file
// hurray, load it in.
file.read(_resList[res]->ad, len);
- //close the cluster
+ // close the cluster
file.close();
#ifdef SCUMM_BIG_ENDIAN
@@ -553,7 +553,7 @@ uint8 *ResourceManager::open(uint32 res) {
// pass the address of the mem & lock the memory too
// might be locked already (if count > 1)
- memory.lockMemory(_resList[res]);
+ memory->lockMemory(_resList[res]);
return (uint8 *) _resList[res]->ad;
}
@@ -614,7 +614,7 @@ uint32 ResourceManager::fetchUsage(void) {
return _currentMemoryUsage;
}
-void ResourceManager::close(uint32 res) {
+void ResourceManager::closeResource(uint32 res) {
// decrements the count
// resource floats when count = 0
@@ -624,7 +624,7 @@ void ResourceManager::close(uint32 res) {
//closing but isnt open?
if (!(_count[res]))
- error("close: closing %d but it isn't open", res);
+ error("closeResource: closing %d but it isn't open", res);
//#endif
//one less has it open
@@ -633,7 +633,7 @@ void ResourceManager::close(uint32 res) {
//if noone has the file open then unlock and allow to float
if (!_count[res]) {
// pass the address of the mem
- memory.floatMemory(_resList[res]);
+ memory->floatMemory(_resList[res]);
}
}
@@ -723,7 +723,7 @@ uint32 ResourceManager::helpTheAgedOut(void) {
// trash this old resource
_age[oldest_res] = 0; // effectively gone from _resList
- memory.freeMemory(_resList[oldest_res]); // release the memory too
+ memory->freeMemory(_resList[oldest_res]); // release the memory too
return _resList[oldest_res]->size; // return bytes freed
}
@@ -745,8 +745,8 @@ void ResourceManager::examine(int res) {
else if (_resConvTable[res * 2] == 0xffff)
Debug_Printf("%d is a null & void resource number\n", res);
else {
- //open up the resource and take a look inside!
- file_header = (_standardHeader*) res_man.open(res);
+ // open up the resource and take a look inside!
+ file_header = (_standardHeader*) openResource(res);
// Debug_Printf("%d\n", file_header->fileType);
// Debug_Printf("%s\n", file_header->name);
@@ -826,7 +826,7 @@ void ResourceManager::examine(int res) {
Debug_Printf("unrecognised fileType %d\n", file_header->fileType);
break;
}
- res_man.close(res);
+ closeResource(res);
}
}
@@ -840,7 +840,7 @@ void ResourceManager::kill(int res) {
if (!_count[res]) {
if (_age[res]) {
_age[res] = 0; // effectively gone from _resList
- memory.freeMemory(_resList[res]); // release the memory too
+ memory->freeMemory(_resList[res]); // release the memory too
Debug_Printf("Trashed %d\n", res);
} else
Debug_Printf("%d not in memory\n", res);
@@ -851,7 +851,7 @@ void ResourceManager::kill(int res) {
void ResourceManager::remove(uint32 res) {
if (_age[res]) {
_age[res] = 0; // effectively gone from _resList
- memory.freeMemory(_resList[res]); // release the memory too
+ memory->freeMemory(_resList[res]); // release the memory too
debug(5, " - Trashing %d", res);
} else
debug(5, "remove(%d) not even in memory!", res);
@@ -864,16 +864,16 @@ void ResourceManager::removeAll(void) {
int j;
uint32 res;
- j = memory._baseMemBlock;
+ j = memory->_baseMemBlock;
do {
- if (memory._memList[j].uid < 65536) { // a resource
- res = memory._memList[j].uid;
+ if (memory->_memList[j].uid < 65536) { // a resource
+ res = memory->_memList[j].uid;
_age[res] = 0; // effectively gone from _resList
- memory.freeMemory(_resList[res]); // release the memory too
+ memory->freeMemory(_resList[res]); // release the memory too
}
- j = memory._memList[j].child;
+ j = memory->_memList[j].child;
} while (j != -1);
}
@@ -887,20 +887,20 @@ void ResourceManager::killAll(bool wantInfo) {
uint32 nuked = 0;
_standardHeader *header;
- j = memory._baseMemBlock;
+ j = memory->_baseMemBlock;
do {
- if (memory._memList[j].uid < 65536) { // a resource
- res = memory._memList[j].uid;
+ if (memory->_memList[j].uid < 65536) { // a resource
+ res = memory->_memList[j].uid;
// not the global vars which are assumed to be open in
// memory & not the player object!
if (res != 1 && res != CUR_PLAYER_ID) {
- header = (_standardHeader *) res_man.open(res);
- res_man.close(res);
+ header = (_standardHeader *) openResource(res);
+ closeResource(res);
_age[res] = 0; // effectively gone from _resList
- memory.freeMemory(_resList[res]); // release the memory too
+ memory->freeMemory(_resList[res]); // release the memory too
nuked++;
// if this was called from the console,
@@ -910,7 +910,7 @@ void ResourceManager::killAll(bool wantInfo) {
}
}
}
- j = memory._memList[j].child;
+ j = memory->_memList[j].child;
} while (j != -1);
// if this was called from the console
@@ -937,20 +937,20 @@ void ResourceManager::killAllObjects(bool wantInfo) {
uint32 nuked = 0;
_standardHeader *header;
- j = memory._baseMemBlock;
+ j = memory->_baseMemBlock;
do {
- if (memory._memList[j].uid < 65536) { // a resource
- res = memory._memList[j].uid;
+ if (memory->_memList[j].uid < 65536) { // a resource
+ res = memory->_memList[j].uid;
//not the global vars which are assumed to be open in
// memory & not the player object!
if (res != 1 && res != CUR_PLAYER_ID) {
- header = (_standardHeader*) res_man.open(res);
- res_man.close(res);
+ header = (_standardHeader*) openResource(res);
+ closeResource(res);
if (header->fileType == GAME_OBJECT) {
_age[res] = 0; // effectively gone from _resList
- memory.freeMemory(_resList[res]); // release the memory too
+ memory->freeMemory(_resList[res]); // release the memory too
nuked++;
// if this was called from the console
@@ -961,7 +961,7 @@ void ResourceManager::killAllObjects(bool wantInfo) {
}
}
}
- j = memory._memList[j].child;
+ j = memory->_memList[j].child;
} while (j != -1);
// if this was called from the console
@@ -981,7 +981,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
g_logic.fnStopMusic(NULL);
- Clear_fx_queue(); // stops all fx & clears the queue (James22july97)
+ g_sword2->clearFxQueue(); // stops all fx & clears the queue (James22july97)
getCd(_cdTab[newCluster] & 3);
// Kick out old cached cluster and load the new one.
@@ -1031,16 +1031,16 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
g_sword2->setLuggage(0);
uint8 *bgfile;
- bgfile = res_man.open(2950); // open the screen resource
+ bgfile = openResource(2950); // open the screen resource
g_display->initialiseBackgroundLayer(NULL);
g_display->initialiseBackgroundLayer(NULL);
- g_display->initialiseBackgroundLayer(FetchBackgroundLayer(bgfile));
+ g_display->initialiseBackgroundLayer(g_sword2->fetchBackgroundLayer(bgfile));
g_display->initialiseBackgroundLayer(NULL);
g_display->initialiseBackgroundLayer(NULL);
- g_display->setPalette(0, 256, FetchPalette(bgfile), RDPAL_FADE);
+ g_display->setPalette(0, 256, g_sword2->fetchPalette(bgfile), RDPAL_FADE);
- g_display->renderParallax(FetchBackgroundLayer(bgfile), 2);
- res_man.close(2950); // release the screen resource
+ g_display->renderParallax(g_sword2->fetchBackgroundLayer(bgfile), 2);
+ closeResource(2950); // release the screen resource
// Git rid of read-only status, if it is set.
SVM_SetFileAttributes(_resourceFiles[newCluster], FILE_ATTRIBUTE_NORMAL);
@@ -1061,7 +1061,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
uint8 *loadingBar;
_cdtEntry *cdt;
- text_spr = fontRenderer.makeTextSprite(FetchTextLine(res_man.open(2283), 8) + 2, 640, 187, g_sword2->_speechFontId);
+ text_spr = fontRenderer.makeTextSprite(g_sword2->fetchTextLine(openResource(2283), 8) + 2, 640, 187, g_sword2->_speechFontId);
frame = (_frameHeader*) text_spr->ad;
@@ -1076,12 +1076,12 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
textSprite.blend = 0;
textSprite.colourTable = 0;
- res_man.close(2283);
+ closeResource(2283);
- loadingBar = res_man.open(2951);
+ loadingBar = openResource(2951);
- frame = FetchFrameHeader(loadingBar, 0);
- cdt = FetchCdtEntry(loadingBar, 0);
+ frame = g_sword2->fetchFrameHeader(loadingBar, 0);
+ cdt = g_sword2->fetchCdtEntry(loadingBar, 0);
barSprite.x = cdt->x;
barSprite.y = cdt->y;
@@ -1094,12 +1094,12 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
barSprite.blend = 0;
barSprite.colourTable = 0;
- res_man.close(2951);
+ closeResource(2951);
- loadingBar = res_man.open(2951);
- frame = FetchFrameHeader(loadingBar, 0);
+ loadingBar = openResource(2951);
+ frame = g_sword2->fetchFrameHeader(loadingBar, 0);
barSprite.data = (uint8 *) (frame + 1);
- res_man.close(2951);
+ closeResource(2951);
int16 barX = barSprite.x;
int16 barY = barSprite.y;
@@ -1137,14 +1137,14 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
if (step == stepSize) {
step = 0;
// open the screen resource
- bgfile = res_man.open(2950);
- g_display->renderParallax(FetchBackgroundLayer(bgfile), 2);
+ bgfile = openResource(2950);
+ g_display->renderParallax(g_sword2->fetchBackgroundLayer(bgfile), 2);
// release the screen resource
- res_man.close(2950);
- loadingBar = res_man.open(2951);
- frame = FetchFrameHeader(loadingBar, fr);
+ closeResource(2950);
+ loadingBar = openResource(2951);
+ frame = g_sword2->fetchFrameHeader(loadingBar, fr);
barSprite.data = (uint8 *) (frame + 1);
- res_man.close(2951);
+ closeResource(2951);
g_display->drawSprite(&barSprite);
barSprite.x = barX;
barSprite.y = barY;
@@ -1167,7 +1167,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
inFile.close();
outFile.close();
- memory.freeMemory(text_spr);
+ memory->freeMemory(text_spr);
g_display->clearScene();
@@ -1284,9 +1284,9 @@ void ResourceManager::getCd(int cd) {
g_logic.fnStopMusic(NULL);
- textRes = res_man.open(2283);
- g_sword2->displayMsg(FetchTextLine(textRes, 5 + cd) + 2, 0);
- text_spr = fontRenderer.makeTextSprite(FetchTextLine(textRes, 5 + cd) + 2, 640, 187, g_sword2->_speechFontId);
+ textRes = openResource(2283);
+ g_sword2->displayMsg(g_sword2->fetchTextLine(textRes, 5 + cd) + 2, 0);
+ text_spr = fontRenderer.makeTextSprite(g_sword2->fetchTextLine(textRes, 5 + cd) + 2, 640, 187, g_sword2->_speechFontId);
frame = (_frameHeader*) text_spr->ad;
@@ -1304,7 +1304,7 @@ void ResourceManager::getCd(int cd) {
oldY = spriteInfo.y;
oldX = spriteInfo.x;
- res_man.close(2283);
+ closeResource(2283);
do {
if (offNetwork == 1)
@@ -1337,7 +1337,7 @@ void ResourceManager::getCd(int cd) {
spriteInfo.x = oldX;
} while (!done);
- memory.freeMemory(text_spr);
+ memory->freeMemory(text_spr);
g_sword2->removeMsg();
}
diff --git a/sword2/resman.h b/sword2/resman.h
index 27e86e294f..510f22ba5b 100644
--- a/sword2/resman.h
+++ b/sword2/resman.h
@@ -28,16 +28,16 @@ namespace Sword2 {
class ResourceManager {
public:
- void init(void); // read in the config file
- void exit(void);
+ ResourceManager(void); // read in the config file
+ ~ResourceManager(void);
// Returns ad of resource. Loads if not in memory. Retains a count.
// Resource can be aged out of memory if count = 0
// The resource is locked while count != 0
// Resource floats when count = 0
- uint8 *open(uint32 res);
- void close(uint32 res); // decrements the count
+ uint8 *openResource(uint32 res);
+ void closeResource(uint32 res); // decrements the count
// returns '0' if resource out of range or null, otherwise '1' for ok
@@ -105,7 +105,7 @@ private:
char _cdDrives[24];
};
-extern ResourceManager res_man; //declare the object global
+extern ResourceManager *res_man; // declare the object global
} // End of namespace Sword2
diff --git a/sword2/router.cpp b/sword2/router.cpp
index 997b4b4efe..9373a655fd 100644
--- a/sword2/router.cpp
+++ b/sword2/router.cpp
@@ -117,7 +117,7 @@ void Router::allocateRouteMem(void) {
if (_routeSlots[slotNo])
freeRouteMem();
- _routeSlots[slotNo] = memory.allocMemory(sizeof(_walkData) * O_WALKANIM_SIZE, MEM_locked, UID_walk_anim);
+ _routeSlots[slotNo] = memory->allocMemory(sizeof(_walkData) * O_WALKANIM_SIZE, MEM_locked, UID_walk_anim);
// 12000 bytes were used for this in Sword1 mega compacts, based on
// 20 bytes per '_walkData' frame
@@ -135,14 +135,14 @@ void Router::allocateRouteMem(void) {
_walkData* Router::lockRouteMem(void) {
uint8 slotNo = returnSlotNo(ID);
- memory.lockMemory(_routeSlots[slotNo]);
+ memory->lockMemory(_routeSlots[slotNo]);
return (_walkData *) _routeSlots[slotNo]->ad;
}
void Router::floatRouteMem(void) {
uint8 slotNo = returnSlotNo(ID);
- memory.floatMemory(_routeSlots[slotNo]);
+ memory->floatMemory(_routeSlots[slotNo]);
}
void Router::freeRouteMem(void) {
@@ -150,7 +150,7 @@ void Router::freeRouteMem(void) {
// free the mem block pointed to from this entry of _routeSlots[]
- memory.freeMemory(_routeSlots[slotNo]);
+ memory->freeMemory(_routeSlots[slotNo]);
_routeSlots[slotNo] = NULL;
}
@@ -159,7 +159,7 @@ void Router::freeAllRouteMem(void) {
if (_routeSlots[i]) {
// free the mem block pointed to from this entry of
// _routeSlots[]
- memory.freeMemory(_routeSlots[i]);
+ memory->freeMemory(_routeSlots[i]);
_routeSlots[i] = NULL;
}
}
@@ -2561,7 +2561,7 @@ void Router::loadWalkGrid(void) {
for (int i = 0; i < MAX_WALKGRIDS; i++) {
if (_walkGridList[i]) {
// open walk grid file
- fPolygrid = res_man.open(_walkGridList[i]);
+ fPolygrid = res_man->openResource(_walkGridList[i]);
fPolygrid += sizeof(_standardHeader);
memmove((uint8 *) &floorHeader, fPolygrid, sizeof(_walkGridHeader));
fPolygrid += sizeof(_walkGridHeader);
@@ -2603,7 +2603,7 @@ void Router::loadWalkGrid(void) {
}
// close walk grid file
- res_man.close(_walkGridList[i]);
+ res_man->closeResource(_walkGridList[i]);
// increment counts of total bars & nodes in whole
// walkgrid
diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp
index 8cd6575826..0e954622ed 100644
--- a/sword2/save_rest.cpp
+++ b/sword2/save_rest.cpp
@@ -50,43 +50,8 @@ namespace Sword2 {
// max length of a savegame filename, including full path
#define MAX_FILENAME_LEN 128
-static void GetPlayerStructures(void);
-static void PutPlayerStructures(void);
-
-static uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize);
-static uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize);
-
-static uint32 CalcChecksum(uint8 *buffer, uint32 size);
-
-// savegame file header
-
-typedef struct {
- // sum of all bytes in file, excluding this uint32
- uint32 checksum;
-
- // player's description of savegame
- char description[SAVE_DESCRIPTION_LEN];
-
- uint32 varLength; // length of global variables resource
- uint32 screenId; // resource id of screen file
- uint32 runListId; // resource id of run list
- uint32 feet_x; // copy of _thisScreen.feet_x
- uint32 feet_y; // copy of _thisScreen.feet_y
- uint32 music_id; // copy of 'looping_music_id'
- _object_hub player_hub; // copy of player object's object_hub structure
- Object_logic logic; // copy of player character logic structure
-
- // copy of player character graphic structure
- Object_graphic graphic;
-
- Object_mega mega; // copy of player character mega structure
-} _savegameHeader;
-
// savegame consists of header & global variables resource
-// global because easier to copy to/from player object structures
-static _savegameHeader g_header;
-
#ifdef SCUMM_BIG_ENDIAN
// Quick macro to make swapping in-place easier to write
#define SWAP32(x) x = SWAP_BYTES_32(x)
@@ -135,70 +100,70 @@ static void convertHeaderEndian(_savegameHeader &header) {
// SAVE GAME
-uint32 SaveGame(uint16 slotNo, uint8 *desc) {
+uint32 Sword2Engine::saveGame(uint16 slotNo, uint8 *desc) {
mem *saveBufferMem;
uint32 bufferSize;
uint32 errorCode;
// allocate the savegame buffer
- bufferSize = FindBufferSize();
- saveBufferMem = memory.allocMemory(bufferSize, MEM_locked, UID_savegame_buffer);
+ bufferSize = findBufferSize();
+ saveBufferMem = memory->allocMemory(bufferSize, MEM_locked, UID_savegame_buffer);
- FillSaveBuffer(saveBufferMem, bufferSize, desc);
+ fillSaveBuffer(saveBufferMem, bufferSize, desc);
// save it (hopefully no longer platform-specific)
// save the buffer
- errorCode = SaveData(slotNo, saveBufferMem->ad, bufferSize);
+ errorCode = saveData(slotNo, saveBufferMem->ad, bufferSize);
// free the buffer
- memory.freeMemory(saveBufferMem);
+ memory->freeMemory(saveBufferMem);
return errorCode;
}
// calculate size of required savegame buffer
-uint32 FindBufferSize(void) {
+uint32 Sword2Engine::findBufferSize(void) {
// size of savegame header + size of global variables
- return sizeof(g_header) + res_man.fetchLen(1);
+ return sizeof(g_header) + res_man->fetchLen(1);
}
-void FillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) {
- uint8 *varsRes;
+void Sword2Engine::fillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) {
+ uint8 *varsRes;
// set up the g_header
// 'checksum' gets filled in last of all
// player's description of savegame
- sprintf(g_header.description, "%s", (char*) desc);
+ strcpy(g_header.description, (char *) desc);
// length of global variables resource
- g_header.varLength = res_man.fetchLen(1);
+ g_header.varLength = res_man->fetchLen(1);
// resource id of current screen file
- g_header.screenId = g_sword2->_thisScreen.background_layer_id;
+ g_header.screenId = _thisScreen.background_layer_id;
// resource id of current run-list
g_header.runListId = g_logic.getRunList();
// those scroll position control things
- g_header.feet_x = g_sword2->_thisScreen.feet_x;
- g_header.feet_y = g_sword2->_thisScreen.feet_y;
+ g_header.feet_x = _thisScreen.feet_x;
+ g_header.feet_y = _thisScreen.feet_y;
// id of currently looping music (or zero)
- g_header.music_id = looping_music_id;
+ g_header.music_id = _loopingMusicId;
// object hub
- memcpy(&g_header.player_hub, res_man.open(CUR_PLAYER_ID) + sizeof(_standardHeader), sizeof(_object_hub));
- res_man.close(CUR_PLAYER_ID);
+ memcpy(&g_header.player_hub, res_man->openResource(CUR_PLAYER_ID) + sizeof(_standardHeader), sizeof(_object_hub));
+ res_man->closeResource(CUR_PLAYER_ID);
// logic, graphic & mega structures
// copy the 4 essential player object structures into the header
- GetPlayerStructures();
+ getPlayerStructures();
// copy the header to the buffer
@@ -212,7 +177,7 @@ void FillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) {
// copy the global variables to the buffer
// open variables resource
- varsRes = res_man.open(1);
+ varsRes = res_man->openResource(1);
// copy that to the buffer, following the header
memcpy(buffer->ad + sizeof(g_header), varsRes, FROM_LE_32(g_header.varLength));
@@ -226,24 +191,24 @@ void FillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) {
#endif
// close variables resource
- res_man.close(1);
+ res_man->closeResource(1);
- // set the checksum & copy that to the buffer (James05aug97)
+ // set the checksum & copy that to the buffer
- g_header.checksum = TO_LE_32(CalcChecksum((buffer->ad) + sizeof(g_header.checksum), size - sizeof(g_header.checksum)));
+ g_header.checksum = TO_LE_32(calcChecksum((buffer->ad) + sizeof(g_header.checksum), size - sizeof(g_header.checksum)));
memcpy(buffer->ad, &g_header.checksum, sizeof(g_header.checksum));
}
-uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
+uint32 Sword2Engine::saveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
char saveFileName[MAX_FILENAME_LEN];
uint32 itemsWritten;
SaveFile *out;
SaveFileManager *mgr = g_system->get_savefile_manager();
// construct filename
- sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo);
+ sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
- if (!(out = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), true))) {
+ if (!(out = mgr->open_savefile(saveFileName, getSavePath(), true))) {
// error: couldn't open file
delete mgr;
return SR_ERR_FILEOPEN;
@@ -265,48 +230,48 @@ uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
// RESTORE GAME
-uint32 RestoreGame(uint16 slotNo) {
+uint32 Sword2Engine::restoreGame(uint16 slotNo) {
mem *saveBufferMem;
uint32 bufferSize;
uint32 errorCode;
// allocate the savegame buffer
- bufferSize = FindBufferSize();
- saveBufferMem = memory.allocMemory(bufferSize, MEM_locked, UID_savegame_buffer);
+ bufferSize = findBufferSize();
+ saveBufferMem = memory->allocMemory(bufferSize, MEM_locked, UID_savegame_buffer);
// read the savegame file into our buffer
// load savegame into buffer
- errorCode = RestoreData(slotNo, saveBufferMem->ad, bufferSize);
+ errorCode = restoreData(slotNo, saveBufferMem->ad, bufferSize);
// if it was read in successfully, then restore the game from the
// buffer & free the buffer
if (errorCode == SR_OK) {
- errorCode = RestoreFromBuffer(saveBufferMem, bufferSize);
+ errorCode = restoreFromBuffer(saveBufferMem, bufferSize);
// Note that the buffer has been freed inside
- // RestoreFromBuffer, in order to clear it from memory before
+ // restoreFromBuffer, in order to clear it from memory before
// loading in the new screen & runlist
} else {
- // because RestoreFromBuffer would have freed it
- memory.freeMemory(saveBufferMem);
+ // because restoreFromBuffer would have freed it
+ memory->freeMemory(saveBufferMem);
}
return errorCode;
}
-uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
+uint32 Sword2Engine::restoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
char saveFileName[MAX_FILENAME_LEN];
SaveFile *in;
SaveFileManager *mgr = g_system->get_savefile_manager();
uint32 itemsRead;
// construct filename
- sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo);
+ sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
- if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
+ if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
// error: couldn't open file
delete mgr;
return SR_ERR_FILEOPEN;
@@ -339,7 +304,7 @@ uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
}
}
-uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
+uint32 Sword2Engine::restoreFromBuffer(mem *buffer, uint32 size) {
uint8 *varsRes;
int32 pars[2];
@@ -351,10 +316,9 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
#endif
// Calc checksum & check that aginst the value stored in the header
- // (James05aug97)
- if (g_header.checksum != CalcChecksum(buffer->ad + sizeof(g_header.checksum), size - sizeof(g_header.checksum))) {
- memory.freeMemory(buffer);
+ if (g_header.checksum != calcChecksum(buffer->ad + sizeof(g_header.checksum), size - sizeof(g_header.checksum))) {
+ memory->freeMemory(buffer);
// error: incompatible save-data - can't use!
return SR_ERR_INCOMPATIBLE;
@@ -368,8 +332,8 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
// shorter than the current expected length
// if header contradicts actual current size of global variables
- if (g_header.varLength != res_man.fetchLen(1)) {
- memory.freeMemory(buffer);
+ if (g_header.varLength != res_man->fetchLen(1)) {
+ memory->freeMemory(buffer);
// error: incompatible save-data - can't use!
return SR_ERR_INCOMPATIBLE;
@@ -379,7 +343,7 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
// trash all resources from memory except player object & global
// variables
- res_man.killAll(false);
+ res_man->killAll(false);
// clean out the system kill list (no more objects to kill)
g_logic.resetKillList();
@@ -387,17 +351,17 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
// get player character data from savegame buffer
// object hub is just after the standard header
- memcpy(res_man.open(CUR_PLAYER_ID) + sizeof(_standardHeader), &g_header.player_hub, sizeof(_object_hub));
+ memcpy(res_man->openResource(CUR_PLAYER_ID) + sizeof(_standardHeader), &g_header.player_hub, sizeof(_object_hub));
- res_man.close(CUR_PLAYER_ID);
+ res_man->closeResource(CUR_PLAYER_ID);
// fill in the 4 essential player object structures from the header
- PutPlayerStructures();
+ putPlayerStructures();
// get variables resource from the savegame buffer
// open variables resource
- varsRes = res_man.open(1);
+ varsRes = res_man->openResource(1);
// copy that to the buffer, following the header
memcpy(varsRes, buffer->ad + sizeof(g_header), g_header.varLength );
@@ -411,11 +375,11 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
#endif
// close variables resource
- res_man.close(1);
+ res_man->closeResource(1);
// free it now, rather than in RestoreGame, to unblock memory before
// new screen & runlist loaded
- memory.freeMemory(buffer);
+ memory->freeMemory(buffer);
pars[0] = g_header.screenId;
pars[1] = 1;
@@ -423,13 +387,13 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
// So palette not restored immediately after control panel - we want to
// fade up instead!
- g_sword2->_thisScreen.new_palette = 99;
+ _thisScreen.new_palette = 99;
// these need setting after the defaults get set in fnInitBackground
// remember that these can change through the game, so need saving &
// restoring too
- g_sword2->_thisScreen.feet_x = g_header.feet_x;
- g_sword2->_thisScreen.feet_y = g_header.feet_y;
+ _thisScreen.feet_x = g_header.feet_x;
+ _thisScreen.feet_y = g_header.feet_y;
// start the new run list
g_logic.expressChangeSession(g_header.runListId);
@@ -438,19 +402,19 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
// not occur when screen first draws after returning from restore panel
// set '_thisScreen's record of player position
- // - ready for Set_scrolling()
+ // - ready for setScrolling()
- g_sword2->_thisScreen.player_feet_x = g_header.mega.feet_x;
- g_sword2->_thisScreen.player_feet_y = g_header.mega.feet_y;
+ _thisScreen.player_feet_x = g_header.mega.feet_x;
+ _thisScreen.player_feet_y = g_header.mega.feet_y;
// if this screen is wide, recompute the scroll offsets now
- if (g_sword2->_thisScreen.scroll_flag)
- Set_scrolling();
+ if (_thisScreen.scroll_flag)
+ setScrolling();
// Any music required will be started after we've returned from
// Restore_control() - see System_menu() in mouse.cpp!
- looping_music_id = g_header.music_id;
+ _loopingMusicId = g_header.music_id;
// Write to walkthrough file (zebug0.txt)
@@ -462,16 +426,16 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
// GetSaveDescription - PC version...
-uint32 GetSaveDescription(uint16 slotNo, uint8 *description) {
+uint32 Sword2Engine::getSaveDescription(uint16 slotNo, uint8 *description) {
char saveFileName[MAX_FILENAME_LEN];
_savegameHeader dummy;
SaveFile *in;
SaveFileManager *mgr = g_system->get_savefile_manager();
// construct filename
- sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo);
+ sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
- if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
+ if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
// error: couldn't open file
delete mgr;
return SR_ERR_FILEOPEN;
@@ -482,19 +446,19 @@ uint32 GetSaveDescription(uint16 slotNo, uint8 *description) {
delete in;
delete mgr;
- sprintf((char*) description, dummy.description);
+ strcpy((char *) description, dummy.description);
return SR_OK;
}
-bool SaveExists(uint16 slotNo) {
+bool Sword2Engine::saveExists(uint16 slotNo) {
char saveFileName[MAX_FILENAME_LEN];
SaveFileManager *mgr = g_system->get_savefile_manager();
SaveFile *in;
// construct filename
- sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo);
+ sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
- if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
+ if (!(in = mgr->open_savefile(saveFileName, getSavePath(), false))) {
delete mgr;
return false;
}
@@ -505,7 +469,7 @@ bool SaveExists(uint16 slotNo) {
return true;
}
-void GetPlayerStructures(void) {
+void Sword2Engine::getPlayerStructures(void) {
// request the player object structures which need saving
// script no. 7 - 'george_savedata_request' calls fnPassPlayerSaveData
@@ -514,17 +478,17 @@ void GetPlayerStructures(void) {
char *raw_script_ad;
_standardHeader *head;
- head = (_standardHeader*) res_man.open(CUR_PLAYER_ID);
+ head = (_standardHeader*) res_man->openResource(CUR_PLAYER_ID);
if (head->fileType != GAME_OBJECT)
error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
raw_script_ad = (char *) head;
g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
- res_man.close(CUR_PLAYER_ID);
+ res_man->closeResource(CUR_PLAYER_ID);
}
-void PutPlayerStructures(void) {
+void Sword2Engine::putPlayerStructures(void) {
// fill out the player object structures from the savegame structures
// also run the appropriate scripts to set up george's anim tables &
// walkdata, and nico's anim tables
@@ -533,7 +497,7 @@ void PutPlayerStructures(void) {
char *raw_script_ad;
_standardHeader *head;
- head = (_standardHeader*) res_man.open(CUR_PLAYER_ID);
+ head = (_standardHeader*) res_man->openResource(CUR_PLAYER_ID);
if (head->fileType != GAME_OBJECT)
error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
@@ -571,7 +535,16 @@ void PutPlayerStructures(void) {
}
g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
- res_man.close(CUR_PLAYER_ID);
+ res_man->closeResource(CUR_PLAYER_ID);
+}
+
+uint32 Sword2Engine::calcChecksum(uint8 *buffer, uint32 size) {
+ uint32 total = 0;
+
+ for (uint32 pos = 0; pos < size; pos++)
+ total += buffer[pos];
+
+ return total;
}
int32 Logic::fnPassPlayerSaveData(int32 *params) {
@@ -587,9 +560,9 @@ int32 Logic::fnPassPlayerSaveData(int32 *params) {
// copy from player object to savegame header
- memcpy(&g_header.logic, (uint8 *) params[0], sizeof(Object_logic));
- memcpy(&g_header.graphic, (uint8 *) params[1], sizeof(Object_graphic));
- memcpy(&g_header.mega, (uint8 *) params[2], sizeof(Object_mega));
+ memcpy(&g_sword2->g_header.logic, (uint8 *) params[0], sizeof(Object_logic));
+ memcpy(&g_sword2->g_header.graphic, (uint8 *) params[1], sizeof(Object_graphic));
+ memcpy(&g_sword2->g_header.mega, (uint8 *) params[2], sizeof(Object_mega));
// makes no odds
return IR_CONT;
@@ -611,9 +584,9 @@ int32 Logic::fnGetPlayerSaveData(int32 *params) {
// copy from savegame header to player object
- memcpy((uint8 *) ob_logic, &g_header.logic, sizeof(Object_logic));
- memcpy((uint8 *) ob_graphic, &g_header.graphic, sizeof(Object_graphic));
- memcpy((uint8 *) ob_mega, &g_header.mega, sizeof(Object_mega));
+ memcpy((uint8 *) ob_logic, &g_sword2->g_header.logic, sizeof(Object_logic));
+ memcpy((uint8 *) ob_graphic, &g_sword2->g_header.graphic, sizeof(Object_graphic));
+ memcpy((uint8 *) ob_mega, &g_sword2->g_header.mega, sizeof(Object_mega));
// any walk-data must be cleared - the player will be set to stand if
// he was walking when saved
@@ -643,13 +616,4 @@ int32 Logic::fnGetPlayerSaveData(int32 *params) {
return IR_CONT;
}
-uint32 CalcChecksum(uint8 *buffer, uint32 size) {
- uint32 total = 0;
-
- for (uint32 pos = 0; pos < size; pos++)
- total += buffer[pos];
-
- return total;
-}
-
} // End of namespace Sword2
diff --git a/sword2/save_rest.h b/sword2/save_rest.h
index 9f60c3f7e7..b8e1324cd9 100644
--- a/sword2/save_rest.h
+++ b/sword2/save_rest.h
@@ -26,14 +26,6 @@ namespace Sword2 {
#define SAVE_DESCRIPTION_LEN 64
-uint32 SaveGame(uint16 slotNo, uint8 *description);
-uint32 RestoreGame(uint16 slotNo);
-uint32 GetSaveDescription(uint16 slotNo, uint8 *description);
-bool SaveExists(uint16 slotNo);
-void FillSaveBuffer(mem *buffer, uint32 size, uint8 *desc);
-uint32 RestoreFromBuffer(mem *buffer, uint32 size);
-uint32 FindBufferSize(void);
-
// Save & Restore error codes
#define SR_OK 0x00000000 // No worries
diff --git a/sword2/scroll.cpp b/sword2/scroll.cpp
index 3ae0a82aa2..ec64ca2361 100644
--- a/sword2/scroll.cpp
+++ b/sword2/scroll.cpp
@@ -33,10 +33,7 @@ namespace Sword2 {
// max no of pixel allowed to scroll per cycle
#define MAX_SCROLL_DISTANCE 8
-// used to be a define, but now it's flexible (see new functions below)
-uint8 scroll_fraction = 16;
-
-void Set_scrolling(void) {
+void Sword2Engine::setScrolling(void) {
// normally we aim to get George's feet at (320,250) from top left
// of screen window
// feet_x = 128 + 320
@@ -53,51 +50,51 @@ void Set_scrolling(void) {
// if the scroll offsets are being forced in script
if (SCROLL_X || SCROLL_Y) {
// ensure not too far right
- if (g_sword2->_thisScreen.max_scroll_offset_x > SCROLL_X)
- g_sword2->_thisScreen.scroll_offset_x = SCROLL_X;
+ if (_thisScreen.max_scroll_offset_x > SCROLL_X)
+ _thisScreen.scroll_offset_x = SCROLL_X;
else
- g_sword2->_thisScreen.scroll_offset_x = g_sword2->_thisScreen.max_scroll_offset_x;
+ _thisScreen.scroll_offset_x = _thisScreen.max_scroll_offset_x;
// ensure not too far down
- if (g_sword2->_thisScreen.max_scroll_offset_y > SCROLL_Y)
- g_sword2->_thisScreen.scroll_offset_y = SCROLL_Y;
+ if (_thisScreen.max_scroll_offset_y > SCROLL_Y)
+ _thisScreen.scroll_offset_y = SCROLL_Y;
else
- g_sword2->_thisScreen.scroll_offset_y = g_sword2->_thisScreen.max_scroll_offset_y;
+ _thisScreen.scroll_offset_y = _thisScreen.max_scroll_offset_y;
} else {
// George's offset from the centre - the desired position
// for him
- offset_x = g_sword2->_thisScreen.player_feet_x - g_sword2->_thisScreen.feet_x;
- offset_y = g_sword2->_thisScreen.player_feet_y - g_sword2->_thisScreen.feet_y;
+ offset_x = _thisScreen.player_feet_x - _thisScreen.feet_x;
+ offset_y = _thisScreen.player_feet_y - _thisScreen.feet_y;
// prevent scrolling too far left/right/up/down
if (offset_x < 0)
offset_x = 0;
- else if ((uint32) offset_x > g_sword2->_thisScreen.max_scroll_offset_x)
- offset_x = g_sword2->_thisScreen.max_scroll_offset_x;
+ else if ((uint32) offset_x > _thisScreen.max_scroll_offset_x)
+ offset_x = _thisScreen.max_scroll_offset_x;
if (offset_y < 0)
offset_y = 0;
- else if ((uint32) offset_y > g_sword2->_thisScreen.max_scroll_offset_y)
- offset_y = g_sword2->_thisScreen.max_scroll_offset_y;
+ else if ((uint32) offset_y > _thisScreen.max_scroll_offset_y)
+ offset_y = _thisScreen.max_scroll_offset_y;
// first time on this screen - need absolute scroll
// immediately!
- if (g_sword2->_thisScreen.scroll_flag == 2) {
+ if (_thisScreen.scroll_flag == 2) {
debug(5, "init scroll");
- g_sword2->_thisScreen.scroll_offset_x = offset_x;
- g_sword2->_thisScreen.scroll_offset_y = offset_y;
- g_sword2->_thisScreen.scroll_flag = 1;
+ _thisScreen.scroll_offset_x = offset_x;
+ _thisScreen.scroll_offset_y = offset_y;
+ _thisScreen.scroll_flag = 1;
} else {
// catch up with required scroll offsets - speed
// depending on distance to catch up (dx and dy) &
// 'SCROLL_FRACTION' used, but limit to certain
// number of pixels per cycle (MAX_SCROLL_DISTANCE)
- dx = g_sword2->_thisScreen.scroll_offset_x - offset_x;
- dy = g_sword2->_thisScreen.scroll_offset_y - offset_y;
+ dx = _thisScreen.scroll_offset_x - offset_x;
+ dy = _thisScreen.scroll_offset_y - offset_y;
// current scroll_offset_x is less than the required
// value
@@ -111,39 +108,39 @@ void Set_scrolling(void) {
// NB. dx is -ve, so we subtract
// dx / SCROLL_FRACTION
- scroll_distance_x = 1 - dx / scroll_fraction;
+ scroll_distance_x = 1 - dx / _scrollFraction;
if (scroll_distance_x > MAX_SCROLL_DISTANCE)
scroll_distance_x = MAX_SCROLL_DISTANCE;
- g_sword2->_thisScreen.scroll_offset_x += scroll_distance_x;
+ _thisScreen.scroll_offset_x += scroll_distance_x;
} else if (dx > 0) {
// current scroll_offset_x is greater than
// the required value
// => dec by (fraction of the differnce)
- scroll_distance_x = 1 + dx / scroll_fraction;
+ scroll_distance_x = 1 + dx / _scrollFraction;
if (scroll_distance_x > MAX_SCROLL_DISTANCE)
scroll_distance_x = MAX_SCROLL_DISTANCE;
- g_sword2->_thisScreen.scroll_offset_x -= scroll_distance_x;
+ _thisScreen.scroll_offset_x -= scroll_distance_x;
}
if (dy < 0) {
- scroll_distance_y = 1 - dy / scroll_fraction;
+ scroll_distance_y = 1 - dy / _scrollFraction;
if (scroll_distance_y > MAX_SCROLL_DISTANCE)
scroll_distance_y = MAX_SCROLL_DISTANCE;
- g_sword2->_thisScreen.scroll_offset_y += scroll_distance_y;
+ _thisScreen.scroll_offset_y += scroll_distance_y;
} else if (dy > 0) {
- scroll_distance_y = 1 + dy / scroll_fraction;
+ scroll_distance_y = 1 + dy / _scrollFraction;
if (scroll_distance_y > MAX_SCROLL_DISTANCE)
scroll_distance_y = MAX_SCROLL_DISTANCE;
- g_sword2->_thisScreen.scroll_offset_y -= scroll_distance_y;
+ _thisScreen.scroll_offset_y -= scroll_distance_y;
}
}
}
@@ -173,14 +170,14 @@ int32 Logic::fnSetScrollCoordinate(int32 *params) {
int32 Logic::fnSetScrollSpeedNormal(int32 *params) {
// params: none
- scroll_fraction = 16;
+ g_sword2->_scrollFraction = 16;
return IR_CONT;
}
int32 Logic::fnSetScrollSpeedSlow(int32 *params) {
// params: none
- scroll_fraction = 32;
+ g_sword2->_scrollFraction = 32;
return IR_CONT;
}
diff --git a/sword2/scroll.h b/sword2/scroll.h
index 44d26f718e..6b776a424b 100644
--- a/sword2/scroll.h
+++ b/sword2/scroll.h
@@ -23,9 +23,6 @@
#define _SCROLL
namespace Sword2 {
-
-void Set_scrolling(void);
-
} // End of namespace Sword2
#endif
diff --git a/sword2/sound.cpp b/sword2/sound.cpp
index 21128b3450..a1437d4191 100644
--- a/sword2/sound.cpp
+++ b/sword2/sound.cpp
@@ -33,99 +33,80 @@
#include "sword2/defs.h" // for RESULT
#include "sword2/interpreter.h"
#include "sword2/logic.h"
-#include "sword2/protocol.h" // for FetchObjectName() for debugging fnPlayFx
+#include "sword2/protocol.h" // for fetchObjectName() for debugging fnPlayFx
#include "sword2/resman.h"
#include "sword2/sound.h"
#include "sword2/sword2.h"
namespace Sword2 {
-typedef struct {
- uint32 resource; // resource id of sample
- uint32 fetchId; // Id of resource in PSX CD queue. :)
- uint16 delay; // cycles to wait before playing (or 'random chance' if FX_RANDOM)
- uint8 volume; // 0..16
- int8 pan; // -16..16
- uint8 type; // FX_SPOT, FX_RANDOM or FX_LOOP
-} _fxq_entry;
-
-// max number of fx in queue at once [DO NOT EXCEED 255]
-#define FXQ_LENGTH 32
-
-static _fxq_entry fxq[FXQ_LENGTH];
-
-// used to store id of tunes that loop, for save & restore
-uint32 looping_music_id = 0;
-
-void Trigger_fx(uint8 j);
-
// initialise the fxq by clearing all the entries
-void Init_fx_queue(void) {
- for (int j = 0; j < FXQ_LENGTH; j++) {
- fxq[j].resource = 0; // 0 resource means 'empty' slot
- fxq[j].fetchId = 0; // Not being fetched.
+void Sword2Engine::initFxQueue(void) {
+ for (int i = 0; i < FXQ_LENGTH; i++) {
+ _fxQueue[i].resource = 0; // 0 resource means 'empty' slot
+ _fxQueue[i].fetchId = 0; // Not being fetched.
}
}
-// process the fxq once every game cycle
+// process the fx queue once every game cycle
-void Process_fx_queue(void) {
- for (int j = 0; j < FXQ_LENGTH; j++) {
- if (!fxq[j].resource)
+void Sword2Engine::processFxQueue(void) {
+ for (int i = 0; i < FXQ_LENGTH; i++) {
+ if (!_fxQueue[i].resource)
continue;
- switch (fxq[j].type) {
+ switch (_fxQueue[i].type) {
case FX_RANDOM:
// 1 in 'delay' chance of this fx occurring
- if (g_sword2->_rnd.getRandomNumber(fxq[j].delay) == 0)
- Trigger_fx(j);
+ if (_rnd.getRandomNumber(_fxQueue[i].delay) == 0)
+ triggerFx(i);
break;
case FX_SPOT:
- if (fxq[j].delay)
- fxq[j].delay--;
+ if (_fxQueue[i].delay)
+ _fxQueue[i].delay--;
else {
- Trigger_fx(j);
- fxq[j].type = FX_SPOT2;
+ triggerFx(i);
+ _fxQueue[i].type = FX_SPOT2;
}
break;
case FX_SPOT2:
// Once the Fx has finished remove it from the queue.
- if (g_sound->isFxOpen(j + 1))
- fxq[j].resource = 0;
+ if (g_sound->isFxOpen(i + 1))
+ _fxQueue[i].resource = 0;
break;
}
}
}
-// called from Process_fx_queue only
+// called from processFxQueue only
-void Trigger_fx(uint8 j) {
+void Sword2Engine::triggerFx(uint8 j) {
uint8 *data;
int32 id;
uint32 rv;
id = (uint32) j + 1; // because 0 is not a valid id
- if (fxq[j].type == FX_SPOT) {
+ if (_fxQueue[j].type == FX_SPOT) {
// load in the sample
- data = res_man.open(fxq[j].resource);
+ data = res_man->openResource(_fxQueue[j].resource);
data += sizeof(_standardHeader);
// wav data gets copied to sound memory
- rv = g_sound->playFx(id, data, fxq[j].volume, fxq[j].pan, RDSE_FXSPOT);
+ rv = g_sound->playFx(id, data, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT);
// release the sample
- res_man.close(fxq[j].resource);
+ res_man->closeResource(_fxQueue[j].resource);
} else {
// random & looped fx are already loaded into sound memory
// by fnPlayFx()
// - to be referenced by 'j', so pass NULL data
- if (fxq[j].type == FX_RANDOM) {
+ if (_fxQueue[j].type == FX_RANDOM) {
// Not looped
- rv = g_sound->playFx(id, NULL, fxq[j].volume, fxq[j].pan, RDSE_FXSPOT);
+ rv = g_sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT);
} else {
// Looped
- rv = g_sound->playFx(id, NULL, fxq[j].volume, fxq[j].pan, RDSE_FXLOOP);
+ rv = g_sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXLOOP);
}
}
@@ -133,6 +114,33 @@ void Trigger_fx(uint8 j) {
debug(5, "SFX ERROR: playFx() returned %.8x", rv);
}
+// Stops all looped & random fx and clears the entire queue
+
+void Sword2Engine::clearFxQueue(void) {
+ // stop all fx & remove the samples from sound memory
+ g_sound->clearAllFx();
+
+ // clean out the queue
+ initFxQueue();
+}
+
+void Sword2Engine::killMusic(void) {
+ _loopingMusicId = 0; // clear the 'looping' flag
+ g_sound->stopMusic();
+}
+
+void Sword2Engine::pauseAllSound(void) {
+ g_sound->pauseMusic();
+ g_sound->pauseSpeech();
+ g_sound->pauseFx();
+}
+
+void Sword2Engine::unpauseAllSound(void) {
+ g_sound->unpauseMusic();
+ g_sound->unpauseSpeech();
+ g_sound->unpauseFx();
+}
+
// called from script only
int32 Logic::fnPlayFx(int32 *params) {
@@ -177,34 +185,34 @@ int32 Logic::fnPlayFx(int32 *params) {
strcpy(type, "INVALID");
}
- debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", FetchObjectName(params[0]), params[3], params[4], params[2], type);
+ debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", g_sword2->fetchObjectName(params[0]), params[3], params[4], params[2], type);
}
- while (j < FXQ_LENGTH && fxq[j].resource != 0)
+ while (j < FXQ_LENGTH && g_sword2->_fxQueue[j].resource != 0)
j++;
if (j == FXQ_LENGTH)
return IR_CONT;
- fxq[j].resource = params[0]; // wav resource id
- fxq[j].type = params[1]; // FX_SPOT, FX_LOOP or FX_RANDOM
+ g_sword2->_fxQueue[j].resource = params[0]; // wav resource id
+ g_sword2->_fxQueue[j].type = params[1]; // FX_SPOT, FX_LOOP or FX_RANDOM
- if (fxq[j].type == FX_RANDOM) {
+ if (g_sword2->_fxQueue[j].type == FX_RANDOM) {
// 'delay' param is the intended average no. seconds between
// playing this effect
- fxq[j].delay = params[2] * 12;
+ g_sword2->_fxQueue[j].delay = params[2] * 12;
} else {
// FX_SPOT or FX_LOOP:
// 'delay' is no. frames to wait before playing
- fxq[j].delay = params[2];
+ g_sword2->_fxQueue[j].delay = params[2];
}
- fxq[j].volume = params[3]; // 0..16
- fxq[j].pan = params[4]; // -16..16
+ g_sword2->_fxQueue[j].volume = params[3]; // 0..16
+ g_sword2->_fxQueue[j].pan = params[4]; // -16..16
- if (fxq[j].type == FX_SPOT) {
+ if (g_sword2->_fxQueue[j].type == FX_SPOT) {
// "pre-load" the sample; this gets it into memory
- data = res_man.open(fxq[j].resource);
+ data = res_man->openResource(g_sword2->_fxQueue[j].resource);
#ifdef _SWORD2_DEBUG
header = (_standardHeader*) data;
@@ -213,14 +221,14 @@ int32 Logic::fnPlayFx(int32 *params) {
#endif
// but then releases it to "age" out if the space is needed
- res_man.close(fxq[j].resource);
+ res_man->closeResource(g_sword2->_fxQueue[j].resource);
} else {
// random & looped fx
id = (uint32) j + 1; // because 0 is not a valid id
// load in the sample
- data = res_man.open(fxq[j].resource);
+ data = res_man->openResource(g_sword2->_fxQueue[j].resource);
#ifdef _SWORD2_DEBUG
header = (_standardHeader*)data;
@@ -237,13 +245,13 @@ int32 Logic::fnPlayFx(int32 *params) {
debug(5, "SFX ERROR: openFx() returned %.8x", rv);
// release the sample
- res_man.close(fxq[j].resource);
+ res_man->closeResource(g_sword2->_fxQueue[j].resource);
}
- if (fxq[j].type == FX_LOOP) {
+ if (g_sword2->_fxQueue[j].type == FX_LOOP) {
// play now, rather than in Process_fx_queue where it was
// getting played again & again!
- Trigger_fx(j);
+ g_sword2->triggerFx(j);
}
// in case we want to call fnStopFx() later, to kill this fx
@@ -299,7 +307,7 @@ int32 Logic::fnStopFx(int32 *params) {
uint32 id;
uint32 rv;
- if (fxq[j].type == FX_RANDOM || fxq[j].type == FX_LOOP) {
+ if (g_sword2->_fxQueue[j].type == FX_RANDOM || g_sword2->_fxQueue[j].type == FX_LOOP) {
id = (uint32) j + 1; // because 0 is not a valid id
// stop fx & remove sample from sound memory
@@ -310,7 +318,7 @@ int32 Logic::fnStopFx(int32 *params) {
}
// remove from queue
- fxq[j].resource = 0;
+ g_sword2->_fxQueue[j].resource = 0;
return IR_CONT;
}
@@ -322,20 +330,10 @@ int32 Logic::fnStopAllFx(int32 *params) {
// params: none
- Clear_fx_queue();
+ g_sword2->clearFxQueue();
return IR_CONT;
}
-// Stops all looped & random fx and clears the entire queue
-
-void Clear_fx_queue(void) {
- // stop all fx & remove the samples from sound memory
- g_sound->clearAllFx();
-
- // clean out the queue
- Init_fx_queue();
-}
-
int32 Logic::fnPrepareMusic(int32 *params) {
// params: 1 id of music to prepare [guess]
return IR_CONT;
@@ -357,13 +355,13 @@ int32 Logic::fnPlayMusic(int32 *params) {
// keep a note of the id, for restarting after an
// interruption to gameplay
- looping_music_id = params[0];
+ g_sword2->_loopingMusicId = params[0];
} else {
loopFlag = false;
// don't need to restart this tune after control panel or
// restore
- looping_music_id = 0;
+ g_sword2->_loopingMusicId = 0;
}
// add the appropriate file extension & play it
@@ -376,7 +374,7 @@ int32 Logic::fnPlayMusic(int32 *params) {
} else {
File f;
- sprintf(filename, "music%d.clu", res_man.whichCd());
+ sprintf(filename, "music%d.clu", res_man->whichCd());
if (f.open(filename))
f.close();
else
@@ -396,16 +394,11 @@ int32 Logic::fnPlayMusic(int32 *params) {
int32 Logic::fnStopMusic(int32 *params) {
// params: none
- looping_music_id = 0; // clear the 'looping' flag
+ g_sword2->_loopingMusicId = 0; // clear the 'looping' flag
g_sound->stopMusic();
return IR_CONT;
}
-void Kill_music(void) {
- looping_music_id = 0; // clear the 'looping' flag
- g_sound->stopMusic();
-}
-
int32 Logic::fnCheckMusicPlaying(int32 *params) {
// params: none
@@ -418,16 +411,4 @@ int32 Logic::fnCheckMusicPlaying(int32 *params) {
return IR_CONT;
}
-void PauseAllSound(void) {
- g_sound->pauseMusic();
- g_sound->pauseSpeech();
- g_sound->pauseFx();
-}
-
-void UnpauseAllSound(void) {
- g_sound->unpauseMusic();
- g_sound->unpauseSpeech();
- g_sound->unpauseFx();
-}
-
} // End of namespace Sword2
diff --git a/sword2/sound.h b/sword2/sound.h
index 66a68db660..3aaf71e777 100644
--- a/sword2/sound.h
+++ b/sword2/sound.h
@@ -30,31 +30,19 @@
#ifndef SOUND_H
#define SOUND_H
+// max number of fx in queue at once [DO NOT EXCEED 255]
+#define FXQ_LENGTH 32
+
namespace Sword2 {
// fx types
-#define FX_SPOT 0
-#define FX_LOOP 1
-#define FX_RANDOM 2
-#define FX_SPOT2 3
-
-// to be called during system initialisation
-void Init_fx_queue(void);
-
-// to be called from the main loop, once per cycle
-void Process_fx_queue(void);
-
-// stops all fx & clears the queue - eg. when leaving a location
-void Clear_fx_queue(void);
-
-void PauseAllSound(void);
-void UnpauseAllSound(void);
-
-void Kill_music(void);
-
-// used to store id of tunes that loop, for save & restore
-extern uint32 looping_music_id;
+enum {
+ FX_SPOT = 0,
+ FX_LOOP = 1,
+ FX_RANDOM = 2,
+ FX_SPOT2 = 3
+};
} // End of namespace Sword2
diff --git a/sword2/speech.cpp b/sword2/speech.cpp
index a0e7c6c370..36334a2955 100644
--- a/sword2/speech.cpp
+++ b/sword2/speech.cpp
@@ -217,9 +217,9 @@ int32 Logic::fnChoose(int32 *params) {
for (j = 0; j < 15; j++) {
if (j < IN_SUBJECT) {
debug(5, " ICON res %d for %d", subject_list[j].res, j);
- icon = res_man.open(subject_list[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP;
+ icon = res_man->openResource(subject_list[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP;
g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon);
- res_man.close(subject_list[j].res);
+ res_man->closeResource(subject_list[j].res);
} else {
//no icon here
debug(5, " NULL for %d", j);
@@ -261,18 +261,18 @@ int32 Logic::fnChoose(int32 *params) {
// change icons
for (j = 0; j < IN_SUBJECT; j++) {
- debug(5, "%s", FetchObjectName(subject_list[j].res));
+ debug(5, "%s", g_sword2->fetchObjectName(subject_list[j].res));
// change all others to grey
if (j != hit) {
- icon = res_man.open( subject_list[j].res ) + sizeof(_standardHeader);
+ icon = res_man->openResource( subject_list[j].res ) + sizeof(_standardHeader);
g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon);
- res_man.close(subject_list[j].res);
+ res_man->closeResource(subject_list[j].res);
}
}
- debug(5, "Selected: %s", FetchObjectName(subject_list[hit].res));
+ debug(5, "Selected: %s", g_sword2->fetchObjectName(subject_list[hit].res));
// this is our looping flag
choosing = 0;
@@ -360,7 +360,7 @@ int32 Logic::fnTheyDo(int32 *params) {
int32 target = params[0];
// request status of target
- head = (_standardHeader*) res_man.open(target);
+ head = (_standardHeader*) res_man->openResource(target);
if (head->fileType != GAME_OBJECT)
error("fnTheyDo %d not an object", target);
@@ -369,7 +369,7 @@ int32 Logic::fnTheyDo(int32 *params) {
// call the base script - this is the graphic/mouse service call
runScript(raw_script_ad, raw_script_ad, &null_pc);
- res_man.close(target);
+ res_man->closeResource(target);
// result is 1 for waiting, 0 for busy
@@ -422,7 +422,7 @@ int32 Logic::fnTheyDoWeWait(int32 *params) {
// ok, see if the target is busy - we must request this info from the
// target object
- head = (_standardHeader*) res_man.open(target);
+ head = (_standardHeader*) res_man->openResource(target);
if (head->fileType != GAME_OBJECT)
error("fnTheyDoWeWait %d not an object", target);
@@ -431,7 +431,7 @@ int32 Logic::fnTheyDoWeWait(int32 *params) {
// call the base script - this is the graphic/mouse service call
runScript(raw_script_ad, raw_script_ad, &null_pc);
- res_man.close(target);
+ res_man->closeResource(target);
ob_logic = (Object_logic *) params[0];
@@ -502,7 +502,7 @@ int32 Logic::fnWeWait(int32 *params) {
int32 target = params[0];
// request status of target
- head = (_standardHeader*) res_man.open(target);
+ head = (_standardHeader*) res_man->openResource(target);
if (head->fileType != GAME_OBJECT)
error("fnWeWait: %d not an object", target);
@@ -511,7 +511,7 @@ int32 Logic::fnWeWait(int32 *params) {
// call the base script - this is the graphic/mouse service call
runScript(raw_script_ad, raw_script_ad, &null_pc);
- res_man.close(target);
+ res_man->closeResource(target);
// result is 1 for waiting, 0 for busy
@@ -550,7 +550,7 @@ int32 Logic::fnTimedWait(int32 *params) {
ob_logic->looping = params[2]; //first time in
// request status of target
- head = (_standardHeader*) res_man.open(target);
+ head = (_standardHeader*) res_man->openResource(target);
if (head->fileType != GAME_OBJECT)
error("fnTimedWait %d not an object", target);
@@ -559,7 +559,7 @@ int32 Logic::fnTimedWait(int32 *params) {
// call the base script - this is the graphic/mouse service call
runScript(raw_script_ad, raw_script_ad, &null_pc);
- res_man.close(target);
+ res_man->closeResource(target);
// result is 1 for waiting, 0 for busy
@@ -993,14 +993,14 @@ int32 Logic::fnISpeak(int32 *params) {
// if the resource number is within range & it's not
// a null resource
- if (res_man.checkValid(text_res)) {
+ if (res_man->checkValid(text_res)) {
// open the resource
- head = (_standardHeader*) res_man.open(text_res);
+ head = (_standardHeader*) res_man->openResource(text_res);
if (head->fileType == TEXT_FILE) {
// if it's not an animation file
// if line number is out of range
- if (CheckTextLine((uint8*) head, local_text) == 0) {
+ if (g_sword2->checkTextLine((uint8*) head, local_text) == 0) {
// line number out of range
RESULT = 2;
}
@@ -1010,7 +1010,7 @@ int32 Logic::fnISpeak(int32 *params) {
}
// close the resource
- res_man.close(text_res);
+ res_man->closeResource(text_res);
if (RESULT)
return IR_CONT;
@@ -1030,11 +1030,11 @@ int32 Logic::fnISpeak(int32 *params) {
local_text = params[S_TEXT] & 0xffff;
// open text file & get the line
- text = FetchTextLine(res_man.open(text_res), local_text);
+ text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text);
officialTextNumber = READ_LE_UINT16(text);
// now ok to close the text file
- res_man.close(text_res);
+ res_man->closeResource(text_res);
// prevent dud lines from appearing while testing text & speech
// since these will not occur in the game anyway
@@ -1065,7 +1065,7 @@ int32 Logic::fnISpeak(int32 *params) {
if (PLAYER_ID != CUR_PLAYER_ID)
debug(5, "(%d) Nico: %s", officialTextNumber, text + 2);
else
- debug(5, "(%d) %s: %s", officialTextNumber, FetchObjectName(ID), text + 2);
+ debug(5, "(%d) %s: %s", officialTextNumber, g_sword2->fetchObjectName(ID), text + 2);
// Set up the speech animation
@@ -1169,7 +1169,7 @@ int32 Logic::fnISpeak(int32 *params) {
File fp;
- sprintf(speechFile, "speech%d.clu", res_man.whichCd());
+ sprintf(speechFile, "speech%d.clu", res_man->whichCd());
if (fp.open(speechFile))
fp.close();
@@ -1212,8 +1212,8 @@ int32 Logic::fnISpeak(int32 *params) {
ob_graphic->anim_pc++;
// open the anim file
- anim_file = res_man.open(ob_graphic->anim_resource);
- anim_head = FetchAnimHeader(anim_file);
+ anim_file = res_man->openResource(ob_graphic->anim_resource);
+ anim_head = g_sword2->fetchAnimHeader(anim_file);
if (!speech_anim_type) {
// ANIM IS TO BE LIP-SYNC'ED & REPEATING
@@ -1242,7 +1242,7 @@ int32 Logic::fnISpeak(int32 *params) {
}
// close the anim file
- res_man.close(ob_graphic->anim_resource);
+ res_man->closeResource(ob_graphic->anim_resource);
} else if (speech_anim_type) {
// Placed here so we actually display the last frame of the
// anim.
@@ -1404,15 +1404,15 @@ void LocateTalker(int32 *params) {
// build_display.cpp
// open animation file & set up the necessary pointers
- file = res_man.open(anim_id);
+ file = res_man->openResource(anim_id);
- anim_head = FetchAnimHeader(file);
+ anim_head = g_sword2->fetchAnimHeader(file);
// '0' means 1st frame
- cdt_entry = FetchCdtEntry(file, 0);
+ cdt_entry = g_sword2->fetchCdtEntry(file, 0);
// '0' means 1st frame
- frame_head = FetchFrameHeader(file, 0);
+ frame_head = g_sword2->fetchFrameHeader(file, 0);
// check if this frame has offsets ie. this is a scalable
// mega frame
@@ -1456,7 +1456,7 @@ void LocateTalker(int32 *params) {
text_y -= g_sword2->_thisScreen.scroll_offset_y;
// release the anim resource
- res_man.close(anim_id);
+ res_man->closeResource(anim_id);
}
}
@@ -1510,7 +1510,7 @@ void Form_text(int32 *params) {
local_text = params[S_TEXT] & 0xffff;
// open text file & get the line
- text = FetchTextLine(res_man.open(text_res), local_text);
+ text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text);
// 'text + 2' to skip the first 2 bytes which form the line
// reference number
@@ -1522,7 +1522,7 @@ void Form_text(int32 *params) {
g_sword2->_speechFontId, POSITION_AT_CENTRE_OF_BASE);
// now ok to close the text file
- res_man.close(text_res);
+ res_man->closeResource(text_res);
// set speech duration, in case not using wav
// no. of cycles = (no. of chars) + 30
@@ -1552,7 +1552,7 @@ void GetCorrectCdForSpeech(int32 wavId) {
// if we specifically need CD1 or CD2 (ie. it's not on both)
// then check it's there (& ask for it if it's not there)
if (cd == 1 || cd == 2)
- res_man.getCd(cd);
+ res_man->getCd(cd);
}
#endif
diff --git a/sword2/startup.cpp b/sword2/startup.cpp
index 674ff09319..3bca897a1c 100644
--- a/sword2/startup.cpp
+++ b/sword2/startup.cpp
@@ -125,17 +125,17 @@ uint32 Init_start_menu(void) {
// - need to check in case un-built sections included in
// start list
- if (res_man.checkValid(res)) {
+ if (res_man->checkValid(res)) {
debug(5, "- resource %d ok", res);
- raw_script = (char*) res_man.open(res);
+ raw_script = (char*) res_man->openResource(res);
null_pc = 0;
g_logic.runScript(raw_script, raw_script, &null_pc);
- res_man.close(res);
+ res_man->closeResource(res);
} else
debug(5, "- resource %d invalid", res);
}
- memory.freeMemory(temp);
+ memory->freeMemory(temp);
return 1;
}
@@ -197,7 +197,7 @@ void Con_start(int start) {
// restarting - stop sfx, music & speech!
- Clear_fx_queue();
+ g_sword2->clearFxQueue();
// fade out any music that is currently playing
g_logic.fnStopMusic(NULL);
@@ -212,12 +212,12 @@ void Con_start(int start) {
// remove all resources from memory, including player
// object & global variables
- res_man.removeAll();
+ res_man->removeAll();
// reopen global variables resource & send address to
// interpreter - it won't be moving
- g_logic.setGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
- res_man.close(1);
+ g_logic.setGlobalInterpreterVariables((int32 *) (res_man->openResource(1) + sizeof(_standardHeader)));
+ res_man->closeResource(1);
// free all the route memory blocks from previous game
router.freeAllRouteMem();
@@ -231,8 +231,8 @@ void Con_start(int start) {
// set the key
// Open George
- raw_data_ad = (char *) res_man.open(8);
- raw_script = (char *) res_man.open(start_list[start].start_res_id);
+ raw_data_ad = (char *) res_man->openResource(8);
+ raw_script = (char *) res_man->openResource(start_list[start].start_res_id);
// denotes script to run
null_pc = start_list[start].key & 0xffff;
@@ -240,10 +240,10 @@ void Con_start(int start) {
Debug_Printf("Running start %d\n", start);
g_logic.runScript(raw_script, raw_data_ad, &null_pc);
- res_man.close(start_list[start].start_res_id);
+ res_man->closeResource(start_list[start].start_res_id);
// Close George
- res_man.close(8);
+ res_man->closeResource(8);
// make sure thre's a mouse, in case restarting while
// mouse not available
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index 556886f3bb..a75b6c4e23 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -133,6 +133,11 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
_mixer->setVolume(256);
_mixer->setMusicVolume(256);
+ // get some falling RAM and put it in your pocket, never let it slip
+ // away
+
+ memory = new MemoryManager();
+ res_man = new ResourceManager();
g_sound = _sound = new Sound(_mixer);
g_display = _display = new Display(640, 480);
gui = new Gui();
@@ -180,6 +185,9 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
_pointerTextBlocNo = 0;
_playerActivityDelay = 0;
_realLuggageItem = 0;
+
+ // used to be a define, but now it's flexible
+ _scrollFraction = 16;
}
Sword2Engine::~Sword2Engine() {
@@ -188,6 +196,8 @@ Sword2Engine::~Sword2Engine() {
delete _display;
delete _debugger;
delete gui;
+ delete res_man;
+ delete memory;
}
void Sword2Engine::errorString(const char *buf1, char *buf2) {
@@ -212,19 +222,9 @@ int32 Sword2Engine::InitialiseGame(void) {
uint8 *file;
- // get some falling RAM and put it in your pocket, never let it slip
- // away
-
- debug(5, "CALLING: memory.init");
- memory.init();
-
- // initialise the resource manager
- debug(5, "CALLING: res_man.init");
- res_man.init();
-
// initialise global script variables
// res 1 is the globals list
- file = res_man.open(1);
+ file = res_man->openResource(1);
debug(5, "CALLING: SetGlobalInterpreterVariables");
g_logic.setGlobalInterpreterVariables((int32 * ) (file + sizeof(_standardHeader)));
@@ -234,7 +234,7 @@ int32 Sword2Engine::InitialiseGame(void) {
// DON'T CLOSE PLAYER OBJECT RESOURCE - KEEP IT OPEN IN MEMORY SO IT
// CAN'T MOVE!
- file = res_man.open(8);
+ file = res_man->openResource(8);
// Set up font resource variables for this language version
@@ -255,7 +255,7 @@ int32 Sword2Engine::InitialiseGame(void) {
// initialise the sound fx queue
debug(5, "CALLING: Init_fx_queue");
- Init_fx_queue();
+ initFxQueue();
// all demos (not just web)
if (_features & GF_DEMO) {
@@ -270,11 +270,7 @@ void Close_game() {
debug(5, "Close_game() STARTING:");
// Stop music instantly!
- Kill_music();
-
- // free the memory again
- memory.exit();
- res_man.exit();
+ g_sword2->killMusic();
g_system->quit();
}
@@ -304,13 +300,13 @@ int32 GameCycle(void) {
// if this screen is wide, recompute the scroll offsets every cycle
if (g_sword2->_thisScreen.scroll_flag)
- Set_scrolling();
+ g_sword2->setScrolling();
g_sword2->mouseEngine();
- Process_fx_queue();
+ g_sword2->processFxQueue();
// update age and calculate previous cycle memory usage
- res_man.nextCycle();
+ res_man->nextCycle();
if (quitGame)
return 1;
@@ -339,8 +335,8 @@ void Sword2Engine::go() {
}
if (_saveSlot != -1) {
- if (SaveExists(_saveSlot))
- RestoreGame(_saveSlot);
+ if (saveExists(_saveSlot))
+ restoreGame(_saveSlot);
else { // show restore menu
setMouse(NORMAL_MOUSE_ID);
if (!gui->restoreControl())
@@ -488,19 +484,19 @@ void Sword2Engine::Start_game(void) {
uint32 null_pc = 1;
// open george object, ready for start script to reference
- raw_data_ad = (char *) res_man.open(8);
+ raw_data_ad = (char *) res_man->openResource(8);
// open the ScreenManager object
- raw_script = (char *) res_man.open(screen_manager_id);
+ raw_script = (char *) res_man->openResource(screen_manager_id);
// run the start script now (because no console)
g_logic.runScript(raw_script, raw_data_ad, &null_pc);
// close the ScreenManager object
- res_man.close(screen_manager_id);
+ res_man->closeResource(screen_manager_id);
// close george
- res_man.close(8);
+ res_man->closeResource(8);
debug(5, "Start_game() DONE.");
}
@@ -523,16 +519,16 @@ void PauseGame(void) {
// uint8 *text;
// open text file & get the line "PAUSED"
- // text = FetchTextLine(res_man.open(3258), 449);
+ // text = FetchTextLine(res_man->openResource(3258), 449);
// pause_text_bloc_no = Build_new_block(text + 2, 320, 210, 640, 184, RDSPR_TRANS | RDSPR_DISPLAYALIGN, SPEECH_FONT_ID, POSITION_AT_CENTRE_OF_BASE);
// now ok to close the text file
- // res_man.close(3258);
+ // res_man->closeResource(3258);
// don't allow Pause while screen fading or while black
if (g_display->getFadeStatus() != RDFADE_NONE)
return;
- PauseAllSound();
+ g_sword2->pauseAllSound();
// make a normal mouse
g_sword2->clearPointerText();
@@ -557,7 +553,7 @@ void PauseGame(void) {
}
// don't dim it if we're single-stepping through frames
- // dim the palette during the pause (James26jun97)
+ // dim the palette during the pause
if (stepOneCycle == 0)
g_display->dimPalette();
@@ -572,7 +568,7 @@ void UnpauseGame(void) {
if (OBJECT_HELD && g_sword2->_realLuggageItem)
g_sword2->setLuggage(g_sword2->_realLuggageItem);
- UnpauseAllSound();
+ g_sword2->unpauseAllSound();
// put back game screen palette; see Build_display.cpp
g_sword2->setFullPalette(0xffffffff);
diff --git a/sword2/sword2.h b/sword2/sword2.h
index 8d44e81f96..8abc60d0c7 100644
--- a/sword2/sword2.h
+++ b/sword2/sword2.h
@@ -28,10 +28,13 @@
#include "sword2/build_display.h"
#include "sword2/console.h"
#include "sword2/events.h"
+#include "sword2/header.h"
#include "sword2/icons.h"
#include "sword2/layers.h"
#include "sword2/mouse.h"
#include "sword2/object.h"
+#include "sword2/save_rest.h"
+#include "sword2/sound.h"
#include "sword2/driver/d_sound.h"
#include "sword2/driver/d_draw.h"
@@ -129,6 +132,14 @@ private:
void startNewPalette(void);
void processLayer(uint32 layer_number);
+ void getPlayerStructures(void);
+ void putPlayerStructures(void);
+
+ uint32 saveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize);
+ uint32 restoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize);
+
+ uint32 calcChecksum(uint8 *buffer, uint32 size);
+
public:
Sword2Engine(GameDetector *detector, OSystem *syst);
~Sword2Engine();
@@ -276,6 +287,91 @@ public:
void registerMouse(Object_mouse *ob_mouse);
+ uint8 *fetchPalette(uint8 *screenFile);
+ _screenHeader *fetchScreenHeader(uint8 *screenFile);
+ _layerHeader *fetchLayerHeader(uint8 *screenFile, uint16 layerNo);
+ uint8 *fetchShadingMask(uint8 *screenFile);
+
+ _animHeader *fetchAnimHeader(uint8 *animFile);
+ _cdtEntry *fetchCdtEntry(uint8 *animFile, uint16 frameNo);
+ _frameHeader *fetchFrameHeader(uint8 *animFile, uint16 frameNo);
+ _parallax *fetchBackgroundParallaxLayer(uint8 *screenFile, int layer);
+ _parallax *fetchBackgroundLayer(uint8 *screenFile);
+ _parallax *fetchForegroundParallaxLayer(uint8 *screenFile, int layer);
+ uint8 *fetchTextLine(uint8 *file, uint32 text_line);
+ uint8 checkTextLine(uint8 *file, uint32 text_line);
+ uint8 *fetchPaletteMatchTable(uint8 *screenFile);
+ uint8 *fetchObjectName(int32 resourceId);
+
+ // savegame file header
+
+ struct _savegameHeader {
+ // sum of all bytes in file, excluding this uint32
+ uint32 checksum;
+
+ // player's description of savegame
+ char description[SAVE_DESCRIPTION_LEN];
+
+ uint32 varLength; // length of global variables resource
+ uint32 screenId; // resource id of screen file
+ uint32 runListId; // resource id of run list
+ uint32 feet_x; // copy of _thisScreen.feet_x
+ uint32 feet_y; // copy of _thisScreen.feet_y
+ uint32 music_id; // copy of 'looping_music_id'
+ _object_hub player_hub; // copy of player object's object_hub structure
+ Object_logic logic; // copy of player character logic structure
+
+ // copy of player character graphic structure
+ Object_graphic graphic;
+
+ // copy of player character mega structure
+ Object_mega mega;
+ };
+
+ _savegameHeader g_header;
+
+ uint32 saveGame(uint16 slotNo, uint8 *description);
+ uint32 restoreGame(uint16 slotNo);
+ uint32 getSaveDescription(uint16 slotNo, uint8 *description);
+ bool saveExists(uint16 slotNo);
+ void fillSaveBuffer(mem *buffer, uint32 size, uint8 *desc);
+ uint32 restoreFromBuffer(mem *buffer, uint32 size);
+ uint32 findBufferSize(void);
+
+ uint8 _scrollFraction;
+
+ void setScrolling(void);
+
+ struct _fxq_entry {
+ uint32 resource; // resource id of sample
+ uint32 fetchId; // Id of resource in PSX CD queue. :)
+ uint16 delay; // cycles to wait before playing (or 'random chance' if FX_RANDOM)
+ uint8 volume; // 0..16
+ int8 pan; // -16..16
+ uint8 type; // FX_SPOT, FX_RANDOM or FX_LOOP
+ };
+
+ _fxq_entry _fxQueue[FXQ_LENGTH];
+
+ // used to store id of tunes that loop, for save & restore
+ uint32 _loopingMusicId;
+
+ // to be called during system initialisation
+ void initFxQueue(void);
+
+ // to be called from the main loop, once per cycle
+ void processFxQueue(void);
+
+ // stops all fx & clears the queue - eg. when leaving a location
+ void clearFxQueue(void);
+
+ void pauseAllSound(void);
+ void unpauseAllSound(void);
+
+ void killMusic(void);
+
+ void triggerFx(uint8 j);
+
void errorString(const char *buf_input, char *buf_output);
void initialiseFontResourceFlags(void);
void initialiseFontResourceFlags(uint8 language);
diff --git a/sword2/tony_gsdk.cpp b/sword2/tony_gsdk.cpp
index 22b768ecb8..ef1f52a0df 100644
--- a/sword2/tony_gsdk.cpp
+++ b/sword2/tony_gsdk.cpp
@@ -31,9 +31,6 @@ namespace Sword2 {
uint32 Read_file(const char *name, mem **membloc, uint32 uid) {
// read the file in and place into an allocated MEM_float block
- // FIXME: As far as I can see, this function is only used in debug
- // builds, so maybe it should be removed completely?
-
File fh;
uint32 size;
@@ -45,7 +42,7 @@ uint32 Read_file(const char *name, mem **membloc, uint32 uid) {
size = fh.size();
// reserve enough floating memory for the file
- *membloc = memory.allocMemory(size, MEM_float, uid);
+ *membloc = memory->allocMemory(size, MEM_float, uid);
if (fh.read((*membloc)->ad, size) != size) {
debug(5, "Read_file read fail %d", name);
@@ -54,7 +51,7 @@ uint32 Read_file(const char *name, mem **membloc, uint32 uid) {
fh.close();
- //ok, done it - return bytes read
+ // ok, done it - return bytes read
return size;
}
diff --git a/sword2/walker.cpp b/sword2/walker.cpp
index 97b0283862..91e2d1e758 100644
--- a/sword2/walker.cpp
+++ b/sword2/walker.cpp
@@ -266,17 +266,17 @@ int32 Logic::fnWalkToAnim(int32 *params) {
if (ob_logic->looping == 0) {
// open anim file
- anim_file = res_man.open(params[4]);
+ anim_file = res_man->openResource(params[4]);
// point to animation header
- anim_head = FetchAnimHeader( anim_file );
+ anim_head = g_sword2->fetchAnimHeader( anim_file );
pars[4] = anim_head->feetStartX; // target_x
pars[5] = anim_head->feetStartY; // target_y
pars[6] = anim_head->feetStartDir; // target_dir
// close anim file
- res_man.close(params[4]);
+ res_man->closeResource(params[4]);
// if start coords not yet set in anim header, use the standby
// coords (which should be set beforehand in the script)
@@ -286,7 +286,7 @@ int32 Logic::fnWalkToAnim(int32 *params) {
pars[5] = standby_y;
pars[6] = standby_dir;
- debug(5, "WARNING: fnWalkToAnim(%s) used standby coords", FetchObjectName(params[4]));
+ debug(5, "WARNING: fnWalkToAnim(%s) used standby coords", g_sword2->fetchObjectName(params[4]));
}
if (pars[6] < 0 || pars[6] > 7)
@@ -430,8 +430,8 @@ int32 Logic::fnStandAfterAnim(int32 *params) {
// open the anim file & set up a pointer to the animation header
// open anim file
- anim_file = res_man.open(params[2]);
- anim_head = FetchAnimHeader(anim_file);
+ anim_file = res_man->openResource(params[2]);
+ anim_head = g_sword2->fetchAnimHeader(anim_file);
// set up the parameter list for fnWalkTo()
@@ -450,14 +450,14 @@ int32 Logic::fnStandAfterAnim(int32 *params) {
pars[3] = standby_y;
pars[4] = standby_dir;
- debug(5, "WARNING: fnStandAfterAnim(%s) used standby coords", FetchObjectName(params[2]));
+ debug(5, "WARNING: fnStandAfterAnim(%s) used standby coords", g_sword2->fetchObjectName(params[2]));
}
if (pars[4] < 0 || pars[4] > 7)
error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
// close the anim file
- res_man.close(params[2]);
+ res_man->closeResource(params[2]);
// call fnStandAt() with target coords set to anim end position
return fnStandAt(pars);
@@ -477,8 +477,8 @@ int32 Logic::fnStandAtAnim(int32 *params) {
// open the anim file & set up a pointer to the animation header
// open anim file
- anim_file = res_man.open(params[2]);
- anim_head = FetchAnimHeader(anim_file);
+ anim_file = res_man->openResource(params[2]);
+ anim_head = g_sword2->fetchAnimHeader(anim_file);
// set up the parameter list for fnWalkTo()
@@ -497,14 +497,14 @@ int32 Logic::fnStandAtAnim(int32 *params) {
pars[3] = standby_y;
pars[4] = standby_dir;
- debug(5, "WARNING: fnStandAtAnim(%s) used standby coords", FetchObjectName(params[2]));
+ debug(5, "WARNING: fnStandAtAnim(%s) used standby coords", g_sword2->fetchObjectName(params[2]));
}
if (pars[4] < 0 || pars[4] > 7)
error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
// close the anim file
- res_man.close(params[2]);
+ res_man->closeResource(params[2]);
// call fnStandAt() with target coords set to anim end position
return fnStandAt(pars);
@@ -603,7 +603,7 @@ int32 Logic::fnFaceMega(int32 *params) {
if (ob_logic->looping == 0) {
// get targets info
- head = (_standardHeader*) res_man.open(params[4]);
+ head = (_standardHeader*) res_man->openResource(params[4]);
if (head->fileType != GAME_OBJECT)
error("fnFaceMega %d not an object", params[4]);
@@ -613,7 +613,7 @@ int32 Logic::fnFaceMega(int32 *params) {
//call the base script - this is the graphic/mouse service call
runScript(raw_script_ad, raw_script_ad, &null_pc);
- res_man.close(params[4]);
+ res_man->closeResource(params[4]);
// engineMega is now the Object_mega of mega we want to turn
// to face
@@ -665,7 +665,7 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) {
// not been here before so decide where to walk-to
if (!ob_logic->looping) {
// first request the targets info
- head = (_standardHeader*) res_man.open(params[4]);
+ head = (_standardHeader*) res_man->openResource(params[4]);
if (head->fileType != GAME_OBJECT)
error("fnWalkToTalkToMega %d not an object", params[4]);
@@ -676,7 +676,7 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) {
// call
runScript(raw_script_ad, raw_script_ad, &null_pc);
- res_man.close(params[4]);
+ res_man->closeResource(params[4]);
// engineMega is now the Object_mega of mega we want to
// route to
@@ -744,8 +744,8 @@ int32 Logic::fnAddWalkGrid(int32 *params) {
router.addWalkGrid(params[0]);
// Touch the grid, getting it into memory.
- res_man.open(params[0]);
- res_man.close(params[0]);
+ res_man->openResource(params[0]);
+ res_man->closeResource(params[0]);
return IR_CONT;
}