diff options
author | Torbjörn Andersson | 2003-11-02 15:58:45 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2003-11-02 15:58:45 +0000 |
commit | db9b8070f6750a204c5d6e95c60ecbbac7ef848c (patch) | |
tree | fc819401ca76f7762499e878e1d90b82338e1950 /sword2 | |
parent | e9ae86bb76bf6087a1bb11f6158fd96676572866 (diff) | |
download | scummvm-rg350-db9b8070f6750a204c5d6e95c60ecbbac7ef848c.tar.gz scummvm-rg350-db9b8070f6750a204c5d6e95c60ecbbac7ef848c.tar.bz2 scummvm-rg350-db9b8070f6750a204c5d6e95c60ecbbac7ef848c.zip |
More moving of stuff into classes. I had to make a few changes/cleanups to
events.cpp, so there could be regressions.
svn-id: r11053
Diffstat (limited to 'sword2')
-rw-r--r-- | sword2/build_display.cpp | 20 | ||||
-rw-r--r-- | sword2/console.cpp | 139 | ||||
-rw-r--r-- | sword2/console.h | 49 | ||||
-rw-r--r-- | sword2/debug.cpp | 217 | ||||
-rw-r--r-- | sword2/debug.h | 36 | ||||
-rw-r--r-- | sword2/events.cpp | 261 | ||||
-rw-r--r-- | sword2/events.h | 14 | ||||
-rw-r--r-- | sword2/function.cpp | 21 | ||||
-rw-r--r-- | sword2/function.h | 5 | ||||
-rw-r--r-- | sword2/icons.cpp | 60 | ||||
-rw-r--r-- | sword2/icons.h | 13 | ||||
-rw-r--r-- | sword2/logic.h | 1 | ||||
-rw-r--r-- | sword2/mouse.cpp | 59 | ||||
-rw-r--r-- | sword2/sound.cpp | 2 | ||||
-rw-r--r-- | sword2/speech.cpp | 8 | ||||
-rw-r--r-- | sword2/sword2.cpp | 30 | ||||
-rw-r--r-- | sword2/sword2.h | 36 | ||||
-rw-r--r-- | sword2/walker.cpp | 22 |
18 files changed, 456 insertions, 537 deletions
diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp index 0eedd87d62..c6ede1aaef 100644 --- a/sword2/build_display.cpp +++ b/sword2/build_display.cpp @@ -155,7 +155,7 @@ void Sword2Engine::buildDisplay(void) { // walkgrid, mouse & player markers & mouse area // rectangle - Draw_debug_graphics(); + _debugger->drawDebugGraphics(); // text blocks @@ -205,7 +205,7 @@ void Sword2Engine::displayMsg(uint8 *text, int time) { _palEntry oldPal[256]; uint32 rv; // drivers error return value - warning("DisplayMsg: %s", (char *) text); + debug(2, "DisplayMsg: %s", (char *) text); if (g_display->getFadeStatus() != RDFADE_BLACK) { g_display->fadeDown(); @@ -499,10 +499,10 @@ void Sword2Engine::processImage(buildit *build_unit) { spriteInfo.y = 1; // create box to surround sprite - just outside sprite box - rect_x1 = spriteInfo.x - 1; - rect_y1 = spriteInfo.y - 1; - rect_x2 = spriteInfo.x + spriteInfo.scaledWidth; - rect_y2 = spriteInfo.y + spriteInfo.scaledHeight; + _debugger->_rectX1 = spriteInfo.x - 1; + _debugger->_rectY1 = spriteInfo.y - 1; + _debugger->_rectX2 = spriteInfo.x + spriteInfo.scaledWidth; + _debugger->_rectY2 = spriteInfo.y + spriteInfo.scaledHeight; } // #ifdef _SWORD2_DEBUG @@ -588,11 +588,11 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) { // update player graphic details for on-screen debug info if (ID == CUR_PLAYER_ID) { - playerGraphic.type = ob_graph->type; - playerGraphic.anim_resource = ob_graph->anim_resource; + _debugger->_playerGraphic.type = ob_graph->type; + _debugger->_playerGraphic.anim_resource = ob_graph->anim_resource; // counting 1st frame as 'frame 1' - playerGraphic.anim_pc = ob_graph->anim_pc + 1; - player_graphic_no_frames = anim_head->noAnimFrames; + _debugger->_playerGraphic.anim_pc = ob_graph->anim_pc + 1; + _debugger->_playerGraphicNoFrames = anim_head->noAnimFrames; } // fill in the buildit structure for this frame diff --git a/sword2/console.cpp b/sword2/console.cpp index db54937152..cd09bf192f 100644 --- a/sword2/console.cpp +++ b/sword2/console.cpp @@ -35,13 +35,11 @@ namespace Sword2 { -bool wantSfxDebug = false; // sfx debug enabled/disabled from console - -static void Var_check(int var) { +void Debugger::varGet(int var) { Debug_Printf("%d\n", VAR(var)); } -static void Var_set(int var, int val) { +void Debugger::varSet(int var, int val) { Debug_Printf("was %d, ", VAR(var)); VAR(var) = val; Debug_Printf("now %d\n", VAR(var)); @@ -51,6 +49,36 @@ Debugger::Debugger(Sword2Engine *s) : Common::Debugger<Debugger>() { _vm = s; + memset(_debugTextBlocks, 0, sizeof(_debugTextBlocks)); + memset(_showVar, 0, sizeof(_showVar)); + + _displayDebugText = false; // "INFO" + _displayWalkGrid = false; // "WALKGRID" + _displayMouseMarker = false; // "MOUSE" + _displayTime = false; // "TIME" + _displayPlayerMarker = false; // "PLAYER" + _displayTextNumbers = false; // "TEXT" + + _definingRectangles = false; // "RECT" + _draggingRectangle = 0; // 0 = waiting to start new rect + // 1 = currently dragging a rectangle + + _rectX1 = _rectY1 = 0; + _rectX2 = _rectY2 = 0; + _rectFlicker = false; + + _testingSnR = false; // "SAVEREST" - for system to kill all + // object resources (except player) in + // fnAddHuman() + + _startTime = 0; // "TIMEON" & "TIMEOFF" - system start + // time + + _textNumber = 0; // Current system text line number + + _playerGraphicNoFrames = 0; // No. of frames in currently displayed + // anim + // Register commands DCmd_Register("continue", &Debugger::Cmd_Exit); @@ -121,7 +149,6 @@ void Debugger::postEnter() { } - /////////////////////////////////////////////////// // Now the fun stuff: @@ -188,9 +215,9 @@ bool Debugger::Cmd_Start(int argc, const char **argv) { } bool Debugger::Cmd_Info(int argc, const char **argv) { - displayDebugText = !displayDebugText; + _displayDebugText = !_displayDebugText; - if (displayDebugText) + if (_displayDebugText) DebugPrintf("Info text on\n"); else DebugPrintf("Info Text off\n"); @@ -199,9 +226,9 @@ bool Debugger::Cmd_Info(int argc, const char **argv) { } bool Debugger::Cmd_WalkGrid(int argc, const char **argv) { - displayWalkGrid = !displayWalkGrid; + _displayWalkGrid = !_displayWalkGrid; - if (displayWalkGrid) + if (_displayWalkGrid) DebugPrintf("Walk-grid display on\n"); else DebugPrintf("Walk-grid display off\n"); @@ -210,9 +237,9 @@ bool Debugger::Cmd_WalkGrid(int argc, const char **argv) { } bool Debugger::Cmd_Mouse(int argc, const char **argv) { - displayMouseMarker = !displayMouseMarker; + _displayMouseMarker = !_displayMouseMarker; - if (displayMouseMarker) + if (_displayMouseMarker) DebugPrintf("Mouse marker on\n"); else DebugPrintf("Mouse marker off\n"); @@ -221,9 +248,9 @@ bool Debugger::Cmd_Mouse(int argc, const char **argv) { } bool Debugger::Cmd_Player(int argc, const char **argv) { - displayPlayerMarker = !displayPlayerMarker; + _displayPlayerMarker = !_displayPlayerMarker; - if (displayPlayerMarker) + if (_displayPlayerMarker) DebugPrintf("Player feet marker on\n"); else DebugPrintf("Player feet marker off\n"); @@ -240,7 +267,7 @@ bool Debugger::Cmd_ResLook(int argc, const char **argv) { } bool Debugger::Cmd_CurrentInfo(int argc, const char **argv) { - Print_current_info(); + printCurrentInfo(); return true; } @@ -266,10 +293,10 @@ bool Debugger::Cmd_Nuke(int argc, const char **argv) { bool Debugger::Cmd_Var(int argc, const char **argv) { switch (argc) { case 2: - Var_check(atoi(argv[1])); + varGet(atoi(argv[1])); break; case 3: - Var_set(atoi(argv[1]), atoi(argv[2])); + varSet(atoi(argv[1]), atoi(argv[2])); break; default: DebugPrintf("Usage: %s number value\n", argv[0]); @@ -280,14 +307,14 @@ bool Debugger::Cmd_Var(int argc, const char **argv) { } bool Debugger::Cmd_Rect(int argc, const char **argv) { - definingRectangles = !definingRectangles; + _definingRectangles = !_definingRectangles; - if (definingRectangles) + if (_definingRectangles) DebugPrintf("Mouse rectangles enabled\n"); else DebugPrintf("Mouse rectangles disabled\n"); - draggingRectangle = 0; + _draggingRectangle = 0; return true; } @@ -297,29 +324,29 @@ bool Debugger::Cmd_Clear(int argc, const char **argv) { } bool Debugger::Cmd_DebugOn(int argc, const char **argv) { - displayDebugText = true; - displayWalkGrid = true; - displayMouseMarker = true; - displayPlayerMarker = true; - displayTextNumbers = true; + _displayDebugText = true; + _displayWalkGrid = true; + _displayMouseMarker = true; + _displayPlayerMarker = true; + _displayTextNumbers = true; DebugPrintf("Enabled all on-screen debug info\n"); return true; } bool Debugger::Cmd_DebugOff(int argc, const char **argv) { - displayDebugText = false; - displayWalkGrid = false; - displayMouseMarker = false; - displayPlayerMarker = false; - displayTextNumbers = false; + _displayDebugText = false; + _displayWalkGrid = false; + _displayMouseMarker = false; + _displayPlayerMarker = false; + _displayTextNumbers = false; DebugPrintf("Disabled all on-screen debug info\n"); return true; } bool Debugger::Cmd_SaveRest(int argc, const char **argv) { - testingSnR = !testingSnR; + _testingSnR = !_testingSnR; - if (testingSnR) + if (_testingSnR) DebugPrintf("Enabled S&R logic_script stability checking\n"); else DebugPrintf("Disabled S&R logic_script stability checking\n"); @@ -440,24 +467,24 @@ bool Debugger::Cmd_BltFxOff(int argc, const char **argv) { bool Debugger::Cmd_TimeOn(int argc, const char **argv) { if (argc == 2) - startTime = SVM_timeGetTime() - atoi(argv[1]) * 1000; - else if (startTime == 0) - startTime = SVM_timeGetTime(); - displayTime = true; + _startTime = SVM_timeGetTime() - atoi(argv[1]) * 1000; + else if (_startTime == 0) + _startTime = SVM_timeGetTime(); + _displayTime = true; DebugPrintf("Timer display on\n"); return true; } bool Debugger::Cmd_TimeOff(int argc, const char **argv) { - displayTime = false; + _displayTime = false; DebugPrintf("Timer display off\n"); return true; } bool Debugger::Cmd_Text(int argc, const char **argv) { - displayTextNumbers = !displayTextNumbers; + _displayTextNumbers = !_displayTextNumbers; - if (displayTextNumbers) + if (_displayTextNumbers) DebugPrintf("Text numbers on\n"); else DebugPrintf("Text numbers off\n"); @@ -479,14 +506,14 @@ bool Debugger::Cmd_ShowVar(int argc, const char **argv) { // search for a spare slot in the watch-list, but also watch out for // this variable already being in the list - while (showVarNo < MAX_SHOWVARS && showVar[showVarNo] != 0 && showVar[showVarNo] != varNo) + while (showVarNo < MAX_SHOWVARS && _showVar[showVarNo] != 0 && _showVar[showVarNo] != varNo) showVarNo++; // if we've found a spare slot or the variable's already there if (showVarNo < MAX_SHOWVARS) { - if (showVar[showVarNo] == 0) { + if (_showVar[showVarNo] == 0) { // empty slot - add it to the list at this slot - showVar[showVarNo] = varNo; + _showVar[showVarNo] = varNo; DebugPrintf("var(%d) added to the watch-list\n", varNo); } else DebugPrintf("var(%d) already in the watch-list!\n", varNo); @@ -508,12 +535,12 @@ bool Debugger::Cmd_HideVar(int argc, const char **argv) { varNo = atoi(argv[1]); // search for 'varNo' in the watch-list - while (showVarNo < MAX_SHOWVARS && showVar[showVarNo] != varNo) + while (showVarNo < MAX_SHOWVARS && _showVar[showVarNo] != varNo) showVarNo++; if (showVarNo < MAX_SHOWVARS) { // We've found 'varNo' in the list - clear this slot - showVar[showVarNo] = 0; + _showVar[showVarNo] = 0; DebugPrintf("var(%d) removed from watch-list\n", varNo); } else DebugPrintf("Sorry - can't find var(%d) in the list\n", varNo); @@ -588,7 +615,7 @@ bool Debugger::Cmd_AnimTest(int argc, const char **argv) { Con_start(32); // Same as typing "VAR 912 <value>" at the console - Var_set(912, atoi(argv[1])); + varSet(912, atoi(argv[1])); DebugPrintf("Setting flag 'system_testing_anims'\n"); return true; @@ -604,9 +631,9 @@ bool Debugger::Cmd_TextTest(int argc, const char **argv) { Con_start(33); // Same as typing "VAR 1230 <value>" at the console - Var_set(1230, atoi(argv[1])); + varSet(1230, atoi(argv[1])); - displayTextNumbers = true; + _displayTextNumbers = true; DebugPrintf("Setting flag 'system_testing_text'\n"); DebugPrintf("Text numbers on\n"); @@ -623,12 +650,12 @@ bool Debugger::Cmd_LineTest(int argc, const char **argv) { Con_start(33); // Same as typing "VAR 1230 <value>" at the console - Var_set(1230, atoi(argv[1])); + varSet(1230, atoi(argv[1])); // Same as typing "VAR 1264 <value>" at the console - Var_set(1264, atoi(argv[2])); + varSet(1264, atoi(argv[2])); - displayTextNumbers = true; + _displayTextNumbers = true; DebugPrintf("Setting flag 'system_testing_text'\n"); DebugPrintf("Setting flag 'system_test_line_no'\n"); @@ -640,9 +667,9 @@ bool Debugger::Cmd_Grab(int argc, const char **argv) { DebugPrintf("FIXME: Continuous screen-grabbing not implemented\n"); #if 0 - grabbingSequences = !grabbingSequences; + g_sword2->_grabbingSequences = !g_sword2->_grabbingSequences; - if (grabbingSequences) + if (g_sword2->_grabbingSequences) DebugPrintf("PCX-grabbing enabled\n"); else DebugPrintf("PCX-grabbing disabled\n"); @@ -655,9 +682,9 @@ bool Debugger::Cmd_Events(int argc, const char **argv) { DebugPrintf("EVENT LIST:\n"); for (uint32 i = 0; i < MAX_events; i++) { - if (event_list[i].id) { - uint32 target = event_list[i].id; - uint32 script = event_list[i].interact_id; + if (g_sword2->_eventList[i].id) { + 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); @@ -668,9 +695,9 @@ bool Debugger::Cmd_Events(int argc, const char **argv) { } bool Debugger::Cmd_Sfx(int argc, const char **argv) { - wantSfxDebug = !wantSfxDebug; + g_sword2->_wantSfxDebug = !g_sword2->_wantSfxDebug; - if (wantSfxDebug) + if (g_sword2->_wantSfxDebug) DebugPrintf("SFX logging activated\n"); else DebugPrintf("SFX logging deactivated\n"); diff --git a/sword2/console.h b/sword2/console.h index f81456c8dd..047bc0cba6 100644 --- a/sword2/console.h +++ b/sword2/console.h @@ -21,21 +21,62 @@ #define C_ONSOLE_H #include "common/debugger.h" -#include "sword2/memory.h" +#include "sword2/debug.h" +#include "sword2/object.h" #define Debug_Printf g_sword2->_debugger->DebugPrintf namespace Sword2 { -extern bool grabbingSequences; -extern bool wantSfxDebug; // sfx debug file enabled/disabled from console - class Sword2Engine; class Debugger : public Common::Debugger<Debugger> { +private: + void varGet(int var); + void varSet(int var, int val); + + bool _displayDebugText; + bool _displayWalkGrid; + bool _displayMouseMarker; + bool _displayTime; + bool _displayPlayerMarker; + bool _displayTextNumbers; + + bool _rectFlicker; + + int32 _startTime; + + int32 _showVar[MAX_SHOWVARS]; + + uint8 _debugTextBlocks[MAX_DEBUG_TEXT_BLOCKS]; + + void clearDebugTextBlocks(void); + 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); + public: Debugger(Sword2Engine *s); + int16 _rectX1, _rectY1; + int16 _rectX2, _rectY2; + + uint8 _draggingRectangle; + bool _definingRectangles; + + bool _testingSnR; + + int32 _textNumber; + + Object_graphic _playerGraphic; + uint32 _playerGraphicNoFrames; + + void buildDebugText(void); + void drawDebugGraphics(void); + protected: Sword2Engine *_vm; diff --git a/sword2/debug.cpp b/sword2/debug.cpp index f1d6ef60db..098072c06c 100644 --- a/sword2/debug.cpp +++ b/sword2/debug.cpp @@ -36,75 +36,32 @@ namespace Sword2 { -bool displayDebugText = false; // "INFO" -bool displayWalkGrid = false; // "WALKGRID" -bool displayMouseMarker = false; // "MOUSE" -bool displayTime = false; // "TIME" -bool displayPlayerMarker = false; // "PLAYER" -bool displayTextNumbers = false; // "TEXT" -uint8 renderSkip = 0; // Toggled on 'S' key - to render only - // 1 in 4 frames, to speed up game - -bool definingRectangles = false; // "RECT" -uint8 draggingRectangle = 0; // 0 = waiting to start new rect; - // 1 = currently dragging a rectangle -int16 rect_x1 = 0; -int16 rect_y1 = 0; -int16 rect_x2 = 0; -int16 rect_y2 = 0; -bool rectFlicker = false; - -bool testingSnR = false; // "SAVEREST" - for system to kill all - // object resources (except player) in - // fnAddHuman() - -int32 startTime = 0; // "TIMEON" & "TIMEOFF" - system start - // time. -int32 gameCycle = 0; // Counter for game clocks. - -int32 textNumber = 0; // Current system text line number - -int32 showVar[MAX_SHOWVARS]; // "SHOWVAR" - -Object_graphic playerGraphic; // For displaying player object's - // current graphical info -uint32 player_graphic_no_frames = 0; // No. of frames in currently displayed - // anim - -uint8 debug_text_blocks[MAX_DEBUG_TEXT_BLOCKS]; - -void Clear_debug_text_blocks(void); -void Make_debug_text_block(char *text, int16 x, int16 y); -void Plot_cross_hair(int16 x, int16 y, uint8 pen); -void DrawRect(int16 x, int16 y, int16 x2, int16 y2, uint8 pen); - -void Clear_debug_text_blocks(void) { +void Debugger::clearDebugTextBlocks(void) { uint8 blockNo = 0; - while (blockNo < MAX_DEBUG_TEXT_BLOCKS && debug_text_blocks[blockNo] > 0) { + while (blockNo < MAX_DEBUG_TEXT_BLOCKS && _debugTextBlocks[blockNo] > 0) { // kill the system text block - fontRenderer.killTextBloc(debug_text_blocks[blockNo]); + fontRenderer.killTextBloc(_debugTextBlocks[blockNo]); // clear this element of our array of block numbers - debug_text_blocks[blockNo] = 0; + _debugTextBlocks[blockNo] = 0; blockNo++; } } -void Make_debug_text_block(char *text, int16 x, int16 y) { +void Debugger::makeDebugTextBlock(char *text, int16 x, int16 y) { uint8 blockNo = 0; - while (blockNo < MAX_DEBUG_TEXT_BLOCKS && debug_text_blocks[blockNo] > 0) + while (blockNo < MAX_DEBUG_TEXT_BLOCKS && _debugTextBlocks[blockNo] > 0) blockNo++; - if (blockNo == MAX_DEBUG_TEXT_BLOCKS) - error("ERROR: debug_text_blocks[] full in Make_debug_text_block()"); + assert(blockNo < MAX_DEBUG_TEXT_BLOCKS); - debug_text_blocks[blockNo] = fontRenderer.buildNewBloc((uint8 *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION); + _debugTextBlocks[blockNo] = fontRenderer.buildNewBloc((uint8 *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION); } -void Build_debug_text(void) { +void Debugger::buildDebugText(void) { char buf[128]; int32 showVarNo; // for variable watching @@ -113,7 +70,7 @@ void Build_debug_text(void) { int32 *varTable; // clear the array of text block numbers for the debug text - Clear_debug_text_blocks(); + clearDebugTextBlocks(); // mouse coords /* @@ -121,82 +78,82 @@ void Build_debug_text(void) { if (displayMouseMarker) { sprintf(buf, "%d,%d", mousex + this_screen.scroll_offset_x, mousey + this_screen.scroll_offset_y); if (mousex>560) - Make_debug_text_block(buf, mousex - 50, mousey - 15); + makeDebugTextBlock(buf, mousex - 50, mousey - 15); else - Make_debug_text_block(buf, mousex + 5, mousey - 15); + makeDebugTextBlock(buf, mousex + 5, mousey - 15); } */ // mouse area coords // defining a mouse area the easy way, by creating a box on-screen - if (draggingRectangle || SYSTEM_TESTING_ANIMS) { + if (_draggingRectangle || SYSTEM_TESTING_ANIMS) { // so we can see what's behind the lines - rectFlicker = !rectFlicker; + _rectFlicker = !_rectFlicker; - sprintf (buf, "x1=%d", rect_x1); - Make_debug_text_block(buf, 0, 120); + sprintf(buf, "x1=%d", _rectX1); + makeDebugTextBlock(buf, 0, 120); - sprintf (buf, "y1=%d", rect_y1); - Make_debug_text_block(buf, 0, 135); + sprintf(buf, "y1=%d", _rectY1); + makeDebugTextBlock(buf, 0, 135); - sprintf (buf, "x2=%d", rect_x2); - Make_debug_text_block(buf, 0, 150); + sprintf(buf, "x2=%d", _rectX2); + makeDebugTextBlock(buf, 0, 150); - sprintf (buf, "y2=%d", rect_y2); - Make_debug_text_block(buf, 0, 165); + sprintf(buf, "y2=%d", _rectY2); + makeDebugTextBlock(buf, 0, 165); } // testingSnR indicator - if (testingSnR) { // see fnAddHuman() - sprintf (buf, "TESTING LOGIC STABILITY!"); - Make_debug_text_block(buf, 0, 105); + if (_testingSnR) { // see fnAddHuman() + sprintf(buf, "TESTING LOGIC STABILITY!"); + makeDebugTextBlock(buf, 0, 105); } // speed-up indicator - if (renderSkip) { // see sword.cpp - sprintf (buf, "SKIPPING FRAMES FOR SPEED-UP!"); - Make_debug_text_block(buf, 0, 120); + if (g_sword2->_renderSkip) { // see sword.cpp + sprintf(buf, "SKIPPING FRAMES FOR SPEED-UP!"); + makeDebugTextBlock(buf, 0, 120); } // debug info at top of screen - enabled/disabled as one complete unit - if (displayTime) { + if (_displayTime) { int32 time = SVM_timeGetTime(); - if ((time - startTime) / 1000 >= 10000) - startTime = time; + if ((time - _startTime) / 1000 >= 10000) + _startTime = time; - time -= startTime; + time -= _startTime; sprintf(buf, "Time %.2d:%.2d:%.2d.%.3d", (time / 3600000) % 60, (time / 60000) % 60, (time / 1000) % 60, time % 1000); - Make_debug_text_block(buf, 500, 360); - sprintf(buf, "Game %d", gameCycle); - Make_debug_text_block(buf, 500, 380); + makeDebugTextBlock(buf, 500, 360); + sprintf(buf, "Game %d", g_sword2->_gameCycle); + makeDebugTextBlock(buf, 500, 380); } // current text number & speech-sample resource id - if (displayTextNumbers) { - if (textNumber) { + if (_displayTextNumbers) { + if (_textNumber) { if (SYSTEM_TESTING_TEXT) { if (SYSTEM_WANT_PREVIOUS_LINE) sprintf(buf, "backwards"); else sprintf(buf, "forwards"); - Make_debug_text_block(buf, 0, 340); + makeDebugTextBlock(buf, 0, 340); } - sprintf(buf, "res: %d", textNumber / SIZE); - Make_debug_text_block(buf, 0, 355); + sprintf(buf, "res: %d", _textNumber / SIZE); + makeDebugTextBlock(buf, 0, 355); - sprintf(buf, "pos: %d", textNumber & 0xffff); - Make_debug_text_block(buf, 0, 370); + sprintf(buf, "pos: %d", _textNumber & 0xffff); + makeDebugTextBlock(buf, 0, 370); sprintf(buf, "TEXT: %d", officialTextNumber); - Make_debug_text_block(buf, 0, 385); + makeDebugTextBlock(buf, 0, 385); } } @@ -204,16 +161,16 @@ void Build_debug_text(void) { if (SYSTEM_TESTING_ANIMS) { sprintf(buf, "trying resource %d", SYSTEM_TESTING_ANIMS); - Make_debug_text_block(buf, 0, 90); + makeDebugTextBlock(buf, 0, 90); } // general debug info - if (displayDebugText) { + if (_displayDebugText) { /* // CD in use - sprintf (buf, "CD-%d", currentCD); - Make_debug_text_block(buf, 0, 0); + sprintf(buf, "CD-%d", currentCD); + makeDebugTextBlock(buf, 0, 0); */ // mouse coords & object pointed to @@ -226,7 +183,7 @@ void Build_debug_text(void) { sprintf(buf, "last click at %d,%d (---)", MOUSE_X, MOUSE_Y); - Make_debug_text_block(buf, 0, 15); + makeDebugTextBlock(buf, 0, 15); if (mouse_touching) sprintf(buf, "mouse %d,%d (id %d: %s)", @@ -239,75 +196,75 @@ void Build_debug_text(void) { g_display->_mouseX + this_screen.scroll_offset_x, g_display->_mouseY + this_screen.scroll_offset_y); - Make_debug_text_block(buf, 0, 30); + makeDebugTextBlock(buf, 0, 30); // player coords & graphic info // if player objct has a graphic - if (playerGraphic.anim_resource) + if (_playerGraphic.anim_resource) sprintf(buf, "player %d,%d %s (%d) #%d/%d", this_screen.player_feet_x, this_screen.player_feet_y, - FetchObjectName(playerGraphic.anim_resource), - playerGraphic.anim_resource, - playerGraphic.anim_pc, - player_graphic_no_frames); + FetchObjectName(_playerGraphic.anim_resource), + _playerGraphic.anim_resource, + _playerGraphic.anim_pc, + _playerGraphicNoFrames); else sprintf(buf, "player %d,%d --- %d", this_screen.player_feet_x, this_screen.player_feet_y, - playerGraphic.anim_pc); + _playerGraphic.anim_pc); - Make_debug_text_block(buf, 0, 45); + makeDebugTextBlock(buf, 0, 45); // frames-per-second counter sprintf(buf, "fps %d", g_sword2->_fps); - Make_debug_text_block(buf, 440, 0); + makeDebugTextBlock(buf, 440, 0); // location number sprintf(buf, "location=%d", LOCATION); - Make_debug_text_block(buf, 440, 15); + makeDebugTextBlock(buf, 440, 15); // "result" variable sprintf(buf, "result=%d", RESULT); - Make_debug_text_block(buf, 440, 30); + makeDebugTextBlock(buf, 440, 30); // no. of events in event list - sprintf(buf, "events=%d", CountEvents()); - Make_debug_text_block(buf, 440, 45); + sprintf(buf, "events=%d", g_sword2->countEvents()); + makeDebugTextBlock(buf, 440, 45); // sprite list usage sprintf(buf, "bgp0: %d/%d", g_sword2->_curBgp0, MAX_bgp0_sprites); - Make_debug_text_block(buf, 560, 0); + makeDebugTextBlock(buf, 560, 0); sprintf(buf, "bgp1: %d/%d", g_sword2->_curBgp1, MAX_bgp1_sprites); - Make_debug_text_block(buf, 560, 15); + makeDebugTextBlock(buf, 560, 15); sprintf(buf, "back: %d/%d", g_sword2->_curBack, MAX_back_sprites); - Make_debug_text_block(buf, 560, 30); + makeDebugTextBlock(buf, 560, 30); sprintf(buf, "sort: %d/%d", g_sword2->_curSort, MAX_sort_sprites); - Make_debug_text_block(buf, 560, 45); + makeDebugTextBlock(buf, 560, 45); sprintf(buf, "fore: %d/%d", g_sword2->_curFore, MAX_fore_sprites); - Make_debug_text_block(buf, 560, 60); + makeDebugTextBlock(buf, 560, 60); sprintf(buf, "fgp0: %d/%d", g_sword2->_curFgp0, MAX_fgp0_sprites); - Make_debug_text_block(buf, 560, 75); + makeDebugTextBlock(buf, 560, 75); sprintf(buf, "fgp1: %d/%d", g_sword2->_curFgp1, MAX_fgp1_sprites); - Make_debug_text_block(buf, 560, 90); + makeDebugTextBlock(buf, 560, 90); // largest layer & sprite // NB. Strings already constructed in Build_display.cpp - Make_debug_text_block(g_sword2->_largestLayerInfo, 0, 60); - Make_debug_text_block(g_sword2->_largestSpriteInfo, 0, 75); + makeDebugTextBlock(g_sword2->_largestLayerInfo, 0, 60); + makeDebugTextBlock(g_sword2->_largestSpriteInfo, 0, 75); // "waiting for person" indicator - set form fnTheyDo and // fnTheyDoWeWait @@ -316,7 +273,7 @@ void Build_debug_text(void) { sprintf(buf, "script waiting for %s (%d)", FetchObjectName(speechScriptWaiting), speechScriptWaiting); - Make_debug_text_block(buf, 0, 90); + makeDebugTextBlock(buf, 0, 90); } // variable watch display @@ -327,14 +284,14 @@ void Build_debug_text(void) { varTable = (int32 *) (res_man.open(1) + sizeof(_standardHeader)); for (showVarNo = 0; showVarNo < MAX_SHOWVARS; showVarNo++) { - varNo = showVar[showVarNo]; // get variable number + varNo = _showVar[showVarNo]; // get variable number // if non-zero ie. cannot watch 'id' but not needed // anyway because it changes throughout the logic loop if (varNo) { sprintf(buf, "var(%d) = %d", varNo, varTable[varNo]); - Make_debug_text_block(buf, 530, showVarPos); + makeDebugTextBlock(buf, 530, showVarPos); showVarPos += 15; // next line down } } @@ -345,40 +302,40 @@ void Build_debug_text(void) { // sprite blocks above! memory.memoryString(buf); - Make_debug_text_block(buf, 0, 0); + makeDebugTextBlock(buf, 0, 0); } } -void Draw_debug_graphics(void) { +void Debugger::drawDebugGraphics(void) { // walk-grid - if (displayWalkGrid) + if (_displayWalkGrid) router.plotWalkGrid(); // player feet coord marker - if (displayPlayerMarker) - Plot_cross_hair(this_screen.player_feet_x, this_screen.player_feet_y, 215); + if (_displayPlayerMarker) + plotCrossHair(this_screen.player_feet_x, this_screen.player_feet_y, 215); // mouse marker & coords - if (displayMouseMarker) - Plot_cross_hair(g_display->_mouseX + this_screen.scroll_offset_x, g_display->_mouseY + this_screen.scroll_offset_y, 215); + if (_displayMouseMarker) + plotCrossHair(g_display->_mouseX + this_screen.scroll_offset_x, g_display->_mouseY + this_screen.scroll_offset_y, 215); // mouse area rectangle / sprite box rectangle when testing anims if (SYSTEM_TESTING_ANIMS) { // draw box around current frame - DrawRect(rect_x1, rect_y1, rect_x2, rect_y2, 184); - } else if (draggingRectangle) { + drawRect(_rectX1, _rectY1, _rectX2, _rectY2, 184); + } else if (_draggingRectangle) { // defining a mouse area the easy way, by creating a box // on-screen - if (rectFlicker) - DrawRect(rect_x1, rect_y1, rect_x2, rect_y2, 184); + if (_rectFlicker) + drawRect(_rectX1, _rectY1, _rectX2, _rectY2, 184); } } -void Plot_cross_hair(int16 x, int16 y, uint8 pen) { +void Debugger::plotCrossHair(int16 x, int16 y, uint8 pen) { g_display->plotPoint(x, y, pen); // driver function g_display->drawLine(x - 2, y, x - 5, y, pen); // driver function @@ -388,14 +345,14 @@ void Plot_cross_hair(int16 x, int16 y, uint8 pen) { g_display->drawLine(x, y + 2, x, y + 5, pen); } -void DrawRect(int16 x1, int16 y1, int16 x2, int16 y2, uint8 pen) { +void Debugger::drawRect(int16 x1, int16 y1, int16 x2, int16 y2, uint8 pen) { g_display->drawLine(x1, y1, x2, y1, pen); // top edge g_display->drawLine(x1, y2, x2, y2, pen); // bottom edge g_display->drawLine(x1, y1, x1, y2, pen); // left edge g_display->drawLine(x2, y1, x2, y2, pen); // right edge } -void Print_current_info(void) { +void Debugger::printCurrentInfo(void) { // prints general stuff about the screen, etc. if (this_screen.background_layer_id) { diff --git a/sword2/debug.h b/sword2/debug.h index 78b5c1912f..63c6451b1b 100644 --- a/sword2/debug.h +++ b/sword2/debug.h @@ -20,46 +20,12 @@ #ifndef D_DEBUG #define D_DEBUG -#include "sword2/object.h" - // FIXME: I don't know how large this constant used to be #define MAX_DEBUG_TEXT_BLOCKS 50 -namespace Sword2 { - -extern bool displayDebugText; -extern bool displayWalkGrid; -extern bool displayMouseMarker; -extern bool displayPlayerMarker; -extern bool displayTime; -extern bool displayTextNumbers; -extern bool definingRectangles; -extern uint8 draggingRectangle; -extern int32 startTime; -extern int32 gameCycle; -extern uint8 renderSkip; - -extern int16 rect_x1; -extern int16 rect_y1; -extern int16 rect_x2; -extern int16 rect_y2; - -extern bool testingSnR; - -extern int32 textNumber; - -extern Object_graphic playerGraphic; -extern uint32 player_graphic_no_frames; - #define MAX_SHOWVARS 15 -extern int32 showVar[MAX_SHOWVARS]; - -void Build_debug_text(void); -void Draw_debug_graphics(void); - -void Print_current_info(void); - +namespace Sword2 { } // End of namespace Sword2 #endif diff --git a/sword2/events.cpp b/sword2/events.cpp index 8b8d8ff957..0a270283f7 100644 --- a/sword2/events.cpp +++ b/sword2/events.cpp @@ -25,84 +25,109 @@ #include "sword2/events.h" #include "sword2/interpreter.h" #include "sword2/logic.h" -#include "sword2/memory.h" #include "sword2/object.h" -#include "sword2/sync.h" namespace Sword2 { -_event_unit event_list[MAX_events]; - -void Init_event_system(void) { - for (int i = 0; i < MAX_events; i++) { - //denotes free slot - event_list[i].id = 0; - } +void Sword2Engine::initEventSystem(void) { + memset(_eventList, 0, sizeof(_eventList)); } -uint32 CountEvents(void) { +uint32 Sword2Engine::countEvents(void) { uint32 count = 0; for (int i = 0; i < MAX_events; i++) { - if (event_list[i].id) + if (_eventList[i].id) count++; } return count; } -int32 Logic::fnRequestSpeech(int32 *params) { - // change current script - must be followed by a TERMINATE script - // directive - - // params: 0 id of target to catch the event and startup speech - // servicing - +void Sword2Engine::sendEvent(uint32 id, uint32 interact_id) { int i; for (i = 0; i < MAX_events; i++) { - if (event_list[i].id == (uint32) params[0]) + if (_eventList[i].id == id) break; - if (!event_list[i].id) + if (!_eventList[i].id) break; } - if (i == MAX_events) - error("fnSetEvent out of event slots"); + assert(i < MAX_events); // found that slot // id of person to stop - event_list[i].id = params[0]; + _eventList[i].id = id; - // full script id to interact with - megas run their own 7th script - event_list[i].interact_id = (params[0] * 65536) + 6; + // full script id + _eventList[i].interact_id = interact_id; +} - return IR_CONT; +void Sword2Engine::setPlayerActionEvent(uint32 id, uint32 interact_id) { + // Full script id of action script number 2 + sendEvent(id, (interact_id << 16) | 2); } -void Set_player_action_event(uint32 id, uint32 interact_id) { - int i; +bool Sword2Engine::checkEventWaiting(void) { + for (int i = 0; i < MAX_events; i++) { + if (_eventList[i].id == ID) + return true; + } - for (i = 0; i < MAX_events; i++) { - if (event_list[i].id == id) - break; + return false; +} - if (!event_list[i].id) - break; +void Sword2Engine::startEvent(void) { + // call this from stuff like fnWalk + // you must follow with a return IR_TERMINATE + + for (int i = 0; i < MAX_events; i++) { + if (_eventList[i].id == ID) { + // run 3rd script of target object on level 1 + g_logic.logicOne(_eventList[i].interact_id); + + // clear the slot + _eventList[i].id = 0; + return; + } } - if (i == MAX_events) - error("Set_event out of event slots"); + // oh dear - stop the system + error("Start_event can't find event for id %d", ID); +} - // found that slot +void Sword2Engine::clearEvent(uint32 id) { + for (int i = 0; i < MAX_events; i++) { + if (_eventList[i].id == id) { + // clear the slot + _eventList[i].id = 0; + return; + } + } +} - // id of person to stop - event_list[i].id = id; +void Sword2Engine::killAllIdsEvents(uint32 id) { + for (int i = 0; i < MAX_events; i++) { + if (_eventList[i].id == id) { + // clear the slot + _eventList[i].id = 0; + } + } +} + +int32 Logic::fnRequestSpeech(int32 *params) { + // change current script - must be followed by a TERMINATE script + // directive + + // params: 0 id of target to catch the event and startup speech + // servicing - // full script id of action script number 2 - event_list[i].interact_id = (interact_id * 65536) + 2; + // Full script id to interact with - megas run their own 7th script + g_sword2->sendEvent(params[0], (params[0] << 16) | 6); + return IR_CONT; } int32 Logic::fnSetPlayerActionEvent(int32 *params) { @@ -115,29 +140,7 @@ int32 Logic::fnSetPlayerActionEvent(int32 *params) { // params: 0 id to interact with - // search for an existing event or a slot - - int i; - - for (i = 0; i < MAX_events; i++) { - if (event_list[i].id == CUR_PLAYER_ID) - break; - - if (!event_list[i].id) - break; - } - - if (i == MAX_events) - error("Set_event out of event slots"); - - // found that slot - - // id of person to stop - event_list[i].id = CUR_PLAYER_ID; - - // full script id of action script number 2 - event_list[i].interact_id = (params[0] * 65536) + 2; - + g_sword2->setPlayerActionEvent(CUR_PLAYER_ID, params[0]); return IR_CONT; } @@ -148,29 +151,7 @@ int32 Logic::fnSendEvent(int32 *params) { // params: 0 id to recieve event // 1 script to run - // search for an existing event or a slot - - int i; - - for (i = 0; i < MAX_events; i++) { - if (event_list[i].id == (uint32) params[0]) - break; - - if (!event_list[i].id) - break; - } - - if (i == MAX_events) - error("fnSendEvent out of event slots"); - - // found that slot - - // id of person to stop - event_list[i].id = params[0]; - - //full script id - event_list[i].interact_id = params[1]; - + g_sword2->sendEvent(params[0], params[1]); return IR_CONT; } @@ -179,14 +160,10 @@ int32 Logic::fnCheckEventWaiting(int32 *params) { // params: none - RESULT = 0; - - for (int i = 0; i < MAX_events; i++) { - if (event_list[i].id == ID) { - RESULT = 1; - break; - } - } + if (g_sword2->checkEventWaiting()) + RESULT = 1; + else + RESULT = 0; return IR_CONT; } @@ -197,18 +174,11 @@ int32 Logic::fnCheckEventWaiting(int32 *params) { int32 Logic::fnCheckForEvent(int32 *params) { // params: none - for (int i = 0; i < MAX_events; i++) { - if (event_list[i].id == ID) { - // start the event - // run 3rd script of target object on level 1 - logicOne(event_list[i].interact_id); - // clear the event slot - event_list[i].id = 0; - return IR_TERMINATE; - } - } + if (!g_sword2->checkEventWaiting()) + return IR_CONT; - return IR_CONT; + g_sword2->startEvent(); + return IR_TERMINATE; } // combination of fnPause and fnCheckForEvent @@ -220,23 +190,17 @@ int32 Logic::fnPauseForEvent(int32 *params) { // params: 0 pointer to object's logic structure // 1 number of game-cycles to pause - Object_logic *ob_logic = (Object_logic *)params[0]; + Object_logic *ob_logic = (Object_logic *) params[0]; // first, check for an event - for (int i = 0; i < MAX_events; i++) { - if (event_list[i].id == ID) { - // reset the 'looping' flag - ob_logic->looping = 0; - - // start the event - // run 3rd script of target object on level 1 - logicOne(event_list[i].interact_id); + if (g_sword2->checkEventWaiting()) { + // reset the 'looping' flag + ob_logic->looping = 0; - // clear the event slot - event_list[i].id = 0; - return IR_TERMINATE; - } + // start the event - run 3rd script of target object on level 1 + g_sword2->startEvent(); + return IR_TERMINATE; } // no event, so do the fnPause bit @@ -264,73 +228,18 @@ int32 Logic::fnPauseForEvent(int32 *params) { } } -bool Check_event_waiting(void) { - for (int i = 0; i < MAX_events; i++) { - if (event_list[i].id == ID) - return true; - } - - return false; -} - int32 Logic::fnClearEvent(int32 *params) { // params: none - for (int i = 0; i < MAX_events; i++) { - if (event_list[i].id == ID) { - //clear the slot - event_list[i].id = 0; - return IR_CONT; - } - } - + g_sword2->clearEvent(ID); return IR_CONT; } -void Start_event(void) { - // call this from stuff like fnWalk - // you must follow with a return IR_TERMINATE - - for (int i = 0; i < MAX_events; i++) { - if (event_list[i].id == ID) { - // run 3rd script of target object on level 1 - g_logic.logicOne(event_list[i].interact_id); - - //clear the slot - event_list[i].id = 0; - return; - } - } - - // oh dear - stop the system - error("Start_event can't find event for id %d", ID); -} - int32 Logic::fnStartEvent(int32 *params) { // params: none - for (int i = 0; i < MAX_events; i++) - if (event_list[i].id == ID) { - // run 3rd script of target object on level 1 - logicOne(event_list[i].interact_id); - - // clear the slot - event_list[i].id = 0; - return IR_TERMINATE; - } - - // oh dear - stop the system - error("fnStartEvent can't find event for id %d", ID); - return 0; // never called - but lets stop them bloody errors -} - -void Kill_all_ids_events(uint32 id) { - for (int i = 0; i < MAX_events; i++) { - if (event_list[i].id == id) { - // clear the slot - event_list[i].id = 0; - } - } + g_sword2->startEvent(); + return IR_TERMINATE; } } // End of namespace Sword2 diff --git a/sword2/events.h b/sword2/events.h index 6d4fc29ceb..0f24302080 100644 --- a/sword2/events.h +++ b/sword2/events.h @@ -20,7 +20,7 @@ #ifndef _EVENTS #define _EVENTS -#include "sword2/object.h" +#define MAX_events 10 namespace Sword2 { @@ -29,18 +29,6 @@ struct _event_unit { uint32 interact_id; }; -#define MAX_events 10 - -extern _event_unit event_list[MAX_events]; - -void Init_event_system(void); -void Set_player_action_event(uint32 id, uint32 interact_id); -void Start_event(void); -bool Check_event_waiting(void); -void Kill_all_ids_events(uint32 id); - -uint32 CountEvents(void); - } // End of namespace Sword2 #endif diff --git a/sword2/function.cpp b/sword2/function.cpp index cf22e81179..472f713092 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -35,9 +35,6 @@ namespace Sword2 { -Object_graphic engine_graph; // global for engine -Object_mega engine_mega; // global for engine - int32 Logic::fnTestFunction(int32 *params) { // params: 0 address of a flag return IR_CONT; @@ -85,7 +82,7 @@ int32 Logic::fnInteract(int32 *params) { PLAYER_ACTION = 0; // 3rd script of clicked on id - logicUp((params[0] * 65536) + 2); + logicUp((params[0] < 16) | 2); // out, up and around again - pc is saved for current level to be // returned to @@ -207,7 +204,7 @@ int32 Logic::fnPassGraph(int32 *params) { // params: 0 pointer to a graphic structure (might not need this?) - memcpy(&engine_graph, (uint8 *) params[0], sizeof(Object_graphic)); + memcpy(&g_sword2->_engineGraph, (uint8 *) params[0], sizeof(Object_graphic)); // makes no odds return IR_CONT; @@ -223,7 +220,7 @@ int32 Logic::fnPassMega(int32 *params) { // params: 0 pointer to a mega structure - memcpy(&engine_mega, (uint8 *) params[0], sizeof(Object_mega)); + memcpy(&g_sword2->_engineMega, (uint8 *) params[0], sizeof(Object_mega)); // makes no odds return IR_CONT; @@ -246,17 +243,19 @@ int32 Logic::fnSetValue(int32 *params) { return IR_CONT; } +#ifdef _SWORD2_DEBUG #define BLACK 0 #define WHITE 1 #define RED 2 #define GREEN 3 #define BLUE 4 -uint8 black[4] = { 0, 0, 0, 0 }; -uint8 white[4] = { 255, 255, 255, 0 }; -uint8 red[4] = { 255, 0, 0, 0 }; -uint8 green[4] = { 0, 255, 0, 0 }; -uint8 blue[4] = { 0, 0, 255, 0 }; +static uint8 black[4] = { 0, 0, 0, 0 }; +static uint8 white[4] = { 255, 255, 255, 0 }; +static uint8 red[4] = { 255, 0, 0, 0 }; +static uint8 green[4] = { 0, 255, 0, 0 }; +static uint8 blue[4] = { 0, 0, 255, 0 }; +#endif int32 Logic::fnFlash(int32 *params) { // flash colour 0 (ie. border) - useful during script development diff --git a/sword2/function.h b/sword2/function.h index 3b04853705..d9565796d8 100644 --- a/sword2/function.h +++ b/sword2/function.h @@ -20,13 +20,8 @@ #ifndef _FUNCTION #define _FUNCTION -#include "sword2/object.h" - namespace Sword2 { -extern Object_graphic engine_graph; // global for engine -extern Object_mega engine_mega; // global for engine - } // End of namespace Sword2 #endif diff --git a/sword2/icons.cpp b/sword2/icons.cpp index f27ec6b171..437ff1d39b 100644 --- a/sword2/icons.cpp +++ b/sword2/icons.cpp @@ -28,24 +28,14 @@ namespace Sword2 { -// tempory list -menu_object temp_list[TOTAL_engine_pockets]; -uint32 total_temp = 0; - -menu_object master_menu_list[TOTAL_engine_pockets]; -uint32 total_masters=0; - int32 Logic::fnAddMenuObject(int32 *params) { // params: 0 pointer to a menu_object structure to copy down -#ifdef _SWORD2_DEBUG - if (total_temp == TOTAL_engine_pockets) - error("TOTAL_engine_pockets exceeded!"); -#endif + assert(g_sword2->_totalTemp < TOTAL_engine_pockets); // copy the structure to our in-the-engine list - memcpy(&temp_list[total_temp], (uint8 *) params[0], sizeof(menu_object)); - total_temp++; + memcpy(&g_sword2->_tempList[g_sword2->_totalTemp], (uint8 *) params[0], sizeof(menu_object)); + g_sword2->_totalTemp++; // script continue return IR_CONT; @@ -65,14 +55,14 @@ int32 Logic::fnRefreshInventory(int32 *params) { // so that the icon in 'object_held' is coloured while the rest are // grey examining_menu_icon = 1; - Build_menu(); + g_sword2->buildMenu(); examining_menu_icon = 0; // script continue return IR_CONT; } -void Build_menu(void) { +void Sword2Engine::buildMenu(void) { // create and start the inventory menu - NOW AT THE BOTTOM OF THE // SCREEN! @@ -84,15 +74,15 @@ void Build_menu(void) { uint32 res; // reset temp list which will be totally rebuilt - total_temp = 0; + _totalTemp = 0; - debug(5, "build top menu %d", total_masters); + debug(5, "build top menu %d", _totalMasters); // clear the temp list before building a new temp list in-case list // gets smaller. check each master for (j = 0; j < TOTAL_engine_pockets; j++) - temp_list[j].icon_resource = 0; + _tempList[j].icon_resource = 0; // Call menu builder script which will register all carried menu // objects. Run the 'build_menu' script in the 'menu_master' object @@ -104,23 +94,23 @@ void Build_menu(void) { // Compare new with old. Anything in master thats not in new gets // removed from master - if found in new too, remove from temp - if (total_masters) { + if (_totalMasters) { // check each master - for (j = 0; j < total_masters; j++) { + for (j = 0; j < _totalMasters; j++) { for (k = 0; k < TOTAL_engine_pockets; k++) { res = 0; // if master is in temp - if (master_menu_list[j].icon_resource == temp_list[k].icon_resource) { + if (_masterMenuList[j].icon_resource == _tempList[k].icon_resource) { // kill it in the temp - temp_list[k].icon_resource = 0; + _tempList[k].icon_resource = 0; res = 1; break; } } if (!res) { // otherwise not in temp so kill in main - master_menu_list[j].icon_resource = 0; + _masterMenuList[j].icon_resource = 0; debug(5, "Killed menu %d", j); } } @@ -128,20 +118,20 @@ void Build_menu(void) { // merge master downwards - total_masters = 0; + _totalMasters = 0; //check each master slot for (j = 0; j < TOTAL_engine_pockets; j++) { // not current end - meaning out over the end so move down - if (master_menu_list[j].icon_resource && j != total_masters) { - memcpy(&master_menu_list[total_masters++], &master_menu_list[j], sizeof(menu_object)); + if (_masterMenuList[j].icon_resource && j != _totalMasters) { + memcpy(&_masterMenuList[_totalMasters++], &_masterMenuList[j], sizeof(menu_object)); // moved down now so kill here - master_menu_list[j].icon_resource = 0; - } else if (master_menu_list[j].icon_resource) { + _masterMenuList[j].icon_resource = 0; + } else if (_masterMenuList[j].icon_resource) { // skip full slots - total_masters++; + _totalMasters++; } } @@ -151,18 +141,18 @@ void Build_menu(void) { // check each master slot for (j = 0; j < TOTAL_engine_pockets; j++) { - if (temp_list[j].icon_resource) { + if (_tempList[j].icon_resource) { // here's a new temp - memcpy(&master_menu_list[total_masters++], &temp_list[j], sizeof(menu_object)); + memcpy(&_masterMenuList[_totalMasters++], &_tempList[j], sizeof(menu_object)); } } // init top menu from master list for (j = 0; j < 15; j++) { - if (master_menu_list[j].icon_resource) { + if (_masterMenuList[j].icon_resource) { // 'res' is now the resource id of the icon - res = master_menu_list[j].icon_resource; + res = _masterMenuList[j].icon_resource; if (examining_menu_icon) { // WHEN AN ICON HAS BEEN RIGHT-CLICKED FOR @@ -201,7 +191,7 @@ void Build_menu(void) { icon_coloured = 1; } - icon = res_man.open(master_menu_list[j].icon_resource) + sizeof(_standardHeader); + icon = res_man.open(_masterMenuList[j].icon_resource) + sizeof(_standardHeader); // The coloured icon is stored directly after the // greyed out one. @@ -221,7 +211,7 @@ void Build_menu(void) { g_display->showMenu(RDMENU_BOTTOM); } -void Build_system_menu(void) { +void Sword2Engine::buildSystemMenu(void) { // start a fresh top system menu uint8 *icon; diff --git a/sword2/icons.h b/sword2/icons.h index 31f2408f47..05084aad0f 100644 --- a/sword2/icons.h +++ b/sword2/icons.h @@ -22,24 +22,19 @@ #include "sword2/object.h" -namespace Sword2 { - #define MENU_MASTER_OBJECT 44 #define TOTAL_subjects (375 - 256 + 1) // the speech subject bar #define TOTAL_engine_pockets (15 + 10) // +10 for overflow +namespace Sword2 { + // define these in a script and then register them with the system -typedef struct { +struct menu_object { int32 icon_resource; // icon graphic graphic int32 luggage_resource; // luggage icon resource (for attaching to // mouse pointer) -} menu_object; - -extern menu_object master_menu_list[TOTAL_engine_pockets]; - -void Build_menu(void); -void Build_system_menu(void); +}; } // End of namespace Sword2 diff --git a/sword2/logic.h b/sword2/logic.h index 5d9e24f81c..fa7ea5b224 100644 --- a/sword2/logic.h +++ b/sword2/logic.h @@ -23,6 +23,7 @@ #define _LOGIC #include "sword2/header.h" +#include "sword2/memory.h" #include "sword2/driver/driver96.h" namespace Sword2 { diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp index bf02f7b4ff..3f96384015 100644 --- a/sword2/mouse.cpp +++ b/sword2/mouse.cpp @@ -133,7 +133,7 @@ void Mouse_engine(void) { } Set_mouse(NORMAL_MOUSE_ID); - Build_system_menu(); + g_sword2->buildSystemMenu(); } System_menu_mouse(); return; @@ -265,7 +265,7 @@ void System_menu_mouse(void) { g_display->hideMenu(RDMENU_TOP); } else { Set_mouse(NORMAL_MOUSE_ID); - Build_system_menu(); + g_sword2->buildSystemMenu(); } // clear the screen & restore the location @@ -368,7 +368,7 @@ void Drag_mouse(void) { CLICKED_ID = mouse_touching; - Set_player_action_event(CUR_PLAYER_ID, mouse_touching); + g_sword2->setPlayerActionEvent(CUR_PLAYER_ID, mouse_touching); debug(5, "USED \"%s\" ICON ON %s", FetchObjectName(OBJECT_HELD), FetchObjectName(CLICKED_ID)); @@ -384,7 +384,7 @@ void Drag_mouse(void) { pos = (g_display->_mouseX - 24) / 40; //clicked on something - what button? - if (master_menu_list[pos].icon_resource) { + if (g_sword2->_masterMenuList[pos].icon_resource) { // always back into menu mode mouse_mode = MOUSE_menu; @@ -405,8 +405,8 @@ void Drag_mouse(void) { //what we clicked on, not what // we're dragging - COMBINE_BASE = master_menu_list[pos].icon_resource; - Set_player_action_event(CUR_PLAYER_ID, MENU_MASTER_OBJECT); + COMBINE_BASE = g_sword2->_masterMenuList[pos].icon_resource; + g_sword2->setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT); // turn off mouse now, to // prevent player trying to @@ -419,7 +419,7 @@ void Drag_mouse(void) { } // refresh the menu - Build_menu(); + g_sword2->buildMenu(); debug(5, "switch to menu mode"); } } @@ -454,13 +454,13 @@ void Menu_mouse(void) { pos = (g_display->_mouseX - 24) / 40; // clicked on something - what button? - if (master_menu_list[pos].icon_resource) { + if (g_sword2->_masterMenuList[pos].icon_resource) { if (me->buttons & RD_RIGHTBUTTONDOWN) { // right button look examining_menu_icon = 1; // id the object via its graphic - OBJECT_HELD = master_menu_list[pos].icon_resource; + OBJECT_HELD = g_sword2->_masterMenuList[pos].icon_resource; // Must clear this so next click on // exit becomes 1st click again @@ -469,10 +469,10 @@ void Menu_mouse(void) { debug(5, "RIGHT-CLICKED ON \"%s\" ICON", FetchObjectName(OBJECT_HELD)); - Set_player_action_event(CUR_PLAYER_ID, MENU_MASTER_OBJECT); + g_sword2->setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT); // refresh the menu - Build_menu(); + g_sword2->buildMenu(); // turn off mouse now, to prevent // player trying to click elsewhere @@ -488,13 +488,13 @@ void Menu_mouse(void) { // mouse_on_off() menu_selected_pos = pos; - current_luggage_resource = master_menu_list[pos].luggage_resource; + current_luggage_resource = g_sword2->_masterMenuList[pos].luggage_resource; mouse_mode = MOUSE_drag; debug(5, "setting OH in menu"); // id the object via its graphic - OBJECT_HELD = master_menu_list[pos].icon_resource; + OBJECT_HELD = g_sword2->_masterMenuList[pos].icon_resource; // must clear this so next click on // exit becomes 1st click again @@ -502,9 +502,9 @@ void Menu_mouse(void) { EXIT_CLICK_ID = 0; // refresh the menu - Build_menu(); + g_sword2->buildMenu(); - Set_luggage(master_menu_list[pos].luggage_resource); + Set_luggage(g_sword2->_masterMenuList[pos].luggage_resource); debug(5, "switch to drag mode"); } } @@ -530,7 +530,7 @@ void Normal_mouse(void) { // reset mouse cursor - in case we're between mice Set_mouse(NORMAL_MOUSE_ID); - Build_system_menu(); + g_sword2->buildSystemMenu(); return; } @@ -560,7 +560,7 @@ void Normal_mouse(void) { // reset mouse cursor Set_mouse(NORMAL_MOUSE_ID); - Build_menu(); + g_sword2->buildMenu(); return; } @@ -572,27 +572,27 @@ void Normal_mouse(void) { me = MouseEvent(); - if (definingRectangles) { - if (draggingRectangle == 0) { + if (g_sword2->_debugger->_definingRectangles) { + if (g_sword2->_debugger->_draggingRectangle == 0) { // not yet dragging a rectangle, so need click to start if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) { // set both (x1,y1) and (x2,y2) to this point - rect_x1 = rect_x2 = (uint32) g_display->_mouseX + this_screen.scroll_offset_x; - rect_y1 = rect_y2 = (uint32) g_display->_mouseY + this_screen.scroll_offset_y; - draggingRectangle = 1; + g_sword2->_debugger->_rectX1 = g_sword2->_debugger->_rectX2 = (uint32) g_display->_mouseX + this_screen.scroll_offset_x; + g_sword2->_debugger->_rectY1 = g_sword2->_debugger->_rectY2 = (uint32) g_display->_mouseY + this_screen.scroll_offset_y; + g_sword2->_debugger->_draggingRectangle = 1; } - } else if (draggingRectangle == 1) { + } else if (g_sword2->_debugger->_draggingRectangle == 1) { // currently dragging a rectangle - click means reset if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) { // lock rectangle, so you can let go of mouse // to type in the coords - draggingRectangle = 2; + g_sword2->_debugger->_draggingRectangle = 2; } else { // drag rectangle - rect_x2 = (uint32) g_display->_mouseX + this_screen.scroll_offset_x; - rect_y2 = (uint32) g_display->_mouseY + this_screen.scroll_offset_y; + g_sword2->_debugger->_rectX2 = (uint32) g_display->_mouseX + this_screen.scroll_offset_x; + g_sword2->_debugger->_rectY2 = (uint32) g_display->_mouseY + this_screen.scroll_offset_y; } } else { // currently locked to avoid knocking out of place @@ -600,7 +600,7 @@ void Normal_mouse(void) { if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) { // click means reset - back to start again - draggingRectangle = 0; + g_sword2->_debugger->_draggingRectangle = 0; } } } else { @@ -673,7 +673,7 @@ void Normal_mouse(void) { EXIT_CLICK_ID = 0; EXIT_FADING = 0; - Set_player_action_event(CUR_PLAYER_ID, mouse_touching); + g_sword2->setPlayerActionEvent(CUR_PLAYER_ID, mouse_touching); if (OBJECT_HELD) debug(5, "USED \"%s\" ICON ON %s", FetchObjectName(OBJECT_HELD), FetchObjectName(CLICKED_ID)); @@ -738,7 +738,6 @@ void Mouse_on_off(void) { // setup luggage icon if (OBJECT_HELD) { - // Set_luggage(master_menu_list[menu_selected_pos].luggage_resource); Set_luggage(current_luggage_resource); } } else @@ -1127,7 +1126,7 @@ int32 Logic::fnAddHuman(int32 *params) { // enabled/disabled from console; status printed with on-screen debug // info - if (testingSnR) { + if (g_sword2->_debugger->_testingSnR) { uint8 black[4] = { 0, 0, 0, 0 }; uint8 white[4] = { 255, 255, 255, 0 }; diff --git a/sword2/sound.cpp b/sword2/sound.cpp index c062ec081e..21128b3450 100644 --- a/sword2/sound.cpp +++ b/sword2/sound.cpp @@ -160,7 +160,7 @@ int32 Logic::fnPlayFx(int32 *params) { _standardHeader *header; #endif - if (wantSfxDebug) { + if (g_sword2->_wantSfxDebug) { char type[10]; switch (params[1]) { // 'type' diff --git a/sword2/speech.cpp b/sword2/speech.cpp index 1038132d6e..4831f00e47 100644 --- a/sword2/speech.cpp +++ b/sword2/speech.cpp @@ -582,9 +582,9 @@ int32 Logic::fnTimedWait(int32 *params) { // not ok RESULT = 1; - //clear the event that hasn't been picked up - in theory, + // clear the event that hasn't been picked up - in theory, // none of this should ever happen - Kill_all_ids_events(target); + g_sword2->killAllIdsEvents(target); debug(5, "EVENT timed out"); @@ -972,7 +972,7 @@ int32 Logic::fnISpeak(int32 *params) { } else cycle_skip = 0; - textNumber = params[S_TEXT]; // for debug info + g_sword2->_debugger->_textNumber = params[S_TEXT]; // for debug info // For testing all text & speech! // A script loop can send any text number to fnISpeak and it @@ -1343,7 +1343,7 @@ int32 Logic::fnISpeak(int32 *params) { ob_logic->looping = 0; // reset for debug info - textNumber = 0; + g_sword2->_debugger->_textNumber = 0; // reset to zero, in case text line not even extracted (since // this number comes from the text line) diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index 1d31f4ef05..95311fe6fd 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -150,6 +150,17 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) _fps = 0; _cycleTime = 0; _frameCount = 0; + + _wantSfxDebug = false; + _grabbingSequences = false; + + // For the menus + + _totalTemp = 0; + memset(_tempList, 0, sizeof(_tempList)); + + _totalMasters = 0; + memset(_masterMenuList, 0, sizeof(_masterMenuList)); } Sword2Engine::~Sword2Engine() { @@ -220,7 +231,7 @@ int32 Sword2Engine::InitialiseGame(void) { Init_sync_system(); debug(5, "CALLING: Init_event_system"); - Init_event_system(); + initEventSystem(); // initialise the sound fx queue @@ -322,6 +333,11 @@ void Sword2Engine::go() { debug(5, "CALLING: initialiseRenderCycle"); g_display->initialiseRenderCycle(); + _renderSkip = false; // Toggled on 'S' key, to render only + // 1 in 4 frames, to speed up game + + _gameCycle = 0; + while (1) { if (_debugger->isAttached()) _debugger->onFrame(); @@ -331,7 +347,7 @@ void Sword2Engine::go() { #ifdef _SWORD2_DEBUG // FIXME: If we want this, we should re-work it to use the backend's // screenshot functionality. -// if (grabbingSequences && !console_status) +// if (_debugger->_grabbingSequences && !console_status) // GrabScreenShot(); #endif @@ -388,7 +404,7 @@ void Sword2Engine::go() { else if (c == 'S') { // 'S' toggles speed up (by skipping // display rendering) - renderSkip = 1 - renderSkip; + _renderSkip = !_renderSkip; } #endif } @@ -396,7 +412,7 @@ void Sword2Engine::go() { // skip GameCycle if we're paused if (gamePaused == 0) { #ifdef _SWORD2_DEBUG - gameCycle++; + _gameCycle++; #endif if (GameCycle()) { @@ -406,13 +422,13 @@ void Sword2Engine::go() { } // creates the debug text blocks - Build_debug_text(); + _debugger->buildDebugText(); #ifdef _SWORD2_DEBUG - // if not in console & 'renderSkip' is set, only render + // if not in console & '_renderSkip' is set, only render // display once every 4 game-cycles - if (console_status || renderSkip == 0 || (gameCycle % 4) == 0) + if (console_status || !_renderSkip || (_gameCycle % 4) == 0) g_sword2->buildDisplay(); // create and flip the screen #else // create and flip the screen diff --git a/sword2/sword2.h b/sword2/sword2.h index 34f77b7ebd..b1e5aa6273 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -27,6 +27,9 @@ #include "common/str.h" #include "sword2/build_display.h" #include "sword2/console.h" +#include "sword2/events.h" +#include "sword2/icons.h" +#include "sword2/object.h" #include "sword2/driver/d_sound.h" #include "sword2/driver/d_draw.h" @@ -181,8 +184,41 @@ public: uint32 _cycleTime; uint32 _frameCount; + bool _wantSfxDebug; + bool _grabbingSequences; + + int32 _gameCycle; + bool _renderSkip; + int32 initBackground(int32 res, int32 new_palette); + _event_unit _eventList[MAX_events]; + + void initEventSystem(void); + void sendEvent(uint32 id, uint32 interact_id); + void setPlayerActionEvent(uint32 id, uint32 interact_id); + void startEvent(void); + bool checkEventWaiting(void); + void clearEvent(uint32 id); + void killAllIdsEvents(uint32 id); + + uint32 countEvents(void); + + // These two are set by fnPassGraph() and fnPassMega(). + // FIXME: _engineGraph isn't used at all, is it? + + Object_graphic _engineGraph; + Object_mega _engineMega; + + menu_object _tempList[TOTAL_engine_pockets]; + uint32 _totalTemp; + + menu_object _masterMenuList[TOTAL_engine_pockets]; + uint32 _totalMasters; + + void buildMenu(void); + void buildSystemMenu(void); + void errorString(const char *buf_input, char *buf_output); void initialiseFontResourceFlags(void); void initialiseFontResourceFlags(uint8 language); diff --git a/sword2/walker.cpp b/sword2/walker.cpp index 5eba3cac09..97b0283862 100644 --- a/sword2/walker.cpp +++ b/sword2/walker.cpp @@ -174,7 +174,7 @@ int32 Logic::fnWalk(int32 *params) { // if stopping the walk early, overwrite the next step with a // slow-out, then finish - if (Check_event_waiting()) { + if (g_sword2->checkEventWaiting()) { if (walkAnim[walk_pc].step == 0 && walkAnim[walk_pc + 1].step == 1) { // at the beginning of a step ob_walkdata = (Object_walkdata *) params[3]; @@ -213,8 +213,8 @@ int32 Logic::fnWalk(int32 *params) { // was only run if a function that always returned zero // returned non-zero. - if (Check_event_waiting()) { - Start_event(); + if (g_sword2->checkEventWaiting()) { + g_sword2->startEvent(); RESULT = 1; // 1 means didn't finish walk return IR_TERMINATE; } else { @@ -615,13 +615,13 @@ int32 Logic::fnFaceMega(int32 *params) { res_man.close(params[4]); - // engine_mega is now the Object_mega of mega we want to turn + // engineMega is now the Object_mega of mega we want to turn // to face pars[3] = params[3]; pars[4] = ob_mega->feet_x; pars[5] = ob_mega->feet_y; - pars[6] = What_target(ob_mega->feet_x, ob_mega->feet_y, engine_mega.feet_x, engine_mega.feet_y); + pars[6] = What_target(ob_mega->feet_x, ob_mega->feet_y, g_sword2->_engineMega.feet_x, g_sword2->_engineMega.feet_y); } pars[0] = params[0]; @@ -678,11 +678,11 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) { res_man.close(params[4]); - // engine_mega is now the Object_mega of mega we want to + // engineMega is now the Object_mega of mega we want to // route to // stand exactly beside the mega, ie. at same y-coord - pars[5] = engine_mega.feet_y; + pars[5] = g_sword2->_engineMega.feet_y; // apply scale factor to walk distance // Ay+B gives 256 * scale ie. 256 * 256 * true_scale for even @@ -693,20 +693,20 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) { mega_seperation= (mega_seperation * scale) / 256; debug(5, "seperation %d", mega_seperation); - debug(5, " target x %d, y %d", engine_mega.feet_x, engine_mega.feet_y); + debug(5, " target x %d, y %d", g_sword2->_engineMega.feet_x, g_sword2->_engineMega.feet_y); - if (engine_mega.feet_x < ob_mega->feet_x) + if (g_sword2->_engineMega.feet_x < ob_mega->feet_x) { // Target is left of us, so aim to stand to their // right. Face down_left - pars[4] = engine_mega.feet_x + mega_seperation; + pars[4] = g_sword2->_engineMega.feet_x + mega_seperation; pars[6] = 5; } else { // Ok, must be right of us so aim to stand to their // left. Face down_right. - pars[4] = engine_mega.feet_x - mega_seperation; + pars[4] = g_sword2->_engineMega.feet_x - mega_seperation; pars[6] = 3; } } |