aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sword2/console.cpp316
-rw-r--r--sword2/console.h8
-rw-r--r--sword2/debug.cpp31
-rw-r--r--sword2/events.cpp24
-rw-r--r--sword2/logic.cpp30
-rw-r--r--sword2/logic.h29
-rw-r--r--sword2/memory.cpp111
-rw-r--r--sword2/memory.h9
-rw-r--r--sword2/resman.cpp125
-rw-r--r--sword2/resman.h68
-rw-r--r--sword2/startup.cpp36
-rw-r--r--sword2/sword2.h31
12 files changed, 410 insertions, 408 deletions
diff --git a/sword2/console.cpp b/sword2/console.cpp
index 32e7d6eeb2..01329eaf1f 100644
--- a/sword2/console.cpp
+++ b/sword2/console.cpp
@@ -179,8 +179,92 @@ bool Debugger::Cmd_Help(int argc, const char **argv) {
return true;
}
+static int compare_blocks(const void *p1, const void *p2) {
+ const MemBlock *m1 = *(const MemBlock * const *) p1;
+ const MemBlock *m2 = *(const MemBlock * const *) p2;
+
+ if (m1->size < m2->size)
+ return 1;
+ if (m1->size > m2->size)
+ return -1;
+ return 0;
+}
+
bool Debugger::Cmd_Mem(int argc, const char **argv) {
- _vm->_memory->memDisplay();
+ int16 numBlocks = _vm->_memory->getNumBlocks();
+ MemBlock *memBlocks = _vm->_memory->getMemBlocks();
+
+ MemBlock **blocks = (MemBlock **) malloc(numBlocks * sizeof(MemBlock));
+
+ int i, j;
+
+ for (i = 0, j = 0; i < MAX_MEMORY_BLOCKS; i++) {
+ if (memBlocks[i].ptr)
+ blocks[j++] = &memBlocks[i];
+ }
+
+ qsort(blocks, numBlocks, sizeof(MemBlock *), compare_blocks);
+
+ DebugPrintf(" size id res type name\n");
+ DebugPrintf("---------------------------------------------------------------------------\n");
+
+ for (i = 0; i < numBlocks; i++) {
+ StandardHeader *head = (StandardHeader *) blocks[i]->ptr;
+ const char *type;
+
+ switch (head->fileType) {
+ case ANIMATION_FILE:
+ type = "ANIMATION_FILE";
+ break;
+ case SCREEN_FILE:
+ type = "SCREEN_FILE";
+ break;
+ case GAME_OBJECT:
+ type = "GAME_OBJECT";
+ break;
+ case WALK_GRID_FILE:
+ type = "WALK_GRID_FILE";
+ break;
+ case GLOBAL_VAR_FILE:
+ type = "GLOBAL_VAR_FILE";
+ break;
+ case PARALLAX_FILE_null:
+ type = "PARALLAX_FILE_null";
+ break;
+ case RUN_LIST:
+ type = "RUN_LIST";
+ break;
+ case TEXT_FILE:
+ type = "TEXT_FILE";
+ break;
+ case SCREEN_MANAGER:
+ type = "SCREEN_MANAGER";
+ break;
+ case MOUSE_FILE:
+ type = "MOUSE_FILE";
+ break;
+ case WAV_FILE:
+ type = "WAV_FILE";
+ break;
+ case ICON_FILE:
+ type = "ICON_FILE";
+ break;
+ case PALETTE_FILE:
+ type = "PALETTE_FILE";
+ break;
+ default:
+ type = "<unknown>";
+ break;
+ }
+
+ DebugPrintf("%9ld %-3d %-4d %-20s %s\n", blocks[i]->size, blocks[i]->id, blocks[i]->uid, type, head->name);
+ }
+
+ free(blocks);
+
+ DebugPrintf("---------------------------------------------------------------------------\n");
+ DebugPrintf("%9ld\n", _vm->_memory->getTotAlloc());
+
return true;
}
@@ -190,7 +274,37 @@ bool Debugger::Cmd_Tony(int argc, const char **argv) {
}
bool Debugger::Cmd_Res(int argc, const char **argv) {
- _vm->_resman->printConsoleClusters();
+ uint32 numClusters = _vm->_resman->getNumClusters();
+
+ if (!numClusters) {
+ DebugPrintf("Argh! No resources!\n");
+ return true;
+ }
+
+ ResourceFile *resFiles = _vm->_resman->getResFiles();
+
+ for (uint i = 0; i < numClusters; i++) {
+ DebugPrintf("%-20s ", resFiles[i].fileName);
+ if (!(resFiles[i].cd & LOCAL_PERM)) {
+ switch (resFiles[i].cd & 3) {
+ case BOTH:
+ DebugPrintf("CD 1 & 2\n");
+ break;
+ case CD1:
+ DebugPrintf("CD 1\n");
+ break;
+ case CD2:
+ DebugPrintf("CD 2\n");
+ break;
+ default:
+ DebugPrintf("CD 3? Huh?!\n");
+ break;
+ }
+ } else
+ DebugPrintf("HD\n");
+ }
+
+ DebugPrintf("%d resources\n", _vm->_resman->getNumResFiles());
return true;
}
@@ -201,12 +315,39 @@ bool Debugger::Cmd_ResList(int argc, const char **argv) {
if (argc > 1)
minCount = atoi(argv[1]);
- _vm->_resman->listResources(minCount);
+ uint32 numResFiles = _vm->_resman->getNumResFiles();
+ Resource *resList = _vm->_resman->getResList();
+
+ for (uint i = 0; i < numResFiles; i++) {
+ if (resList[i].ptr && resList[i].refCount >= minCount) {
+ StandardHeader *head = (StandardHeader *) resList[i].ptr;
+ DebugPrintf("%-4d: %-35s refCount: %-3d\n", i, head->name, resList[i].refCount);
+ }
+ }
+
return true;
}
bool Debugger::Cmd_Starts(int argc, const char **argv) {
- _vm->conPrintStartMenu();
+ uint32 numStarts = _vm->getNumStarts();
+
+ if (!numStarts) {
+ DebugPrintf("Sorry - no startup positions registered?\n");
+
+ uint32 numScreenManagers = _vm->getNumScreenManagers();
+
+ if (!numScreenManagers)
+ DebugPrintf("There is a problem with startup.inf\n");
+ else
+ DebugPrintf(" (%d screen managers found in startup.inf)\n", numScreenManagers);
+ return true;
+ }
+
+ StartUp *startList = _vm->getStartList();
+
+ for (uint i = 0; i < numStarts; i++)
+ DebugPrintf("%d (%s)\n", i, startList[i].description);
+
return true;
}
@@ -218,7 +359,23 @@ bool Debugger::Cmd_Start(int argc, const char **argv) {
return true;
}
- _vm->conStart(atoi(argv[1]));
+ uint32 numStarts = _vm->getNumStarts();
+
+ if (!numStarts) {
+ DebugPrintf("Sorry - there are no startups!\n");
+ return true;
+ }
+
+ int start = atoi(argv[1]);
+
+ if (start < 0 || start >= (int) numStarts) {
+ DebugPrintf("Not a legal start position\n");
+ return true;
+ }
+
+ DebugPrintf("Running start %d\n", start);
+
+ _vm->runStart(start);
_vm->_screen->setPalette(187, 1, pal, RDPAL_INSTANT);
return true;
}
@@ -268,28 +425,139 @@ bool Debugger::Cmd_Player(int argc, const char **argv) {
}
bool Debugger::Cmd_ResLook(int argc, const char **argv) {
- if (argc != 2)
+ if (argc != 2) {
DebugPrintf("Usage: %s number\n", argv[0]);
- else
- _vm->_resman->examine(atoi(argv[1]));
+ return true;
+ }
+
+ int res = atoi(argv[1]);
+ uint32 numResFiles = _vm->_resman->getNumResFiles();
+
+ if (res < 0 || res >= (int) numResFiles) {
+ DebugPrintf("Illegal resource %d. There are %d resources, 0-%d.\n",
+ res, numResFiles, numResFiles - 1);
+ return true;
+ }
+
+ if (!_vm->_resman->checkValid(res)) {
+ DebugPrintf("%d is a null & void resource number\n", res);
+ return true;
+ }
+
+ // Open up the resource and take a look inside!
+ StandardHeader *file_header = (StandardHeader *) _vm->_resman->openResource(res);
+
+ switch (file_header->fileType) {
+ case ANIMATION_FILE:
+ DebugPrintf("<anim> %s\n", file_header->name);
+ break;
+ case SCREEN_FILE:
+ DebugPrintf("<layer> %s\n", file_header->name);
+ break;
+ case GAME_OBJECT:
+ DebugPrintf("<game object> %s\n", file_header->name);
+ break;
+ case WALK_GRID_FILE:
+ DebugPrintf("<walk grid> %s\n", file_header->name);
+ break;
+ case GLOBAL_VAR_FILE:
+ DebugPrintf("<global variables> %s\n", file_header->name);
+ break;
+ case PARALLAX_FILE_null:
+ DebugPrintf("<parallax file NOT USED!> %s\n", file_header->name);
+ break;
+ case RUN_LIST:
+ DebugPrintf("<run list> %s\n", file_header->name);
+ break;
+ case TEXT_FILE:
+ DebugPrintf("<text file> %s\n", file_header->name);
+ break;
+ case SCREEN_MANAGER:
+ DebugPrintf("<screen manager> %s\n", file_header->name);
+ break;
+ case MOUSE_FILE:
+ DebugPrintf("<mouse pointer> %s\n", file_header->name);
+ break;
+ case ICON_FILE:
+ DebugPrintf("<menu icon> %s\n", file_header->name);
+ break;
+ default:
+ DebugPrintf("unrecognised fileType %d\n", file_header->fileType);
+ break;
+ }
+
+ _vm->_resman->closeResource(res);
return true;
}
bool Debugger::Cmd_CurrentInfo(int argc, const char **argv) {
- printCurrentInfo();
+ // prints general stuff about the screen, etc.
+ ScreenInfo *screenInfo = _vm->_screen->getScreenInfo();
+
+ if (screenInfo->background_layer_id) {
+ DebugPrintf("background layer id %d\n", screenInfo->background_layer_id);
+ DebugPrintf("%d wide, %d high\n", screenInfo->screen_wide, screenInfo->screen_deep);
+ DebugPrintf("%d normal layers\n", screenInfo->number_of_layers);
+
+ Cmd_RunList(argc, argv);
+ } else
+ DebugPrintf("No screen\n");
return true;
}
bool Debugger::Cmd_RunList(int argc, const char **argv) {
- _vm->_logic->examineRunList();
+ uint32 *game_object_list;
+ StandardHeader *file_header;
+
+ uint32 runList = _vm->_logic->getRunList();
+
+ if (runList) {
+ game_object_list = (uint32 *) (_vm->_resman->openResource(runList) + sizeof(StandardHeader));
+
+ DebugPrintf("Runlist number %d\n", runList);
+
+ for (int i = 0; game_object_list[i]; i++) {
+ file_header = (StandardHeader *) _vm->_resman->openResource(game_object_list[i]);
+ DebugPrintf("%d %s\n", game_object_list[i], file_header->name);
+ _vm->_resman->closeResource(game_object_list[i]);
+ }
+
+ _vm->_resman->closeResource(runList);
+ } else
+ DebugPrintf("No run list set\n");
+
return true;
}
bool Debugger::Cmd_Kill(int argc, const char **argv) {
- if (argc != 2)
+ if (argc != 2) {
DebugPrintf("Usage: %s number\n", argv[0]);
- else
- _vm->_resman->kill(atoi(argv[1]));
+ return true;
+ }
+
+ int res = atoi(argv[1]);
+ uint32 numResFiles = _vm->_resman->getNumResFiles();
+
+ if (res < 0 || res >= (int) numResFiles) {
+ DebugPrintf("Illegal resource %d. There are %d resources, 0-%d.\n",
+ res, numResFiles, numResFiles - 1);
+ return true;
+ }
+
+ Resource *resList = _vm->_resman->getResList();
+
+ if (!resList[res].ptr) {
+ DebugPrintf("Resource %d is not in memory\n", res);
+ return true;
+ }
+
+ if (resList[res].refCount) {
+ DebugPrintf("Resource %d is open - cannot remove\n", res);
+ return true;
+ }
+
+ _vm->_resman->remove(res);
+ DebugPrintf("Trashed %d\n", res);
return true;
}
@@ -466,7 +734,7 @@ bool Debugger::Cmd_AnimTest(int argc, const char **argv) {
}
// Automatically do "s 32" to run the animation testing start script
- _vm->conStart(32);
+ _vm->runStart(32);
// Same as typing "VAR 912 <value>" at the console
varSet(912, atoi(argv[1]));
@@ -482,7 +750,7 @@ bool Debugger::Cmd_TextTest(int argc, const char **argv) {
}
// Automatically do "s 33" to run the text/speech testing start script
- _vm->conStart(33);
+ _vm->runStart(33);
// Same as typing "VAR 1230 <value>" at the console
varSet(1230, atoi(argv[1]));
@@ -501,7 +769,7 @@ bool Debugger::Cmd_LineTest(int argc, const char **argv) {
}
// Automatically do "s 33" to run the text/speech testing start script
- _vm->conStart(33);
+ _vm->runStart(33);
// Same as typing "VAR 1230 <value>" at the console
varSet(1230, atoi(argv[1]));
@@ -518,7 +786,21 @@ bool Debugger::Cmd_LineTest(int argc, const char **argv) {
}
bool Debugger::Cmd_Events(int argc, const char **argv) {
- _vm->_logic->printEventList();
+ EventUnit *eventList = _vm->_logic->getEventList();
+
+ DebugPrintf("EVENT LIST:\n");
+
+ for (uint32 i = 0; i < MAX_events; i++) {
+ if (eventList[i].id) {
+ byte buf[NAME_LEN];
+ uint32 target = eventList[i].id;
+ uint32 script = eventList[i].interact_id;
+
+ DebugPrintf("slot %2d: id = %s (%d)\n", i, _vm->fetchObjectName(target, buf), target);
+ DebugPrintf(" script = %s (%d) pos %d\n", _vm->fetchObjectName(script / 65536, buf), script / 65536, script % 65536);
+ }
+ }
+
return true;
}
diff --git a/sword2/console.h b/sword2/console.h
index 6c3ee7886b..f7e41f3819 100644
--- a/sword2/console.h
+++ b/sword2/console.h
@@ -46,11 +46,9 @@ private:
byte _debugTextBlocks[MAX_DEBUG_TEXTS];
- void clearDebugTextBlocks(void);
+ void clearDebugTextBlocks();
void makeDebugTextBlock(char *text, int16 x, int16 y);
- void printCurrentInfo(void);
-
void plotCrossHair(int16 x, int16 y, uint8 pen);
void drawRect(int16 x, int16 y, int16 x2, int16 y2, uint8 pen);
@@ -72,8 +70,8 @@ public:
ObjectGraphic _playerGraphic;
uint32 _playerGraphicNoFrames;
- void buildDebugText(void);
- void drawDebugGraphics(void);
+ void buildDebugText();
+ void drawDebugGraphics();
protected:
Sword2Engine *_vm;
diff --git a/sword2/debug.cpp b/sword2/debug.cpp
index 4d4d4eb8ff..11090c3960 100644
--- a/sword2/debug.cpp
+++ b/sword2/debug.cpp
@@ -31,7 +31,7 @@
namespace Sword2 {
-void Debugger::clearDebugTextBlocks(void) {
+void Debugger::clearDebugTextBlocks() {
uint8 blockNo = 0;
while (blockNo < MAX_DEBUG_TEXTS && _debugTextBlocks[blockNo] > 0) {
@@ -56,7 +56,7 @@ void Debugger::makeDebugTextBlock(char *text, int16 x, int16 y) {
_debugTextBlocks[blockNo] = _vm->_fontRenderer->buildNewBloc((byte *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION);
}
-void Debugger::buildDebugText(void) {
+void Debugger::buildDebugText() {
char buf[128];
int32 showVarNo; // for variable watching
@@ -307,12 +307,21 @@ void Debugger::buildDebugText(void) {
// memory indicator - this should come last, to show all the
// sprite blocks above!
- _vm->_memory->memStatusStr(buf);
+ uint32 totAlloc = _vm->_memory->getTotAlloc();
+ int16 numBlocks = _vm->_memory->getNumBlocks();
+
+ if (totAlloc < 1024)
+ sprintf(buf, "%u bytes in %d memory blocks", totAlloc, numBlocks);
+ else if (totAlloc < 1024 * 1024)
+ sprintf(buf, "%uK in %d memory blocks", totAlloc / 1024, numBlocks);
+ else
+ sprintf(buf, "%.02fM in %d memory blocks", totAlloc / 1048576., numBlocks);
+
makeDebugTextBlock(buf, 0, 0);
}
}
-void Debugger::drawDebugGraphics(void) {
+void Debugger::drawDebugGraphics() {
ScreenInfo *screenInfo = _vm->_screen->getScreenInfo();
// walk-grid
@@ -364,18 +373,4 @@ void Debugger::drawRect(int16 x1, int16 y1, int16 x2, int16 y2, uint8 pen) {
_vm->_screen->drawLine(x2, y1, x2, y2, pen); // right edge
}
-void Debugger::printCurrentInfo(void) {
- // prints general stuff about the screen, etc.
- ScreenInfo *screenInfo = _vm->_screen->getScreenInfo();
-
- if (screenInfo->background_layer_id) {
- DebugPrintf("background layer id %d\n", screenInfo->background_layer_id);
- DebugPrintf("%d wide, %d high\n", screenInfo->screen_wide, screenInfo->screen_deep);
- DebugPrintf("%d normal layers\n", screenInfo->number_of_layers);
-
- _vm->_logic->examineRunList();
- } else
- DebugPrintf("No screen\n");
-}
-
} // End of namespace Sword2
diff --git a/sword2/events.cpp b/sword2/events.cpp
index b56f999f20..63eee9df4d 100644
--- a/sword2/events.cpp
+++ b/sword2/events.cpp
@@ -21,14 +21,11 @@
#include "common/stdafx.h"
#include "sword2/sword2.h"
#include "sword2/defs.h"
-#include "sword2/console.h"
#include "sword2/interpreter.h"
#include "sword2/logic.h"
#include "sword2/memory.h"
#include "sword2/resman.h"
-#define Debug_Printf _vm->_debugger->DebugPrintf
-
namespace Sword2 {
void Logic::sendEvent(uint32 id, uint32 interact_id) {
@@ -48,7 +45,7 @@ void Logic::setPlayerActionEvent(uint32 id, uint32 interact_id) {
sendEvent(id, (interact_id << 16) | 2);
}
-int Logic::checkEventWaiting(void) {
+int Logic::checkEventWaiting() {
for (int i = 0; i < MAX_events; i++) {
if (_eventList[i].id == _scriptVars[ID])
return 1;
@@ -57,7 +54,7 @@ int Logic::checkEventWaiting(void) {
return 0;
}
-void Logic::startEvent(void) {
+void Logic::startEvent() {
// call this from stuff like fnWalk
// you must follow with a return IR_TERMINATE
@@ -90,7 +87,7 @@ void Logic::killAllIdsEvents(uint32 id) {
// For the debugger
-uint32 Logic::countEvents(void) {
+uint32 Logic::countEvents() {
uint32 count = 0;
for (int i = 0; i < MAX_events; i++) {
@@ -101,19 +98,4 @@ uint32 Logic::countEvents(void) {
return count;
}
-void Logic::printEventList(void) {
- Debug_Printf("EVENT LIST:\n");
-
- for (uint32 i = 0; i < MAX_events; i++) {
- if (_eventList[i].id) {
- byte buf[NAME_LEN];
- uint32 target = _eventList[i].id;
- uint32 script = _eventList[i].interact_id;
-
- Debug_Printf("slot %2d: id = %s (%d)\n", i, _vm->fetchObjectName(target, buf), target);
- Debug_Printf(" script = %s (%d) pos %d\n", _vm->fetchObjectName(script / 65536, buf), script / 65536, script % 65536);
- }
- }
-}
-
} // End of namespace Sword2
diff --git a/sword2/logic.cpp b/sword2/logic.cpp
index 2472c7f726..1ab10ba8d1 100644
--- a/sword2/logic.cpp
+++ b/sword2/logic.cpp
@@ -21,7 +21,6 @@
#include "common/stdafx.h"
#include "sword2/sword2.h"
#include "sword2/defs.h"
-#include "sword2/console.h"
#include "sword2/interpreter.h"
#include "sword2/logic.h"
#include "sword2/resman.h"
@@ -30,8 +29,6 @@
#define LEVEL (_curObjectHub->logic_level)
-#define Debug_Printf _vm->_debugger->DebugPrintf
-
namespace Sword2 {
Logic::Logic(Sword2Engine *vm) :
@@ -54,7 +51,7 @@ Logic::~Logic() {
* Do one cycle of the current session.
*/
-int Logic::processSession(void) {
+int Logic::processSession() {
// might change during the session, so take a copy here
uint32 run_list = _currentRunList;
@@ -219,7 +216,7 @@ void Logic::expressChangeSession(uint32 sesh_id) {
* @return The private _currentRunList variable.
*/
-uint32 Logic::getRunList(void) {
+uint32 Logic::getRunList() {
return _currentRunList;
}
@@ -257,28 +254,7 @@ void Logic::logicReplace(uint32 new_script) {
_curObjectHub->script_pc[LEVEL] = new_script & 0xffff;
}
-void Logic::examineRunList(void) {
- uint32 *game_object_list;
- StandardHeader *file_header;
-
- if (_currentRunList) {
- // open and lock in place
- game_object_list = (uint32 *) (_vm->_resman->openResource(_currentRunList) + sizeof(StandardHeader));
-
- Debug_Printf("Runlist number %d\n", _currentRunList);
-
- for (int i = 0; game_object_list[i]; i++) {
- file_header = (StandardHeader *) _vm->_resman->openResource(game_object_list[i]);
- Debug_Printf("%d %s\n", game_object_list[i], file_header->name);
- _vm->_resman->closeResource(game_object_list[i]);
- }
-
- _vm->_resman->closeResource(_currentRunList);
- } else
- Debug_Printf("No run list set\n");
-}
-
-void Logic::resetKillList(void) {
+void Logic::resetKillList() {
_kills = 0;
}
diff --git a/sword2/logic.h b/sword2/logic.h
index a75d93a4b2..a23aa10a9e 100644
--- a/sword2/logic.h
+++ b/sword2/logic.h
@@ -44,6 +44,11 @@ struct MovieTextObject;
class Sword2Engine;
class Router;
+struct EventUnit {
+ uint32 id;
+ uint32 interact_id;
+};
+
class Logic {
private:
Sword2Engine *_vm;
@@ -62,11 +67,6 @@ private:
// each object has one of these tacked onto the beginning
ObjectHub *_curObjectHub;
- struct EventUnit {
- uint32 id;
- uint32 interact_id;
- };
-
EventUnit _eventList[MAX_events];
// Resource id of the wav to use as lead-in/lead-out from smacker
@@ -148,6 +148,8 @@ public:
Logic(Sword2Engine *vm);
~Logic();
+ EventUnit *getEventList() { return _eventList; }
+
// Point to the global variable data
static uint32 *_scriptVars;
@@ -166,12 +168,12 @@ public:
void sendEvent(uint32 id, uint32 interact_id);
void setPlayerActionEvent(uint32 id, uint32 interact_id);
- void startEvent(void);
- int checkEventWaiting(void);
+ void startEvent();
+ int checkEventWaiting();
void clearEvent(uint32 id);
void killAllIdsEvents(uint32 id);
- uint32 countEvents(void);
+ uint32 countEvents();
struct SyncUnit {
uint32 id;
@@ -181,7 +183,7 @@ public:
SyncUnit _syncList[MAX_syncs];
void clearSyncs(uint32 id);
- int getSync(void);
+ int getSync();
Router *_router;
@@ -304,22 +306,19 @@ public:
int32 fnChangeShadows(int32 *params);
// do one cycle of the current session
- int processSession(void);
+ int processSession();
// cause the logic loop to terminate and drop out
void expressChangeSession(uint32 sesh_id);
- uint32 getRunList(void);
+ uint32 getRunList();
// setup script_id and script_pc in _curObjectHub - called by fnGosub()
void logicUp(uint32 new_script);
void logicReplace(uint32 new_script);
void logicOne(uint32 new_script);
- void examineRunList(void);
- void resetKillList(void);
-
- void printEventList(void);
+ void resetKillList();
};
} // End of namespace Sword2
diff --git a/sword2/memory.cpp b/sword2/memory.cpp
index 6c84409f0e..ea06fd8abf 100644
--- a/sword2/memory.cpp
+++ b/sword2/memory.cpp
@@ -43,15 +43,10 @@
#include "common/stdafx.h"
#include "sword2/sword2.h"
-#include "sword2/console.h"
#include "sword2/memory.h"
namespace Sword2 {
-#define MAX_BLOCKS 999
-
-#define Debug_Printf _vm->_debugger->DebugPrintf
-
MemoryManager::MemoryManager(Sword2Engine *vm) : _vm(vm) {
// The id stack contains all the possible ids for the memory blocks.
// We use this to ensure that no two blocks ever have the same id.
@@ -71,24 +66,24 @@ MemoryManager::MemoryManager(Sword2Engine *vm) : _vm(vm) {
// encoding or decoding pointers any faster, and these are by far the
// most common operations.
- _idStack = (int16 *) malloc(MAX_BLOCKS * sizeof(int16));
- _memBlocks = (MemBlock *) malloc(MAX_BLOCKS * sizeof(MemBlock));
- _memBlockIndex = (MemBlock **) malloc(MAX_BLOCKS * sizeof(MemBlock *));
+ _idStack = (int16 *) malloc(MAX_MEMORY_BLOCKS * sizeof(int16));
+ _memBlocks = (MemBlock *) malloc(MAX_MEMORY_BLOCKS * sizeof(MemBlock));
+ _memBlockIndex = (MemBlock **) malloc(MAX_MEMORY_BLOCKS * sizeof(MemBlock *));
_totAlloc = 0;
_numBlocks = 0;
- for (int i = 0; i < MAX_BLOCKS; i++) {
- _idStack[i] = MAX_BLOCKS - i - 1;
+ for (int i = 0; i < MAX_MEMORY_BLOCKS; i++) {
+ _idStack[i] = MAX_MEMORY_BLOCKS - i - 1;
_memBlocks[i].ptr = NULL;
_memBlockIndex[i] = NULL;
}
- _idStackPtr = MAX_BLOCKS;
+ _idStackPtr = MAX_MEMORY_BLOCKS;
}
MemoryManager::~MemoryManager() {
- for (int i = 0; i < MAX_BLOCKS; i++)
+ for (int i = 0; i < MAX_MEMORY_BLOCKS; i++)
free(_memBlocks[i].ptr);
free(_memBlocks);
free(_memBlockIndex);
@@ -245,96 +240,4 @@ void MemoryManager::memFree(byte *ptr) {
_memBlockIndex[i] = _memBlockIndex[i + 1];
}
-static int compare_blocks(const void *p1, const void *p2) {
- const MemBlock *m1 = *(const MemBlock * const *) p1;
- const MemBlock *m2 = *(const MemBlock * const *) p2;
-
- if (m1->size < m2->size)
- return 1;
- if (m1->size > m2->size)
- return -1;
- return 0;
-}
-
-void MemoryManager::memDisplay() {
- MemBlock **blocks = (MemBlock **) malloc(_numBlocks * sizeof(MemBlock));
- int i, j;
-
- for (i = 0, j = 0; i < MAX_BLOCKS; i++) {
- if (_memBlocks[i].ptr)
- blocks[j++] = &_memBlocks[i];
- }
-
- qsort(blocks, _numBlocks, sizeof(MemBlock *), compare_blocks);
-
- Debug_Printf(" size id res type name\n");
- Debug_Printf("---------------------------------------------------------------------------\n");
-
- for (i = 0; i < _numBlocks; i++) {
- StandardHeader *head = (StandardHeader *) blocks[i]->ptr;
- const char *type;
-
- switch (head->fileType) {
- case ANIMATION_FILE:
- type = "ANIMATION_FILE";
- break;
- case SCREEN_FILE:
- type = "SCREEN_FILE";
- break;
- case GAME_OBJECT:
- type = "GAME_OBJECT";
- break;
- case WALK_GRID_FILE:
- type = "WALK_GRID_FILE";
- break;
- case GLOBAL_VAR_FILE:
- type = "GLOBAL_VAR_FILE";
- break;
- case PARALLAX_FILE_null:
- type = "PARALLAX_FILE_null";
- break;
- case RUN_LIST:
- type = "RUN_LIST";
- break;
- case TEXT_FILE:
- type = "TEXT_FILE";
- break;
- case SCREEN_MANAGER:
- type = "SCREEN_MANAGER";
- break;
- case MOUSE_FILE:
- type = "MOUSE_FILE";
- break;
- case WAV_FILE:
- type = "WAV_FILE";
- break;
- case ICON_FILE:
- type = "ICON_FILE";
- break;
- case PALETTE_FILE:
- type = "PALETTE_FILE";
- break;
- default:
- type = "<unknown>";
- break;
- }
-
- Debug_Printf("%9ld %-3d %-4d %-20s %s\n", blocks[i]->size, blocks[i]->id, blocks[i]->uid, type, head->name);
- }
-
- free(blocks);
-
- Debug_Printf("---------------------------------------------------------------------------\n");
- Debug_Printf("%9ld\n", _totAlloc);
-}
-
-void MemoryManager::memStatusStr(char *buf) {
- if (_totAlloc < 1024)
- sprintf(buf, "%u bytes in %d memory blocks", _totAlloc, _numBlocks);
- else if (_totAlloc < 1024 * 1024)
- sprintf(buf, "%uK in %d memory blocks", _totAlloc / 1024, _numBlocks);
- else
- sprintf(buf, "%.02fM in %d memory blocks", _totAlloc / 1048576., _numBlocks);
-}
-
} // End of namespace Sword2
diff --git a/sword2/memory.h b/sword2/memory.h
index def61589ff..46a5dd63f0 100644
--- a/sword2/memory.h
+++ b/sword2/memory.h
@@ -21,6 +21,8 @@
#ifndef MEMORY_H
#define MEMORY_H
+#define MAX_MEMORY_BLOCKS 999
+
namespace Sword2 {
struct MemBlock {
@@ -51,14 +53,15 @@ public:
MemoryManager(Sword2Engine *vm);
~MemoryManager();
+ int16 getNumBlocks() { return _numBlocks; }
+ uint32 getTotAlloc() { return _totAlloc; }
+ MemBlock *getMemBlocks() { return _memBlocks; }
+
int32 encodePtr(byte *ptr);
byte *decodePtr(int32 n);
byte *memAlloc(uint32 size, int16 uid);
void memFree(byte *ptr);
-
- void memDisplay();
- void memStatusStr(char *buf);
};
} // End of namespace Sword2
diff --git a/sword2/resman.cpp b/sword2/resman.cpp
index 3ab598ad42..a83471ffbb 100644
--- a/sword2/resman.cpp
+++ b/sword2/resman.cpp
@@ -21,8 +21,8 @@
#include "common/stdafx.h"
#include "common/file.h"
#include "sword2/sword2.h"
-#include "sword2/console.h"
#include "sword2/defs.h"
+#include "sword2/console.h"
#include "sword2/logic.h"
#include "sword2/memory.h"
#include "sword2/resman.h"
@@ -42,14 +42,6 @@ namespace Sword2 {
// resource.tab which is a table which tells us which cluster a resource
// is located in and the number within the cluster
-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
#endif
@@ -198,7 +190,7 @@ ResourceManager::ResourceManager(Sword2Engine *vm) {
_usedMem = 0;
}
-ResourceManager::~ResourceManager(void) {
+ResourceManager::~ResourceManager() {
Resource *res = _cacheStart;
while (res) {
_vm->_memory->memFree(res->ptr);
@@ -659,7 +651,7 @@ uint32 ResourceManager::fetchLen(uint32 res) {
return _resFiles[parent_res_file].entryTab[actual_res * 2 + 1];
}
-void ResourceManager::checkMemUsage(void) {
+void ResourceManager::checkMemUsage() {
while (_usedMem > MAX_MEM_CACHE) {
// we're using up more memory than we wanted to. free some old stuff.
// Newly loaded objects are added to the start of the list,
@@ -679,113 +671,6 @@ void ResourceManager::checkMemUsage(void) {
}
}
-void ResourceManager::printConsoleClusters(void) {
- if (_totalClusters) {
- for (uint i = 0; i < _totalClusters; i++) {
- Debug_Printf("%-20s ", _resFiles[i].fileName);
- if (!(_resFiles[i].cd & LOCAL_PERM)) {
- switch (_resFiles[i].cd & 3) {
- case BOTH:
- Debug_Printf("CD 1 & 2\n");
- break;
- case CD1:
- Debug_Printf("CD 1\n");
- break;
- case CD2:
- Debug_Printf("CD 2\n");
- break;
- default:
- Debug_Printf("CD 3? Huh?!\n");
- break;
- }
- } else
- Debug_Printf("HD\n");
- }
- Debug_Printf("%d resources\n", _totalResFiles);
- } else
- Debug_Printf("Argh! No resources!\n");
-}
-
-void ResourceManager::listResources(uint minCount) {
- for (uint i = 0; i < _totalResFiles; i++) {
- if (_resList[i].ptr && _resList[i].refCount >= minCount) {
- StandardHeader *head = (StandardHeader *) _resList[i].ptr;
- Debug_Printf("%-4d: %-35s refCount: %-3d\n", i, head->name, _resList[i].refCount);
- }
- }
-}
-
-void ResourceManager::examine(int res) {
- if (res < 0 || res >= (int) _totalResFiles)
- Debug_Printf("Illegal resource %d (there are %d resources 0-%d)\n", res, _totalResFiles, _totalResFiles - 1);
- 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!
- StandardHeader *file_header = (StandardHeader *) openResource(res);
-
- switch (file_header->fileType) {
- case ANIMATION_FILE:
- Debug_Printf("<anim> %s\n", file_header->name);
- break;
- case SCREEN_FILE:
- Debug_Printf("<layer> %s\n", file_header->name);
- break;
- case GAME_OBJECT:
- Debug_Printf("<game object> %s\n", file_header->name);
- break;
- case WALK_GRID_FILE:
- Debug_Printf("<walk grid> %s\n", file_header->name);
- break;
- case GLOBAL_VAR_FILE:
- Debug_Printf("<global variables> %s\n", file_header->name);
- break;
- case PARALLAX_FILE_null:
- Debug_Printf("<parallax file NOT USED!> %s\n", file_header->name);
- break;
- case RUN_LIST:
- Debug_Printf("<run list> %s\n", file_header->name);
- break;
- case TEXT_FILE:
- Debug_Printf("<text file> %s\n", file_header->name);
- break;
- case SCREEN_MANAGER:
- Debug_Printf("<screen manager> %s\n", file_header->name);
- break;
- case MOUSE_FILE:
- Debug_Printf("<mouse pointer> %s\n", file_header->name);
- break;
- case ICON_FILE:
- Debug_Printf("<menu icon> %s\n", file_header->name);
- break;
- default:
- Debug_Printf("unrecognised fileType %d\n", file_header->fileType);
- break;
- }
- closeResource(res);
- }
-}
-
-void ResourceManager::kill(int res) {
- if (res < 0 || res >= (int) _totalResFiles) {
- Debug_Printf("Illegal resource %d (there are %d resources 0-%d)\n", res, _totalResFiles, _totalResFiles - 1);
- return;
- }
-
- if (!_resList[res].ptr) {
- Debug_Printf("Resource %d is not in memory\n", res);
- return;
- }
-
- if (_resList[res].refCount) {
- Debug_Printf("Resource %d is open - cannot remove\n", res);
- return;
- }
-
- remove(res);
- Debug_Printf("Trashed %d\n", res);
-}
-
void ResourceManager::remove(int res) {
if (_resList[res].ptr) {
removeFromCacheList(_resList + res);
@@ -802,7 +687,7 @@ void ResourceManager::remove(int res) {
* the player object and global variables resource.
*/
-void ResourceManager::removeAll(void) {
+void ResourceManager::removeAll() {
// We need to clear the FX queue, because otherwise the sound system
// will still believe that the sound resources are in memory, and that
// it's ok to close them.
@@ -880,7 +765,7 @@ void ResourceManager::killAllObjects(bool wantInfo) {
Debug_Printf("Expelled %d resources\n", nuked);
}
-int ResourceManager::whichCd(void) {
+int ResourceManager::whichCd() {
return _curCd;
}
diff --git a/sword2/resman.h b/sword2/resman.h
index aca64e9627..1e50f91047 100644
--- a/sword2/resman.h
+++ b/sword2/resman.h
@@ -23,13 +23,21 @@
class File;
-namespace Sword2 {
-
#define MAX_MEM_CACHE (8 * 1024 * 1024) // we keep up to 8 megs of resource data files in memory
#define MAX_res_files 20
+namespace Sword2 {
+
class Sword2Engine;
+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.
+};
+
struct Resource {
byte *ptr;
uint32 size;
@@ -45,38 +53,12 @@ struct ResourceFile {
};
class ResourceManager {
-public:
- ResourceManager(Sword2Engine *vm); // read in the config file
- ~ResourceManager(void);
-
- byte *openResource(uint32 res, bool dump = false);
- void closeResource(uint32 res);
-
- bool checkValid(uint32 res);
- uint32 fetchLen(uint32 res);
-
- // Prompts the user for the specified CD.
- void getCd(int cd);
-
- int whichCd();
-
- void remove(int res);
-
- // ----console commands
-
- void printConsoleClusters(void);
- void listResources(uint minCount);
- void examine(int res);
- void kill(int res);
- void killAll(bool wantInfo);
- void killAllObjects(bool wantInfo);
- void removeAll(void);
private:
File *openCluFile(uint16 fileNum);
void readCluIndex(uint16 fileNum, File *file = NULL);
void removeFromCacheList(Resource *res);
void addToCacheList(Resource *res);
- void checkMemUsage(void);
+ void checkMemUsage();
Sword2Engine *_vm;
@@ -92,6 +74,34 @@ private:
Resource *_cacheStart, *_cacheEnd;
uint32 _usedMem; // amount of used memory in bytes
+
+public:
+ ResourceManager(Sword2Engine *vm); // read in the config file
+ ~ResourceManager();
+
+ uint32 getNumResFiles() { return _totalResFiles; }
+ uint32 getNumClusters() { return _totalClusters; }
+ ResourceFile *getResFiles() { return _resFiles; }
+ Resource *getResList() { return _resList; }
+
+ byte *openResource(uint32 res, bool dump = false);
+ void closeResource(uint32 res);
+
+ bool checkValid(uint32 res);
+ uint32 fetchLen(uint32 res);
+
+ // Prompts the user for the specified CD.
+ void getCd(int cd);
+
+ int whichCd();
+
+ void remove(int res);
+ void removeAll();
+
+ // ----console commands
+
+ void killAll(bool wantInfo);
+ void killAllObjects(bool wantInfo);
};
} // End of namespace Sword2
diff --git a/sword2/startup.cpp b/sword2/startup.cpp
index d7ae9419ea..5073e4c009 100644
--- a/sword2/startup.cpp
+++ b/sword2/startup.cpp
@@ -22,7 +22,6 @@
#include "common/file.h"
#include "sword2/sword2.h"
-#include "sword2/console.h"
#include "sword2/defs.h"
#include "sword2/interpreter.h"
#include "sword2/logic.h"
@@ -32,8 +31,6 @@
#include "sword2/router.h"
#include "sword2/sound.h"
-#define Debug_Printf _debugger->DebugPrintf
-
namespace Sword2 {
bool Sword2Engine::initStartMenu() {
@@ -145,37 +142,7 @@ void Sword2Engine::registerStartPoint(int32 key, char *name) {
_totalStartups++;
}
-/**
- * The console 'starts' (or 's') command which lists out all the registered
- * start points in the game.
- */
-
-void Sword2Engine::conPrintStartMenu() {
- if (!_totalStartups) {
- Debug_Printf("Sorry - no startup positions registered?\n");
-
- if (!_totalScreenManagers)
- Debug_Printf("There is a problem with startup.inf\n");
- else
- Debug_Printf(" (%d screen managers found in startup.inf)\n", _totalScreenManagers);
- return;
- }
-
- for (uint i = 0; i < _totalStartups; i++)
- Debug_Printf("%d (%s)\n", i, _startList[i].description);
-}
-
-void Sword2Engine::conStart(int start) {
- if (!_totalStartups) {
- Debug_Printf("Sorry - there are no startups!\n");
- return;
- }
-
- if (start < 0 || start >= (int) _totalStartups) {
- Debug_Printf("Not a legal start position\n");
- return;
- }
-
+void Sword2Engine::runStart(int start) {
// Restarting - stop sfx, music & speech!
_sound->clearFxQueue();
@@ -207,7 +174,6 @@ void Sword2Engine::conStart(int start) {
// Denotes script to run
uint32 null_pc = _startList[start].key & 0xffff;
- Debug_Printf("Running start %d\n", start);
_logic->runScript(raw_script, raw_data_ad, &null_pc);
_resman->closeResource(_startList[start].start_res_id);
diff --git a/sword2/sword2.h b/sword2/sword2.h
index 8a30dad63e..23a0d25342 100644
--- a/sword2/sword2.h
+++ b/sword2/sword2.h
@@ -85,6 +85,17 @@ struct KeyboardEvent {
int modifiers;
};
+struct StartUp {
+ char description[MAX_description];
+
+ // id of screen manager object
+ uint32 start_res_id;
+
+ // Tell the manager which startup you want (if there are more than 1)
+ // (i.e more than 1 entrance to a screen and/or separate game boots)
+ uint32 key;
+};
+
class Sword2Engine : public Engine {
private:
uint32 _eventFilter;
@@ -113,18 +124,6 @@ private:
bool _useSubtitles;
- struct StartUp {
- char description[MAX_description];
-
- // id of screen manager object
- uint32 start_res_id;
-
- // tell the manager which startup you want (if there are more
- // than 1) (i.e more than 1 entrance to a screen and/or
- // separate game boots)
- uint32 key;
- };
-
StartUp _startList[MAX_starts];
public:
@@ -256,8 +255,12 @@ public:
bool initStartMenu();
void registerStartPoint(int32 key, char *name);
- void conPrintStartMenu();
- void conStart(int start);
+
+ uint32 getNumStarts() { return _totalStartups; }
+ uint32 getNumScreenManagers() { return _totalScreenManagers; }
+ StartUp *getStartList() { return _startList; }
+
+ void runStart(int start);
// Convenience alias for OSystem::getMillis().
// This is a bit hackish, of course :-).