From 1b52e11d559aa7c8df48bb114d4dd4dfb02a0770 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sun, 12 Oct 2003 14:40:04 +0000 Subject: Moved the "router" code into a new Router class. I'm hoping this is analogous to the SkyAutoRoute class. svn-id: r10754 --- sword2/controls.cpp | 6 +- sword2/debug.cpp | 4 +- sword2/logic.cpp | 6 +- sword2/router.cpp | 1667 ++++++++++++++++++++++---------------------------- sword2/router.h | 186 +++++- sword2/save_rest.cpp | 8 +- sword2/startup.cpp | 2 +- sword2/sword2.cpp | 7 +- sword2/sword2.h | 14 +- sword2/walker.cpp | 22 +- 10 files changed, 951 insertions(+), 971 deletions(-) (limited to 'sword2') diff --git a/sword2/controls.cpp b/sword2/controls.cpp index 28adfe2246..ced13f899b 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -893,7 +893,7 @@ int32 OptionsDialog::writeOptionSettings(void) { SaveFile *fp; SaveFileManager *mgr = g_system->get_savefile_manager(); - sprintf(filename, "%s-settings.dat", g_sword2->_game_name); + sprintf(filename, "%s-settings.dat", g_sword2->_gameName); buff[0] = g_sound->getMusicVolume(); buff[1] = g_sound->getSpeechVolume(); @@ -1435,7 +1435,7 @@ void Gui::restartControl(void) { DEMO = temp_demo_flag; // free all the route memory blocks from previous game - FreeAllRouteMem(); + router.freeAllRouteMem(); // call the same function that first started us up g_sword2->Start_game(); @@ -1483,7 +1483,7 @@ int32 Gui::readOptionSettings(void) { SaveFile *fp; SaveFileManager *mgr = g_system->get_savefile_manager(); - sprintf(filename, "%s-settings.dat", g_sword2->_game_name); + sprintf(filename, "%s-settings.dat", g_sword2->_gameName); if (!(fp = mgr->open_savefile(filename, g_sword2->getSavePath(), false))) return 1; diff --git a/sword2/debug.cpp b/sword2/debug.cpp index a969056716..14d2054279 100644 --- a/sword2/debug.cpp +++ b/sword2/debug.cpp @@ -34,7 +34,7 @@ #include "bs2/mouse.h" #include "bs2/protocol.h" #include "bs2/resman.h" -#include "bs2/router.h" // for PlotWalkGrid() +#include "bs2/router.h" // for plotWalkGrid() #include "bs2/speech.h" // for 'officialTextNumber' and // 'speechScriptWaiting' @@ -358,7 +358,7 @@ void Draw_debug_graphics(void) { // walk-grid if (displayWalkGrid) - PlotWalkGrid(); + router.plotWalkGrid(); // player feet coord marker diff --git a/sword2/logic.cpp b/sword2/logic.cpp index dfec05368e..4dc4123f77 100644 --- a/sword2/logic.cpp +++ b/sword2/logic.cpp @@ -23,7 +23,7 @@ #include "bs2/debug.h" #include "bs2/interpreter.h" #include "bs2/logic.h" -#include "bs2/router.h" // for ClearWalkGridList() +#include "bs2/router.h" // for clearWalkGridList() #include "bs2/sound.h" #include "bs2/sync.h" @@ -237,13 +237,13 @@ void logic::expressChangeSession(uint32 sesh_id) { Init_sync_system(); // reset walkgrid list (see FN_register_walkgrid) - ClearWalkGridList(); + router.clearWalkGridList(); // stops all fx & clears the queue Clear_fx_queue(); // free all the route memory blocks from previous game - FreeAllRouteMem(); + router.freeAllRouteMem(); } void logic::naturalChangeSession(uint32 sesh_id) { diff --git a/sword2/router.cpp b/sword2/router.cpp index 88411c4b2b..836c14a325 100644 --- a/sword2/router.cpp +++ b/sword2/router.cpp @@ -73,10 +73,6 @@ * ****************************************************************************/ -/* - * Include Files - */ - #include "stdafx.h" #include "bs2/driver/driver96.h" #include "bs2/console.h" @@ -91,165 +87,9 @@ namespace Sword2 { -#define MAX_FRAMES_PER_CYCLE 16 -#define NO_DIRECTIONS 8 -#define MAX_FRAMES_PER_CHAR (MAX_FRAMES_PER_CYCLE * NO_DIRECTIONS) -#define ROUTE_END_FLAG 255 - -//--------------------------------------- -// TEMP! -// 1 = force the use of slidy router (so solid path not used when ending walk -// in ANY direction) -int8 forceSlidy; -//--------------------------------------- - -/* - * Type Defines - */ - -#define O_WALKANIM_SIZE 600 // max number of nodes in router output -#define O_GRID_SIZE 200 // max 200 lines & 200 points -#define EXTRA_GRID_SIZE 20 // max 20 lines & 20 points -#define O_ROUTE_SIZE 50 // max number of modules in a route - -typedef struct { - int32 x; - int32 y; - int32 dirS; - int32 dirD; -} _routeData; - -typedef struct { - int32 x; - int32 y; - int32 dir; - int32 num; -} _pathData; - -// Function prototypes - -static int32 GetRoute(void); -static void ExtractRoute(void); -static void LoadWalkGrid(void); -static void SetUpWalkGrid(Object_mega *ob_mega, int32 x, int32 y, int32 dir); -static void LoadWalkData(Object_walkdata *ob_walkdata); - -#ifdef _SWORD2_DEBUG -static void PlotCross(int16 x, int16 y, uint8 colour); -#endif - -static int32 Scan(int32 level); -static int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2); -static int32 LineCheck(int32 x1, int32 x2, int32 y1, int32 y2); -static int32 VertCheck(int32 x, int32 y1, int32 y2); -static int32 HorizCheck(int32 x1, int32 y, int32 x2); -static int32 Check(int32 x1, int32 y1, int32 x2, int32 y2); -static int32 CheckTarget(int32 x, int32 y); - -static int32 SmoothestPath(void); -static int32 SlidyPath(void); -static int32 SolidPath(void); - -static int32 SmoothCheck(int32 best, int32 p, int32 dirS, int32 dirD); - -static int32 AddSlowInFrames(_walkData *walkAnim); -static void AddSlowOutFrames(_walkData *walkAnim); -static void SlidyWalkAnimator(_walkData *walkAnim); -static int32 SolidWalkAnimator(_walkData *walkAnim); - -#define MAX_WALKGRIDS 10 - -static int32 walkGridList[MAX_WALKGRIDS]; - -// because we only have 2 megas in the game! -#define TOTAL_ROUTE_SLOTS 2 - -// stores pointers to mem blocks containing routes created & used by megas -// (NULL if slot not in use) -static mem *route_slots[TOTAL_ROUTE_SLOTS]; - -// Local Variables - -static int32 nbars; -static int32 nnodes; - -// because extra bars will be copied into here afer walkgrid loaded -static _barData bars[O_GRID_SIZE+EXTRA_GRID_SIZE]; - -static _nodeData node[O_GRID_SIZE+EXTRA_GRID_SIZE]; - -// area for extra route data to block parts of floors and enable routing -// round mega charaters - -static int32 nExtraBars = 0; -static int32 nExtraNodes = 0; -static _barData extraBars[EXTRA_GRID_SIZE]; -static _nodeData extraNode[EXTRA_GRID_SIZE]; - -static int32 startX; -static int32 startY; -static int32 startDir; -static int32 targetX; -static int32 targetY; -static int32 targetDir; -static int32 scaleA; -static int32 scaleB; -static _routeData route[O_ROUTE_SIZE]; -static _pathData smoothPath[O_ROUTE_SIZE]; -static _pathData modularPath[O_ROUTE_SIZE]; -static int32 routeLength; - -static int32 framesPerStep; -static int32 framesPerChar; +Router router; -static uint8 nWalkFrames; // no. of frames per walk cycle -static uint8 usingStandingTurnFrames; // any standing turn frames? -static uint8 usingWalkingTurnFrames; // any walking turn frames? -static uint8 usingSlowInFrames; // any slow-in frames? -static uint8 usingSlowOutFrames; // any slow-out frames? -static int32 dx[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR]; -static int32 dy[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR]; -static int8 modX[NO_DIRECTIONS]; -static int8 modY[NO_DIRECTIONS]; -static int32 diagonalx = 0; -static int32 diagonaly = 0; - -static int32 firstStandFrame; - -static int32 firstStandingTurnLeftFrame; -static int32 firstStandingTurnRightFrame; - -static int32 firstWalkingTurnLeftFrame; // left walking turn -static int32 firstWalkingTurnRightFrame; // right walking turn - -static uint32 firstSlowInFrame[NO_DIRECTIONS]; -static uint32 numberOfSlowInFrames[NO_DIRECTIONS]; - -static uint32 leadingLeg[NO_DIRECTIONS]; - -static int32 firstSlowOutFrame; - -// number of slow-out frames on for each leading-leg in each direction -// ie. total number of slow-out frames = (numberOfSlowOutFrames * 2 * -// NO_DIRECTIONS) - -static int32 numberOfSlowOutFrames; - -static int32 stepCount; - -static int32 moduleX; -static int32 moduleY; -static int32 currentDir; -static int32 lastCount; -static int32 frame; - -/* - * CODE - */ - -// ************************************************************************** - -uint8 ReturnSlotNo(uint32 megaId) { +uint8 Router::returnSlotNo(uint32 megaId) { if (ID == CUR_PLAYER_ID) { // George (8) return 0; @@ -259,25 +99,24 @@ uint8 ReturnSlotNo(uint32 megaId) { } } -void AllocateRouteMem(void) { +void Router::allocateRouteMem(void) { uint8 slotNo; - // added (James23June96) // Player character always always slot 0, while the other mega // (normally Nico) always uses slot 1 // Better this way, so that if mega object removed from memory while // in middle of route, the old route will be safely cleared from // memory just before they create a new one - slotNo = ReturnSlotNo(ID); + slotNo = returnSlotNo(ID); // if this slot is already used, then it can't be needed any more // because this id is creating a new route! - if (route_slots[slotNo]) - FreeRouteMem(); + if (_routeSlots[slotNo]) + freeRouteMem(); - route_slots[slotNo] = memory.allocMemory(sizeof(_walkData) * O_WALKANIM_SIZE, MEM_locked, UID_walk_anim); + _routeSlots[slotNo] = memory.allocMemory(sizeof(_walkData) * O_WALKANIM_SIZE, MEM_locked, UID_walk_anim); // 12000 bytes were used for this in Sword1 mega compacts, based on // 20 bytes per '_walkData' frame @@ -292,48 +131,48 @@ void AllocateRouteMem(void) { // megaObject->route_slot_id = slotNo + 1; } -_walkData* LockRouteMem(void) { - uint8 slotNo = ReturnSlotNo(ID); +_walkData* Router::lockRouteMem(void) { + uint8 slotNo = returnSlotNo(ID); - memory.lockMemory(route_slots[slotNo]); - return (_walkData *) route_slots[slotNo]->ad; + memory.lockMemory(_routeSlots[slotNo]); + return (_walkData *) _routeSlots[slotNo]->ad; } -void FloatRouteMem(void) { - uint8 slotNo = ReturnSlotNo(ID); +void Router::floatRouteMem(void) { + uint8 slotNo = returnSlotNo(ID); - memory.floatMemory(route_slots[slotNo]); + memory.floatMemory(_routeSlots[slotNo]); } -void FreeRouteMem(void) { - uint8 slotNo = ReturnSlotNo(ID); +void Router::freeRouteMem(void) { + uint8 slotNo = returnSlotNo(ID); - // free the mem block pointed to from this entry of route_slots[] + // free the mem block pointed to from this entry of _routeSlots[] - memory.freeMemory(route_slots[slotNo]); - route_slots[slotNo] = NULL; + memory.freeMemory(_routeSlots[slotNo]); + _routeSlots[slotNo] = NULL; } -void FreeAllRouteMem(void) { - for (int slotNo = 0; slotNo < TOTAL_ROUTE_SLOTS; slotNo++) { - if (route_slots[slotNo]) { +void Router::freeAllRouteMem(void) { + for (int i = 0; i < TOTAL_ROUTE_SLOTS; i++) { + if (_routeSlots[i]) { // free the mem block pointed to from this entry of - // route_slots[] - memory.freeMemory(route_slots[slotNo]); - route_slots[slotNo] = NULL; + // _routeSlots[] + memory.freeMemory(_routeSlots[i]); + _routeSlots[i] = NULL; } } } -int32 RouteFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, int32 y, int32 dir) { +int32 Router::routeFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, int32 y, int32 dir) { /********************************************************************* * RouteFinder.C polygon router with modular walks * 21 august 94 * 3 november 94 - * RouteFinder creates a list of modules that enables HardWalk to + * routeFinder creates a list of modules that enables HardWalk to * create an animation list. * - * RouteFinder currently works by scanning grid data and coming up + * routeFinder currently works by scanning grid data and coming up * with a ROUTE as a series of way points(nodes), the smoothest eight * directional PATH through these nodes is then found, this * information is made available to HardWalk for a WALK to be created @@ -355,47 +194,47 @@ int32 RouteFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, i // megaId = id; - SetUpWalkGrid(ob_mega, x, y, dir); - LoadWalkData(ob_walkdata); + setUpWalkGrid(ob_mega, x, y, dir); + loadWalkData(ob_walkdata); // lock the _walkData array (NB. AFTER loading walkgrid & walkdata!) - walkAnim = LockRouteMem(); + walkAnim = lockRouteMem(); // All route data now loaded start finding a route // Check if we can get a route through the floor. changed 12 Oct95 JPS - routeFlag = GetRoute(); + routeFlag = getRoute(); if (routeFlag == 2) { // special case for zero length route // if target direction specified as any - if (targetDir > 7) - targetDir = startDir; + if (_targetDir > 7) + _targetDir = _startDir; // just a turn on the spot is required set an end module for // the route let the animator deal with it - // modularPath is normally set by ExtractRoute - - modularPath[0].dir = startDir; - modularPath[0].num = 0; - modularPath[0].x = startX; - modularPath[0].y = startY; - modularPath[1].dir = targetDir; - modularPath[1].num = 0; - modularPath[1].x = startX; - modularPath[1].y = startY; - modularPath[2].dir = 9; - modularPath[2].num = ROUTE_END_FLAG; - - SlidyWalkAnimator(walkAnim); + // modularPath is normally set by extractRoute + + _modularPath[0].dir = _startDir; + _modularPath[0].num = 0; + _modularPath[0].x = _startX; + _modularPath[0].y = _startY; + _modularPath[1].dir = _targetDir; + _modularPath[1].num = 0; + _modularPath[1].x = _startX; + _modularPath[1].y = _startY; + _modularPath[2].dir = 9; + _modularPath[2].num = ROUTE_END_FLAG; + + slidyWalkAnimator(walkAnim); routeFlag = 2; } else if (routeFlag == 1) { // a normal route // Convert the route to an exact path - SmoothestPath(); + smoothestPath(); // The Route had waypoints and direction options @@ -409,35 +248,35 @@ int32 RouteFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, i // we can create a route without sliding and miss the exact // target - if (!forceSlidy) { - if (targetDir == 8) { - // can end facing ANY direction (ie. exact end - // position not vital) - so use SOLID walk to - // avoid sliding to exact position +#ifndef FORCE_SLIDY + if (_targetDir == 8) { + // can end facing ANY direction (ie. exact end + // position not vital) - so use SOLID walk to + // avoid sliding to exact position - SolidPath(); - solidFlag = SolidWalkAnimator(walkAnim); - } + solidPath(); + solidFlag = solidWalkAnimator(walkAnim); } +#endif if (!solidFlag) { // if we failed to create a SOLID route, do a SLIDY // one instead - SlidyPath(); - SlidyWalkAnimator(walkAnim); + slidyPath(); + slidyWalkAnimator(walkAnim); } } else { // Route didn't reach target so assume point was off the floor // routeFlag = 0; } - FloatRouteMem(); // float the _walkData array again + floatRouteMem(); // float the _walkData array again return routeFlag; // send back null route } -int32 GetRoute(void) { +int32 Router::getRoute(void) { /********************************************************************* * GetRoute.C extract a path from walk grid * 12 october 94 @@ -445,7 +284,7 @@ int32 GetRoute(void) { * GetRoute currently works by scanning grid data and coming up with * a ROUTE as a series of way points(nodes). * - * static _routeData route[O_ROUTE_SIZE]; + * static _routeData _route[O_ROUTE_SIZE]; * * return 0 = failed to find a route * @@ -461,7 +300,7 @@ int32 GetRoute(void) { int32 level; int32 changed; - if (startX == targetX && startY == targetY) + if (_startX == _targetX && _startY == _targetY) routeGot = 2; else { // 'else' added by JEL (23jan96) otherwise 'routeGot' affected @@ -469,7 +308,7 @@ int32 GetRoute(void) { // to walk downwards on the spot // returns 3 if target on a line ( +- 1 pixel ) - routeGot = CheckTarget(targetX,targetY); + routeGot = checkTarget(_targetX, _targetY); } if (routeGot == 0) { @@ -479,23 +318,23 @@ int32 GetRoute(void) { // scan through the nodes linking each node to its nearest // neighbour until no more nodes change - // This is the routine that finds a route using Scan() + // This is the routine that finds a route using scan() level = 1; do { - changed = Scan(level); + changed = scan(level); level++; } while (changed == 1); // Check to see if the route reached the target - if (node[nnodes].dist < 9999) { + if (_node[_nnodes].dist < 9999) { // it did so extract the route as nodes and the // directions to go between each node routeGot = 1; - ExtractRoute(); + extractRoute(); // route.X,route.Y and route.Dir now hold all the // route infomation with the target dir or route @@ -508,7 +347,7 @@ int32 GetRoute(void) { // THE SLIDY PATH ROUTINES -int32 SmoothestPath() { +int32 Router::smoothestPath() { // This is the second big part of the route finder and the the only // bit that tries to be clever (the other bits are clever). // @@ -542,7 +381,6 @@ int32 SmoothestPath() { int32 DD; int32 i; int32 j; - int32 temp; int32 steps; int32 option; int32 options; @@ -555,21 +393,21 @@ int32 SmoothestPath() { // route.X route.Y and route.Dir start at far end - smoothPath[0].x = startX; - smoothPath[0].y = startY; - smoothPath[0].dir = startDir; - smoothPath[0].num = 0; + _smoothPath[0].x = _startX; + _smoothPath[0].y = _startY; + _smoothPath[0].dir = _startDir; + _smoothPath[0].num = 0; p = 0; - lastDir = startDir; + lastDir = _startDir; // for each section of the route do { - dirS = route[p].dirS; - dirD = route[p].dirD; - nextDirS = route[p+1].dirS; - nextDirD = route[p+1].dirD; + dirS = _route[p].dirS; + dirD = _route[p].dirD; + nextDirS = _route[p + 1].dirS; + nextDirD = _route[p + 1].dirD; // Check directions into and out of a pair of nodes going in dS = dirS - lastDir; @@ -634,17 +472,12 @@ int32 SmoothestPath() { turns[2] = 2; tempturns[3] = DD; turns[3] = 3; - i = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { if (tempturns[j] > tempturns[j + 1]) { - temp = turns[j]; - turns[j] = turns[j + 1]; - turns[j + 1] = temp; - temp = tempturns[j]; - tempturns[j] = tempturns[j + 1]; - tempturns[j + 1] = temp; + SWAP(turns[j], turns[j + 1]); + SWAP(tempturns[j], tempturns[j + 1]); } } } @@ -653,11 +486,11 @@ int32 SmoothestPath() { // to see on the screen but each option must be checked to see // if it can be walked - options = NewCheck(1, route[p].x, route[p].y, route[p + 1].x, route[p + 1].y); + options = newCheck(1, _route[p].x, _route[p].y, _route[p + 1].x, _route[p + 1].y); #ifdef _SWORD2_DEBUG if (options == 0) { - debug(5, "BestTurns fail %d %d %d %d", route[p].x, route[p].y, route[p + 1].x, route[p + 1].y); + debug(5, "BestTurns fail %d %d %d %d", _route[p].x, _route[p].y, _route[p + 1].x, _route[p + 1].y); debug(5, "BestTurns fail %d %d %d %d", turns[0], turns[1], turns[2], options); Con_fatal_error("BestTurns failed"); } @@ -669,13 +502,13 @@ int32 SmoothestPath() { do { option = 1 << turns[i]; if (option & options) - steps = SmoothCheck(turns[i], p, dirS, dirD); + steps = smoothCheck(turns[i], p, dirS, dirD); i++; } while (steps == 0 && i < 4); #ifdef _SWORD2_DEBUG if (steps == 0) { - debug(5, "BestTurns failed %d %d %d %d", route[p].x, route[p].y, route[p + 1].x, route[p + 1].y); + debug(5, "BestTurns failed %d %d %d %d", _route[p].x, _route[p].y, _route[p + 1].x, _route[p + 1].y); debug(5, "BestTurns failed %d %d %d %d", turns[0], turns[1], turns[2], options); Con_fatal_error("BestTurns failed"); } @@ -683,17 +516,17 @@ int32 SmoothestPath() { // route.X route.Y route.dir and bestTurns start at far end p++; - } while (p < routeLength); + } while (p < _routeLength); // best turns will end heading as near as possible to target dir rest // is down to anim for now - smoothPath[steps].dir = 9; - smoothPath[steps].num = ROUTE_END_FLAG; + _smoothPath[steps].dir = 9; + _smoothPath[steps].num = ROUTE_END_FLAG; return 1; } -int32 SmoothCheck(int32 best, int32 p, int32 dirS, int32 dirD) { +int32 Router::smoothCheck(int32 best, int32 p, int32 dirS, int32 dirD) { /********************************************************************* * Slip sliding away * This path checker checks to see if a walk that exactly follows the @@ -725,10 +558,10 @@ int32 SmoothCheck(int32 best, int32 p, int32 dirS, int32 dirD) { if (p == 0) k = 1; - x = route[p].x; - y = route[p].y; - x2 = route[p + 1].x; - y2 = route[p + 1].y; + x = _route[p].x; + y = _route[p].y; + x2 = _route[p + 1].x; + y2 = _route[p + 1].y; ldx = x2 - x; ldy = y2 - y; dirX = 1; @@ -748,30 +581,30 @@ int32 SmoothCheck(int32 best, int32 p, int32 dirS, int32 dirD) { if (dirS == 0 || dirS == 4) { // vert and diag ddx = ldx; - ddy = (ldx * diagonaly) / diagonalx; + ddy = (ldx * _diagonaly) / _diagonalx; dsy = ldy - ddy; ddx = ddx * dirX; ddy = ddy * dirY; dsy = dsy * dirY; dsx = 0; - sd0 = (ddx + modX[dirD] / 2) / modX[dirD]; - ss0 = (dsy + modY[dirS] / 2) / modY[dirS]; + sd0 = (ddx + _modX[dirD] / 2) / _modX[dirD]; + ss0 = (dsy + _modY[dirS] / 2) / _modY[dirS]; sd1 = sd0 / 2; ss1 = ss0 / 2; sd2 = sd0 - sd1; ss2 = ss0 - ss1; } else { ddy = ldy; - ddx = (ldy * diagonalx) / diagonaly; + ddx = (ldy * _diagonalx) / _diagonaly; dsx = ldx - ddx; ddy = ddy * dirY; ddx = ddx * dirX; dsx = dsx * dirX; dsy = 0; - sd0 = (ddy + modY[dirD] / 2) / modY[dirD]; - ss0 = (dsx + modX[dirS] / 2) / modX[dirS]; + sd0 = (ddy + _modY[dirD] / 2) / _modY[dirD]; + ss0 = (dsx + _modX[dirS] / 2) / _modX[dirS]; sd1 = sd0 / 2; ss1 = ss0 / 2; sd2 = sd0 - sd1; @@ -779,79 +612,78 @@ int32 SmoothCheck(int32 best, int32 p, int32 dirS, int32 dirD) { } if (best == 0) { // halfsquare, diagonal, halfsquare - smoothPath[k].x = x + dsx / 2; - smoothPath[k].y = y + dsy / 2; - smoothPath[k].dir = dirS; - smoothPath[k].num = ss1; + _smoothPath[k].x = x + dsx / 2; + _smoothPath[k].y = y + dsy / 2; + _smoothPath[k].dir = dirS; + _smoothPath[k].num = ss1; k++; - smoothPath[k].x = x + dsx / 2 + ddx; - smoothPath[k].y = y + dsy / 2 + ddy; - smoothPath[k].dir = dirD; - smoothPath[k].num = sd0; + _smoothPath[k].x = x + dsx / 2 + ddx; + _smoothPath[k].y = y + dsy / 2 + ddy; + _smoothPath[k].dir = dirD; + _smoothPath[k].num = sd0; k++; - smoothPath[k].x = x + dsx + ddx; - smoothPath[k].y = y + dsy + ddy; - smoothPath[k].dir = dirS; - smoothPath[k].num = ss2; + _smoothPath[k].x = x + dsx + ddx; + _smoothPath[k].y = y + dsy + ddy; + _smoothPath[k].dir = dirS; + _smoothPath[k].num = ss2; k++; } else if (best == 1) { // square, diagonal - smoothPath[k].x = x + dsx; - smoothPath[k].y = y + dsy; - smoothPath[k].dir = dirS; - smoothPath[k].num = ss0; + _smoothPath[k].x = x + dsx; + _smoothPath[k].y = y + dsy; + _smoothPath[k].dir = dirS; + _smoothPath[k].num = ss0; k++; - smoothPath[k].x = x2; - smoothPath[k].y = y2; - smoothPath[k].dir = dirD; - smoothPath[k].num = sd0; + _smoothPath[k].x = x2; + _smoothPath[k].y = y2; + _smoothPath[k].dir = dirD; + _smoothPath[k].num = sd0; k++; } else if (best == 2) { // diagonal square - smoothPath[k].x = x + ddx; - smoothPath[k].y = y + ddy; - smoothPath[k].dir = dirD; - smoothPath[k].num = sd0; + _smoothPath[k].x = x + ddx; + _smoothPath[k].y = y + ddy; + _smoothPath[k].dir = dirD; + _smoothPath[k].num = sd0; k++; - smoothPath[k].x = x2; - smoothPath[k].y = y2; - smoothPath[k].dir = dirS; - smoothPath[k].num = ss0; + _smoothPath[k].x = x2; + _smoothPath[k].y = y2; + _smoothPath[k].dir = dirS; + _smoothPath[k].num = ss0; k++; } else { // halfdiagonal, square, halfdiagonal - smoothPath[k].x = x + ddx / 2; - smoothPath[k].y = y + ddy / 2; - smoothPath[k].dir = dirD; - smoothPath[k].num = sd1; + _smoothPath[k].x = x + ddx / 2; + _smoothPath[k].y = y + ddy / 2; + _smoothPath[k].dir = dirD; + _smoothPath[k].num = sd1; k++; - smoothPath[k].x = x + dsx + ddx / 2; - smoothPath[k].y = y + dsy + ddy / 2; - smoothPath[k].dir = dirS; - smoothPath[k].num = ss0; + _smoothPath[k].x = x + dsx + ddx / 2; + _smoothPath[k].y = y + dsy + ddy / 2; + _smoothPath[k].dir = dirS; + _smoothPath[k].num = ss0; k++; - smoothPath[k].x = x2; - smoothPath[k].y = y2; - smoothPath[k].dir = dirD; - smoothPath[k].num = sd2; + _smoothPath[k].x = x2; + _smoothPath[k].y = y2; + _smoothPath[k].dir = dirD; + _smoothPath[k].num = sd2; k++; } return k; } -int32 SlidyPath() { +int32 Router::slidyPath() { /********************************************************************* - * SlidyPath creates a path based on part steps with no sliding to get + * slidyPath creates a path based on part steps with no sliding to get * as near as possible to the target without any sliding this routine * is currently unused, but is intended for use when just clicking * about. * * produce a module list from the line data - * *********************************************************************/ int32 smooth; @@ -866,27 +698,27 @@ int32 SlidyPath() { slidy = 1; smooth = 1; - modularPath[0].x = smoothPath[0].x; - modularPath[0].y = smoothPath[0].y; - modularPath[0].dir = smoothPath[0].dir; - modularPath[0].num = 0; - - while (smoothPath[smooth].num < ROUTE_END_FLAG) { - scale = scaleA * smoothPath[smooth].y + scaleB; - deltaX = smoothPath[smooth].x - modularPath[slidy - 1].x; - deltaY = smoothPath[smooth].y - modularPath[slidy - 1].y; - stepX = modX[smoothPath[smooth].dir]; - stepY = modY[smoothPath[smooth].dir]; + _modularPath[0].x = _smoothPath[0].x; + _modularPath[0].y = _smoothPath[0].y; + _modularPath[0].dir = _smoothPath[0].dir; + _modularPath[0].num = 0; + + while (_smoothPath[smooth].num < ROUTE_END_FLAG) { + scale = _scaleA * _smoothPath[smooth].y + _scaleB; + deltaX = _smoothPath[smooth].x - _modularPath[slidy - 1].x; + deltaY = _smoothPath[smooth].y - _modularPath[slidy - 1].y; + stepX = _modX[_smoothPath[smooth].dir]; + stepY = _modY[_smoothPath[smooth].dir]; stepX = stepX * scale; stepY = stepY * scale; stepX = stepX >> 19; // quarter a step minimum stepY = stepY >> 19; if (ABS(deltaX) >= ABS(stepX) && ABS(deltaY) >= ABS(stepY)) { - modularPath[slidy].x = smoothPath[smooth].x; - modularPath[slidy].y = smoothPath[smooth].y; - modularPath[slidy].dir = smoothPath[smooth].dir; - modularPath[slidy].num = 1; + _modularPath[slidy].x = _smoothPath[smooth].x; + _modularPath[slidy].y = _smoothPath[smooth].y; + _modularPath[slidy].dir = _smoothPath[smooth].dir; + _modularPath[slidy].num = 1; slidy++; } smooth++; @@ -895,39 +727,37 @@ int32 SlidyPath() { // in case the last bit had no steps if (slidy > 1) { - modularPath[slidy - 1].x = smoothPath[smooth - 1].x; - modularPath[slidy - 1].y = smoothPath[smooth - 1].y; + _modularPath[slidy - 1].x = _smoothPath[smooth - 1].x; + _modularPath[slidy - 1].y = _smoothPath[smooth - 1].y; } // set up the end of the walk - modularPath[slidy].x = smoothPath[smooth - 1].x; - modularPath[slidy].y = smoothPath[smooth - 1].y; - modularPath[slidy].dir = targetDir; - modularPath[slidy].num = 0; + _modularPath[slidy].x = _smoothPath[smooth - 1].x; + _modularPath[slidy].y = _smoothPath[smooth - 1].y; + _modularPath[slidy].dir = _targetDir; + _modularPath[slidy].num = 0; slidy++; - modularPath[slidy].x = smoothPath[smooth - 1].x; - modularPath[slidy].y = smoothPath[smooth - 1].y; - modularPath[slidy].dir = 9; - modularPath[slidy].num = ROUTE_END_FLAG; + _modularPath[slidy].x = _smoothPath[smooth - 1].x; + _modularPath[slidy].y = _smoothPath[smooth - 1].y; + _modularPath[slidy].dir = 9; + _modularPath[slidy].num = ROUTE_END_FLAG; return 1; } // SLOW IN -int32 AddSlowInFrames(_walkData *walkAnim) { - uint32 slowInFrameNo; - - if (usingSlowInFrames && modularPath[1].num > 0) { - for (slowInFrameNo = 0; slowInFrameNo < numberOfSlowInFrames[currentDir]; slowInFrameNo++) { - walkAnim[stepCount].frame = firstSlowInFrame[currentDir] + slowInFrameNo; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = currentDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; +int32 Router::addSlowInFrames(_walkData *walkAnim) { + if (_usingSlowInFrames && _modularPath[1].num > 0) { + for (uint slowInFrameNo = 0; slowInFrameNo < _numberOfSlowInFrames[_currentDir]; slowInFrameNo++) { + walkAnim[_stepCount].frame = _firstSlowInFrame[_currentDir] + slowInFrameNo; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = _currentDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } return 1; } @@ -935,30 +765,30 @@ int32 AddSlowInFrames(_walkData *walkAnim) { return 0; } -void EarlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata) { +void Router::earlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata) { int32 slowOutFrameNo; int32 walk_pc; _walkData *walkAnim; debug(5, "EARLY SLOW-OUT"); - LoadWalkData(ob_walkdata); + loadWalkData(ob_walkdata); debug(5, "********************************"); - debug(5, "framesPerStep = %d", framesPerStep); - debug(5, "numberOfSlowOutFrames = %d", numberOfSlowOutFrames); - debug(5, "firstWalkingTurnLeftFrame = %d", firstWalkingTurnLeftFrame); - debug(5, "firstWalkingTurnRightFrame = %d", firstWalkingTurnRightFrame); - debug(5, "firstSlowOutFrame = %d", firstSlowOutFrame); + debug(5, "_framesPerStep = %d", _framesPerStep); + debug(5, "_numberOfSlowOutFrames = %d", _numberOfSlowOutFrames); + debug(5, "_firstWalkingTurnLeftFrame = %d", _firstWalkingTurnLeftFrame); + debug(5, "_firstWalkingTurnRightFrame = %d", _firstWalkingTurnRightFrame); + debug(5, "_firstSlowOutFrame = %d", _firstSlowOutFrame); debug(5, "********************************"); walk_pc = ob_mega->walk_pc; // lock the _walkData array (NB. AFTER loading walkgrid & walkdata!) - walkAnim = LockRouteMem(); + walkAnim = lockRouteMem(); // if this mega does actually have slow-out frames - if (usingSlowOutFrames) { + if (_usingSlowOutFrames) { // overwrite the next step (half a cycle) of the walk // (ie .step - 0..5) @@ -970,23 +800,23 @@ void EarlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata) { // frame number of slow-out - remember, there may be // more slow-out frames than walk-frames! - if (walkAnim[walk_pc].frame >= firstWalkingTurnRightFrame) { + if (walkAnim[walk_pc].frame >= _firstWalkingTurnRightFrame) { // if it's a walking turn-right, rather than a // normal step, then map it to a normal step // frame first - walkAnim[walk_pc].frame -= firstWalkingTurnRightFrame; + walkAnim[walk_pc].frame -= _firstWalkingTurnRightFrame; debug(5, "MAPPED TO WALK: walkAnim[%d].frame = %d (walking turn-right frame --> walk frame)", walk_pc, walkAnim[walk_pc].frame); - } else if (walkAnim[walk_pc].frame >= firstWalkingTurnLeftFrame) { + } else if (walkAnim[walk_pc].frame >= _firstWalkingTurnLeftFrame) { // if it's a walking turn-left, rather than a // normal step, then map it to a normal step // frame first - walkAnim[walk_pc].frame -= firstWalkingTurnLeftFrame; + walkAnim[walk_pc].frame -= _firstWalkingTurnLeftFrame; debug(5, "MAPPED TO WALK: walkAnim[%d].frame = %d (walking turn-left frame --> walk frame)", walk_pc, walkAnim[walk_pc].frame); } - walkAnim[walk_pc].frame += firstSlowOutFrame + ((walkAnim[walk_pc].frame / framesPerStep) * (numberOfSlowOutFrames - framesPerStep)); + walkAnim[walk_pc].frame += _firstSlowOutFrame + ((walkAnim[walk_pc].frame / _framesPerStep) * (_numberOfSlowOutFrames - _framesPerStep)); walkAnim[walk_pc].step = 0; debug(5, "SLOW-OUT FRAME: walkAnim[%d].frame = %d",walk_pc, walkAnim[walk_pc].frame); walk_pc++; @@ -994,7 +824,7 @@ void EarlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata) { // add stationary frame(s) (OPTIONAL) - for (slowOutFrameNo = framesPerStep; slowOutFrameNo < numberOfSlowOutFrames; slowOutFrameNo++) { + for (slowOutFrameNo = _framesPerStep; slowOutFrameNo < _numberOfSlowOutFrames; slowOutFrameNo++) { walkAnim[walk_pc].frame = walkAnim[walk_pc - 1].frame + 1; debug(5, "EXTRA FRAME: walkAnim[%d].frame = %d", walk_pc, walkAnim[walk_pc].frame); walkAnim[walk_pc].step = 0; @@ -1007,7 +837,7 @@ void EarlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata) { // this mega doesn't have slow-out frames // stand in current direction - walkAnim[walk_pc].frame = firstStandFrame + walkAnim[walk_pc - 1].dir; + walkAnim[walk_pc].frame = _firstStandFrame + walkAnim[walk_pc - 1].dir; walkAnim[walk_pc].step = 0; walkAnim[walk_pc].dir = walkAnim[walk_pc - 1].dir; walkAnim[walk_pc].x = walkAnim[walk_pc - 1].x; @@ -1025,19 +855,19 @@ void EarlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata) { // SLOW OUT -void AddSlowOutFrames(_walkData *walkAnim) { +void Router::addSlowOutFrames(_walkData *walkAnim) { int32 slowOutFrameNo; // if the mega did actually walk, we overwrite the last step (half a // cycle) with slow-out frames + add any necessary stationary frames - if (usingSlowOutFrames && lastCount >= framesPerStep) { + if (_usingSlowOutFrames && _lastCount >= _framesPerStep) { // place stop frames here // slowdown at the end of the last walk - slowOutFrameNo = lastCount - framesPerStep; + slowOutFrameNo = _lastCount - _framesPerStep; - debug(5, "SLOW OUT: slowOutFrameNo(%d) = lastCount(%d) - framesPerStep(%d)", slowOutFrameNo, lastCount, framesPerStep); + debug(5, "SLOW OUT: slowOutFrameNo(%d) = _lastCount(%d) - _framesPerStep(%d)", slowOutFrameNo, _lastCount, _framesPerStep); // overwrite the last step (half a cycle) of the walk @@ -1046,32 +876,32 @@ void AddSlowOutFrames(_walkData *walkAnim) { // frame number of slow-out - remember, there may be // more slow-out frames than walk-frames! - walkAnim[slowOutFrameNo].frame += firstSlowOutFrame + ((walkAnim[slowOutFrameNo].frame / framesPerStep) * (numberOfSlowOutFrames - framesPerStep)); + walkAnim[slowOutFrameNo].frame += _firstSlowOutFrame + ((walkAnim[slowOutFrameNo].frame / _framesPerStep) * (_numberOfSlowOutFrames - _framesPerStep)); // because no longer a normal walk-step walkAnim[slowOutFrameNo].step = 0; debug(5, "walkAnim[%d].frame = %d",slowOutFrameNo,walkAnim[slowOutFrameNo].frame); slowOutFrameNo++; - } while (slowOutFrameNo < lastCount); + } while (slowOutFrameNo < _lastCount); // add stationary frame(s) (OPTIONAL) - for (slowOutFrameNo = framesPerStep; slowOutFrameNo < numberOfSlowOutFrames; slowOutFrameNo++) { - walkAnim[stepCount].frame = walkAnim[stepCount - 1].frame + 1; + for (slowOutFrameNo = _framesPerStep; slowOutFrameNo < _numberOfSlowOutFrames; slowOutFrameNo++) { + walkAnim[_stepCount].frame = walkAnim[_stepCount - 1].frame + 1; - debug(5, "EXTRA FRAMES: walkAnim[%d].frame = %d", stepCount, walkAnim[stepCount].frame); + debug(5, "EXTRA FRAMES: walkAnim[%d].frame = %d", _stepCount, walkAnim[_stepCount].frame); - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = walkAnim[stepCount - 1].dir; - walkAnim[stepCount].x = walkAnim[stepCount - 1].x; - walkAnim[stepCount].y = walkAnim[stepCount - 1].y; - stepCount++; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = walkAnim[_stepCount - 1].dir; + walkAnim[_stepCount].x = walkAnim[_stepCount - 1].x; + walkAnim[_stepCount].y = walkAnim[_stepCount - 1].y; + _stepCount++; } } } -void SlidyWalkAnimator(_walkData *walkAnim) { +void Router::slidyWalkAnimator(_walkData *walkAnim) { /********************************************************************* * Skidding every where HardWalk creates an animation that exactly * fits the smoothPath and uses foot slipping to fit whole steps into @@ -1081,7 +911,6 @@ void SlidyWalkAnimator(_walkData *walkAnim) { * Returns: rout * * produce a module list from the line data - * *********************************************************************/ static int32 left = 0; @@ -1105,39 +934,39 @@ void SlidyWalkAnimator(_walkData *walkAnim) { int32 frames; p = 0; - lastDir = modularPath[0].dir; - currentDir = modularPath[1].dir; + lastDir = _modularPath[0].dir; + _currentDir = _modularPath[1].dir; - if (currentDir == NO_DIRECTIONS) - currentDir = lastDir; + if (_currentDir == NO_DIRECTIONS) + _currentDir = lastDir; - moduleX = startX; - moduleY = startY; - module16X = moduleX << 16; - module16Y = moduleY << 16; - stepCount = 0; + _moduleX = _startX; + _moduleY = _startY; + module16X = _moduleX << 16; + module16Y = _moduleY << 16; + _stepCount = 0; // START THE WALK WITH THE FIRST STANDFRAME THIS MAY CAUSE A DELAY // BUT IT STOPS THE PLAYER MOVING FOR COLLISIONS ARE DETECTED debug(5, "SLIDY: STARTING THE WALK"); - module = framesPerChar + lastDir; - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module = _framesPerChar + lastDir; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; // TURN TO START THE WALK debug(5, "SLIDY: TURNING TO START THE WALK"); // rotate if we need to - if (lastDir != currentDir) { + if (lastDir != _currentDir) { // get the direction to turn - turnDir = currentDir - lastDir; + turnDir = _currentDir - lastDir; if (turnDir < 0) turnDir += NO_DIRECTIONS; @@ -1149,56 +978,56 @@ void SlidyWalkAnimator(_walkData *walkAnim) { // rotate to new walk direction // for george and nico put in a head turn at the start - if (usingStandingTurnFrames) { + if (_usingStandingTurnFrames) { // new frames for turn frames 29oct95jps if (turnDir < 0) - module = firstStandingTurnLeftFrame + lastDir; + module = _firstStandingTurnLeftFrame + lastDir; else - module = firstStandingTurnRightFrame + lastDir; - - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module = _firstStandingTurnRightFrame + lastDir; + + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } // rotate till were facing new dir then go back 45 degrees - while (lastDir != currentDir) { + while (lastDir != _currentDir) { lastDir += turnDir; // new frames for turn frames 29oct95jps if (turnDir < 0) { if ( lastDir < 0) lastDir += NO_DIRECTIONS; - module = firstStandingTurnLeftFrame + lastDir; + module = _firstStandingTurnLeftFrame + lastDir; } else { if ( lastDir > 7) lastDir -= NO_DIRECTIONS; - module = firstStandingTurnRightFrame + lastDir; + module = _firstStandingTurnRightFrame + lastDir; } - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } // the back 45 degrees bit // step back one because new head turn for george takes us // past the new dir - stepCount--; + _stepCount--; } // his head is in the right direction - lastRealDir = currentDir; + lastRealDir = _currentDir; // SLIDY: THE SLOW IN - AddSlowInFrames(walkAnim); + addSlowInFrames(walkAnim); // THE WALK @@ -1209,94 +1038,94 @@ void SlidyWalkAnimator(_walkData *walkAnim) { // (0 = left; 1 = right) - if (leadingLeg[currentDir] == 0) { + if (_leadingLeg[_currentDir] == 0) { // start the walk on the left leg (ie. at beginning of the // first step of the walk cycle) left = 0; } else { // start the walk on the right leg (ie. at beginning of the // second step of the walk cycle) - left = framesPerStep; + left = _framesPerStep; } - lastCount = stepCount; + _lastCount = _stepCount; // this ensures that we don't put in turn frames for the start lastDir = 99; // this ensures that we don't put in turn frames for the start - currentDir = 99; + _currentDir = 99; do { - assert(stepCount < O_WALKANIM_SIZE); - while (modularPath[p].num == 0) { + assert(_stepCount < O_WALKANIM_SIZE); + while (_modularPath[p].num == 0) { p++; - if (currentDir != 99) - lastRealDir = currentDir; - lastDir = currentDir; - lastCount = stepCount; + if (_currentDir != 99) + lastRealDir = _currentDir; + lastDir = _currentDir; + _lastCount = _stepCount; } // calculate average amount to lose in each step on the way // to the next node - currentDir = modularPath[p].dir; + _currentDir = _modularPath[p].dir; - if (currentDir < NO_DIRECTIONS) { - module = currentDir * framesPerStep * 2 + left; + if (_currentDir < NO_DIRECTIONS) { + module = _currentDir * _framesPerStep * 2 + left; if (left == 0) - left = framesPerStep; + left = _framesPerStep; else left = 0; - moduleEnd = module + framesPerStep; + moduleEnd = module + _framesPerStep; step = 0; - scale = (scaleA * moduleY + scaleB); + scale = (_scaleA * _moduleY + _scaleB); do { - module16X += dx[module] * scale; - module16Y += dy[module] * scale; - moduleX = module16X >> 16; - moduleY = module16Y >> 16; - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = step; // normally 0,1,2,3,4,5,0,1,2,etc - walkAnim[stepCount].dir = currentDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module16X += _dx[module] * scale; + module16Y += _dy[module] * scale; + _moduleX = module16X >> 16; + _moduleY = module16Y >> 16; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = step; // normally 0,1,2,3,4,5,0,1,2,etc + walkAnim[_stepCount].dir = _currentDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; step++; module++; } while (module < moduleEnd); - stepX = modX[modularPath[p].dir]; - stepY = modY[modularPath[p].dir]; - errorX = modularPath[p].x - moduleX; + stepX = _modX[_modularPath[p].dir]; + stepY = _modY[_modularPath[p].dir]; + errorX = _modularPath[p].x - _moduleX; errorX = errorX * stepX; - errorY = modularPath[p].y - moduleY; + errorY = _modularPath[p].y - _moduleY; errorY = errorY * stepY; if (errorX < 0 || errorY < 0) { - modularPath[p].num = 0; // the end of the path + _modularPath[p].num = 0; // the end of the path // okay those last steps took us past our // target but do we want to scoot or moonwalk - frames = stepCount - lastCount; - errorX = modularPath[p].x - walkAnim[stepCount - 1].x; - errorY = modularPath[p].y - walkAnim[stepCount - 1].y; + frames = _stepCount - _lastCount; + errorX = _modularPath[p].x - walkAnim[_stepCount - 1].x; + errorY = _modularPath[p].y - walkAnim[_stepCount - 1].y; - if (frames > framesPerStep) { - lastErrorX = modularPath[p].x - walkAnim[stepCount - 7].x; - lastErrorY = modularPath[p].y - walkAnim[stepCount - 7].y; + if (frames > _framesPerStep) { + lastErrorX = _modularPath[p].x - walkAnim[_stepCount - 7].x; + lastErrorY = _modularPath[p].y - walkAnim[_stepCount - 7].y; if (stepX == 0) { if (3 * ABS(lastErrorY) < ABS(errorY)) { // the last stop was // closest - stepCount -= framesPerStep; + _stepCount -= _framesPerStep; if (left == 0) - left = framesPerStep; + left = _framesPerStep; else left = 0; } @@ -1304,135 +1133,135 @@ void SlidyWalkAnimator(_walkData *walkAnim) { if (3 * ABS(lastErrorX) < ABS(errorX)) { //the last stop was // closest - stepCount -= framesPerStep; + _stepCount -= _framesPerStep; if (left == 0) - left = framesPerStep; + left = _framesPerStep; else left = 0; } } } - errorX = modularPath[p].x - walkAnim[stepCount-1].x; - errorY = modularPath[p].y - walkAnim[stepCount-1].y; + errorX = _modularPath[p].x - walkAnim[_stepCount-1].x; + errorY = _modularPath[p].y - walkAnim[_stepCount-1].y; // okay we've reached the end but we still // have an error if (errorX != 0) { frameCount = 0; - frames = stepCount - lastCount; + frames = _stepCount - _lastCount; do { frameCount++; - walkAnim[lastCount + frameCount - 1].x += errorX * frameCount / frames; + walkAnim[_lastCount + frameCount - 1].x += errorX * frameCount / frames; } while (frameCount < frames); } if (errorY != 0) { frameCount = 0; - frames = stepCount - lastCount; + frames = _stepCount - _lastCount; do { frameCount++; - walkAnim[lastCount + frameCount - 1].y += errorY * frameCount / frames; + walkAnim[_lastCount + frameCount - 1].y += errorY * frameCount / frames; } while (frameCount < frames); } // Now is the time to put in the turn frames // for the last turn - if (frames < framesPerStep) { + if (frames < _framesPerStep) { // this ensures that we don't put in // turn frames for this walk or the // next - currentDir = 99; + _currentDir = 99; } - if (currentDir != 99) - lastRealDir = currentDir; + if (_currentDir != 99) + lastRealDir = _currentDir; // check each turn condition in turn // only for george - if (lastDir != 99 && currentDir != 99 && usingWalkingTurnFrames) { + if (lastDir != 99 && _currentDir != 99 && _usingWalkingTurnFrames) { // 1 and -7 going right -1 and 7 going // left - lastDir = currentDir - lastDir; + lastDir = _currentDir - lastDir; if (lastDir == -1 || lastDir == 7 || lastDir == -2 || lastDir == 6) { // turn at the end of the last // walk - frame = lastCount - framesPerStep; + _frame = _lastCount - _framesPerStep; do { // turning left - walkAnim[frame].frame += firstWalkingTurnLeftFrame; - frame++; - } while (frame < lastCount); + walkAnim[_frame].frame += _firstWalkingTurnLeftFrame; + _frame++; + } while (_frame < _lastCount); } else if (lastDir == 1 || lastDir == -7 || lastDir == 2 || lastDir == -6) { // turn at the end of the // current walk - frame = lastCount - framesPerStep; + _frame = _lastCount - _framesPerStep; do { // turning right - walkAnim[frame].frame += firstWalkingTurnRightFrame; - frame++; - } while (frame < lastCount); + walkAnim[_frame].frame += _firstWalkingTurnRightFrame; + _frame++; + } while (_frame < _lastCount); } - lastDir = currentDir; + lastDir = _currentDir; } // all turns checked - lastCount = stepCount; - moduleX = walkAnim[stepCount - 1].x; - moduleY = walkAnim[stepCount - 1].y; - module16X = moduleX << 16; - module16Y = moduleY << 16; + _lastCount = _stepCount; + _moduleX = walkAnim[_stepCount - 1].x; + _moduleY = walkAnim[_stepCount - 1].y; + module16X = _moduleX << 16; + module16Y = _moduleY << 16; } } - } while (modularPath[p].dir < NO_DIRECTIONS); + } while (_modularPath[p].dir < NO_DIRECTIONS); #ifdef _SWORD2_DEBUG if (lastRealDir == 99) - Con_fatal_error("SlidyWalkAnimatorlast direction error"); + Con_fatal_error("slidyWalkAnimatorlast direction error"); #endif // THE SLOW OUT - AddSlowOutFrames(walkAnim); + addSlowOutFrames(walkAnim); // TURNS TO END THE WALK ? // We've done the walk now put in any turns at the end - if (targetDir == 8) { + if (_targetDir == 8) { // ANY direction -> stand in the last direction - module = firstStandFrame + lastRealDir; - targetDir = lastRealDir; - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastRealDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module = _firstStandFrame + lastRealDir; + _targetDir = lastRealDir; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastRealDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } - if (targetDir == 9) { + if (_targetDir == 9) { // 'stance' was non-zero - if (stepCount == 0) { - module = framesPerChar + lastRealDir; - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastRealDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + if (_stepCount == 0) { + module = _framesPerChar + lastRealDir; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastRealDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } - } else if (targetDir != lastRealDir) { + } else if (_targetDir != lastRealDir) { // rotate to target direction - turnDir = targetDir - lastRealDir; + turnDir = _targetDir - lastRealDir; if ( turnDir < 0) turnDir += NO_DIRECTIONS; @@ -1444,82 +1273,84 @@ void SlidyWalkAnimator(_walkData *walkAnim) { // rotate to target direction // for george and nico put in a head turn at the start - if (usingStandingTurnFrames) { + if (_usingStandingTurnFrames) { // new frames for turn frames 29oct95jps if (turnDir < 0) - module = firstStandingTurnLeftFrame + lastDir; + module = _firstStandingTurnLeftFrame + lastDir; else - module = firstStandingTurnRightFrame + lastDir; - - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastRealDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module = _firstStandingTurnRightFrame + lastDir; + + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastRealDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } // rotate if we need to - while (lastRealDir != targetDir) { + while (lastRealDir != _targetDir) { lastRealDir += turnDir; // new frames for turn frames 29oct95jps if (turnDir < 0) { if (lastRealDir < 0) lastRealDir += NO_DIRECTIONS; - module = firstStandingTurnLeftFrame + lastRealDir; + module = _firstStandingTurnLeftFrame + lastRealDir; } else { if (lastRealDir > 7) lastRealDir -= NO_DIRECTIONS; - module = firstStandingTurnRightFrame + lastRealDir; + module = _firstStandingTurnRightFrame + lastRealDir; } - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastRealDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastRealDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } - module = firstStandFrame + lastRealDir; - walkAnim[stepCount - 1].frame = module; + module = _firstStandFrame + lastRealDir; + walkAnim[_stepCount - 1].frame = module; } else { // just stand at the end - module = firstStandFrame + lastRealDir; - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastRealDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module = _firstStandFrame + lastRealDir; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastRealDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } - walkAnim[stepCount].frame = 512; - walkAnim[stepCount].step = 99; - stepCount++; + walkAnim[_stepCount].frame = 512; + walkAnim[_stepCount].step = 99; + _stepCount++; - walkAnim[stepCount].frame = 512; - walkAnim[stepCount].step = 99; - stepCount++; + walkAnim[_stepCount].frame = 512; + walkAnim[_stepCount].step = 99; + _stepCount++; - walkAnim[stepCount].frame = 512; - walkAnim[stepCount].step = 99; + walkAnim[_stepCount].frame = 512; + walkAnim[_stepCount].step = 99; // write all the frames to "debug.txt" debug(5, "THE WALKDATA:"); - for (frame = 0; frame <= stepCount; frame++) - debug(5, "walkAnim[%d].frame=%d", frame, walkAnim[frame].frame); + for (_frame = 0; _frame <= _stepCount; _frame++) + debug(5, "walkAnim[%d].frame=%d", _frame, walkAnim[_frame].frame); - debug(5, "RouteFinder RouteSize is %d", stepCount); + debug(5, "routeFinder RouteSize is %d", _stepCount); return; } +#ifndef FORCE_SLIDY + // THE SOLID PATH ROUTINES -int32 SolidPath() { +int32 Router::solidPath() { /********************************************************************* * SolidPath creates a path based on whole steps with no sliding to * get as near as possible to the target without any sliding this @@ -1527,12 +1358,8 @@ int32 SolidPath() { * clicking about. * * produce a module list from the line data - * *********************************************************************/ - // FIXME: It says in the comment about that this function is currently - // unused, but is it really? - int32 smooth; int32 solid; int32 scale; @@ -1545,54 +1372,54 @@ int32 SolidPath() { solid = 1; smooth = 1; - modularPath[0].x = smoothPath[0].x; - modularPath[0].y = smoothPath[0].y; - modularPath[0].dir = smoothPath[0].dir; - modularPath[0].num = 0; + _modularPath[0].x = _smoothPath[0].x; + _modularPath[0].y = _smoothPath[0].y; + _modularPath[0].dir = _smoothPath[0].dir; + _modularPath[0].num = 0; do { - scale = scaleA * smoothPath[smooth].y + scaleB; - deltaX = smoothPath[smooth].x - modularPath[solid - 1].x; - deltaY = smoothPath[smooth].y - modularPath[solid - 1].y; - stepX = modX[smoothPath[smooth].dir]; - stepY = modY[smoothPath[smooth].dir]; + scale = _scaleA * _smoothPath[smooth].y + _scaleB; + deltaX = _smoothPath[smooth].x - _modularPath[solid - 1].x; + deltaY = _smoothPath[smooth].y - _modularPath[solid - 1].y; + stepX = _modX[_smoothPath[smooth].dir]; + stepY = _modY[_smoothPath[smooth].dir]; stepX = stepX * scale; stepY = stepY * scale; stepX = stepX >> 16; stepY = stepY >> 16; if (ABS(deltaX) >= ABS(stepX) && ABS(deltaY) >= ABS(stepY)) { - modularPath[solid].x = smoothPath[smooth].x; - modularPath[solid].y = smoothPath[smooth].y; - modularPath[solid].dir = smoothPath[smooth].dir; - modularPath[solid].num = 1; + _modularPath[solid].x = _smoothPath[smooth].x; + _modularPath[solid].y = _smoothPath[smooth].y; + _modularPath[solid].dir = _smoothPath[smooth].dir; + _modularPath[solid].num = 1; solid++; } smooth++; - } while (smoothPath[smooth].num < ROUTE_END_FLAG); + } while (_smoothPath[smooth].num < ROUTE_END_FLAG); // in case the last bit had no steps if (solid == 1) { // there were no paths so put in a dummy end solid = 2; - modularPath[1].dir = smoothPath[0].dir; - modularPath[1].num = 0; + _modularPath[1].dir = _smoothPath[0].dir; + _modularPath[1].num = 0; } - modularPath[solid - 1].x = smoothPath[smooth - 1].x; - modularPath[solid - 1].y = smoothPath[smooth - 1].y; + _modularPath[solid - 1].x = _smoothPath[smooth - 1].x; + _modularPath[solid - 1].y = _smoothPath[smooth - 1].y; // set up the end of the walk - modularPath[solid].x = smoothPath[smooth - 1].x; - modularPath[solid].y = smoothPath[smooth - 1].y; - modularPath[solid].dir = 9; - modularPath[solid].num = ROUTE_END_FLAG; + _modularPath[solid].x = _smoothPath[smooth - 1].x; + _modularPath[solid].y = _smoothPath[smooth - 1].y; + _modularPath[solid].dir = 9; + _modularPath[solid].num = ROUTE_END_FLAG; return 1; } -int32 SolidWalkAnimator(_walkData *walkAnim) { +int32 Router::solidWalkAnimator(_walkData *walkAnim) { /********************************************************************* * SolidWalk creates an animation based on whole steps with no sliding * to get as near as possible to the target without any sliding. This @@ -1620,26 +1447,26 @@ int32 SolidWalkAnimator(_walkData *walkAnim) { // start at the beginning for a change - lastDir = modularPath[0].dir; + lastDir = _modularPath[0].dir; p = 1; - currentDir = modularPath[1].dir; - module = framesPerChar + lastDir; - moduleX = startX; - moduleY = startY; - module16X = moduleX << 16; - module16Y = moduleY << 16; - stepCount = 0; + _currentDir = _modularPath[1].dir; + module = _framesPerChar + lastDir; + _moduleX = _startX; + _moduleY = _startY; + module16X = _moduleX << 16; + module16Y = _moduleY << 16; + _stepCount = 0; // START THE WALK WITH THE FIRST STANDFRAME THIS MAY CAUSE A DELAY // BUT IT STOPS THE PLAYER MOVING FOR COLLISIONS ARE DETECTED debug(5, "SOLID: STARTING THE WALK"); - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; // TURN TO START THE WALK @@ -1647,9 +1474,9 @@ int32 SolidWalkAnimator(_walkData *walkAnim) { // rotate if we need to - if (lastDir != currentDir) { + if (lastDir != _currentDir) { // get the direction to turn - turnDir = currentDir - lastDir; + turnDir = _currentDir - lastDir; if (turnDir < 0) turnDir += NO_DIRECTIONS; @@ -1661,55 +1488,55 @@ int32 SolidWalkAnimator(_walkData *walkAnim) { // rotate to new walk direction // for george and nico put in a head turn at the start - if (usingStandingTurnFrames) { + if (_usingStandingTurnFrames) { // new frames for turn frames 29oct95jps if (turnDir < 0) - module = firstStandingTurnLeftFrame + lastDir; + module = _firstStandingTurnLeftFrame + lastDir; else - module = firstStandingTurnRightFrame + lastDir; - - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module = _firstStandingTurnRightFrame + lastDir; + + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } // rotate till were facing new dir then go back 45 degrees - while (lastDir != currentDir) { + while (lastDir != _currentDir) { lastDir += turnDir; // new frames for turn frames 29oct95jps if (turnDir < 0) { if (lastDir < 0) lastDir += NO_DIRECTIONS; - module = firstStandingTurnLeftFrame + lastDir; + module = _firstStandingTurnLeftFrame + lastDir; } else { if ( lastDir > 7) lastDir -= NO_DIRECTIONS; - module = firstStandingTurnRightFrame + lastDir; + module = _firstStandingTurnRightFrame + lastDir; } - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = lastDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = lastDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; } // the back 45 degrees bit // step back one because new head turn for george takes us // past the new dir - stepCount--; + _stepCount--; } // THE SLOW IN - slowStart = AddSlowInFrames(walkAnim); + slowStart = addSlowInFrames(walkAnim); // THE WALK @@ -1719,89 +1546,89 @@ int32 SolidWalkAnimator(_walkData *walkAnim) { // slow-in frames were drawn // (0 = left; 1 = right) - if (leadingLeg[currentDir] == 0) { + if (_leadingLeg[_currentDir] == 0) { // start the walk on the left leg (ie. at beginning of the // first step of the walk cycle) left = 0; } else { // start the walk on the right leg (ie. at beginning of the // second step of the walk cycle) - left = framesPerStep; + left = _framesPerStep; } - lastCount = stepCount; + _lastCount = _stepCount; // this ensures that we don't put in turn frames for the start lastDir = 99; // this ensures that we don't put in turn frames for the start - currentDir = 99; + _currentDir = 99; do { - while (modularPath[p].num > 0) { - currentDir = modularPath[p].dir; - if (currentDir< NO_DIRECTIONS) { - module = currentDir * framesPerStep * 2 + left; + while (_modularPath[p].num > 0) { + _currentDir = _modularPath[p].dir; + if (_currentDir < NO_DIRECTIONS) { + module = _currentDir * _framesPerStep * 2 + left; if (left == 0) - left = framesPerStep; + left = _framesPerStep; else left = 0; - moduleEnd = module + framesPerStep; + moduleEnd = module + _framesPerStep; step = 0; - scale = (scaleA * moduleY + scaleB); + scale = (_scaleA * _moduleY + _scaleB); do { - module16X += dx[module] * scale; - module16Y += dy[module] * scale; - moduleX = module16X >> 16; - moduleY = module16Y >> 16; - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = step; // normally 0,1,2,3,4,5,0,1,2,etc - walkAnim[stepCount].dir = currentDir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module16X += _dx[module] * scale; + module16Y += _dy[module] * scale; + _moduleX = module16X >> 16; + _moduleY = module16Y >> 16; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = step; // normally 0,1,2,3,4,5,0,1,2,etc + walkAnim[_stepCount].dir = _currentDir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; module++; step++; } while (module < moduleEnd); - errorX = modularPath[p].x - moduleX; - errorX = errorX * modX[modularPath[p].dir]; - errorY = modularPath[p].y - moduleY; - errorY = errorY * modY[modularPath[p].dir]; + errorX = _modularPath[p].x - _moduleX; + errorX = errorX * _modX[_modularPath[p].dir]; + errorY = _modularPath[p].y - _moduleY; + errorY = errorY * _modY[_modularPath[p].dir]; if (errorX < 0 || errorY < 0) { - modularPath[p].num = 0; - stepCount -= framesPerStep; + _modularPath[p].num = 0; + _stepCount -= _framesPerStep; if (left == 0) - left = framesPerStep; + left = _framesPerStep; else left = 0; // Okay this is the end of a section - moduleX = walkAnim[stepCount - 1].x; - moduleY = walkAnim[stepCount - 1].y; - module16X = moduleX << 16; - module16Y = moduleY << 16; - modularPath[p].x =moduleX; - modularPath[p].y =moduleY; + _moduleX = walkAnim[_stepCount - 1].x; + _moduleY = walkAnim[_stepCount - 1].y; + module16X = _moduleX << 16; + module16Y = _moduleY << 16; + _modularPath[p].x = _moduleX; + _modularPath[p].y = _moduleY; // Now is the time to put in the turn // frames for the last turn - if (stepCount - lastCount < framesPerStep) { + if (_stepCount - _lastCount < _framesPerStep) { // no step taken // clean up if a slow in but no // walk if (slowStart == 1) { - stepCount -= numberOfSlowInFrames[currentDir]; - lastCount -= numberOfSlowInFrames[currentDir]; + _stepCount -= _numberOfSlowInFrames[_currentDir]; + _lastCount -= _numberOfSlowInFrames[_currentDir]; slowStart = 0; } @@ -1809,112 +1636,112 @@ int32 SolidWalkAnimator(_walkData *walkAnim) { // put in turn frames for this // walk or the next - currentDir = 99; + _currentDir = 99; } // check each turn condition in turn - if (lastDir != 99 && currentDir != 99 && usingWalkingTurnFrames) { + if (lastDir != 99 && _currentDir != 99 && _usingWalkingTurnFrames) { // only for george // 1 and -7 going right -1 and // 7 going left - lastDir = currentDir - lastDir; + lastDir = _currentDir - lastDir; if (lastDir == -1 || lastDir == 7 || lastDir == -2 || lastDir == 6) { // turn at the end of // the last walk - frame = lastCount - framesPerStep; + _frame = _lastCount - _framesPerStep; do { // turning left - walkAnim[frame].frame += firstWalkingTurnLeftFrame; - frame++; - } while (frame < lastCount); + walkAnim[_frame].frame += _firstWalkingTurnLeftFrame; + _frame++; + } while (_frame < _lastCount); } else if (lastDir == 1 || lastDir == -7 || lastDir == 2 || lastDir == -6) { // turn at the end of // the current walk - frame = lastCount - framesPerStep; + _frame = _lastCount - _framesPerStep; do { // turning right - walkAnim[frame].frame += firstWalkingTurnRightFrame; - frame++; - } while (frame < lastCount); + walkAnim[_frame].frame += _firstWalkingTurnRightFrame; + _frame++; + } while (_frame < _lastCount); } } // all turns checked - lastCount = stepCount; + _lastCount = _stepCount; } } } p++; - lastDir = currentDir; + lastDir = _currentDir; // can only be valid first time round slowStart = 0; - } while (modularPath[p].dir < NO_DIRECTIONS); - + } while (_modularPath[p].dir < NO_DIRECTIONS); // THE SLOW OUT - AddSlowOutFrames(walkAnim); + addSlowOutFrames(walkAnim); - module = framesPerChar + modularPath[p - 1].dir; - walkAnim[stepCount].frame = module; - walkAnim[stepCount].step = 0; - walkAnim[stepCount].dir = modularPath[p - 1].dir; - walkAnim[stepCount].x = moduleX; - walkAnim[stepCount].y = moduleY; - stepCount++; + module = _framesPerChar + _modularPath[p - 1].dir; + walkAnim[_stepCount].frame = module; + walkAnim[_stepCount].step = 0; + walkAnim[_stepCount].dir = _modularPath[p - 1].dir; + walkAnim[_stepCount].x = _moduleX; + walkAnim[_stepCount].y = _moduleY; + _stepCount++; - walkAnim[stepCount].frame = 512; - walkAnim[stepCount].step = 99; - stepCount++; + walkAnim[_stepCount].frame = 512; + walkAnim[_stepCount].step = 99; + _stepCount++; - walkAnim[stepCount].frame = 512; - walkAnim[stepCount].step = 99; - stepCount++; + walkAnim[_stepCount].frame = 512; + walkAnim[_stepCount].step = 99; + _stepCount++; - walkAnim[stepCount].frame = 512; - walkAnim[stepCount].step = 99; + walkAnim[_stepCount].frame = 512; + walkAnim[_stepCount].step = 99; debug(5, "THE WALKDATA:"); - for (frame = 0; frame <= stepCount; frame++) - debug(5, "walkAnim[%d].frame=%d", frame, walkAnim[frame].frame); + for (_frame = 0; _frame <= _stepCount; _frame++) + debug(5, "walkAnim[%d].frame=%d", _frame, walkAnim[_frame].frame); // NO END TURNS - debug(5, "RouteFinder RouteSize is %d", stepCount); + debug(5, "routeFinder RouteSize is %d", _stepCount); // now check the route i = 0; do { - if (!Check(modularPath[i].x, modularPath[i].y, modularPath[i + 1].x, modularPath[i + 1].y)) + if (!check(_modularPath[i].x, _modularPath[i].y, _modularPath[i + 1].x, _modularPath[i + 1].y)) p = 0; i++; } while (i < p - 1); if (p != 0) { - targetDir = modularPath[p - 1].dir; - if (CheckTarget(moduleX, moduleY) == 3) { + _targetDir = _modularPath[p - 1].dir; + if (checkTarget(_moduleX, _moduleY) == 3) { // new target on a line p = 0; - debug(5, "Solid walk target was on a line %d %d", moduleX, moduleY); + debug(5, "Solid walk target was on a line %d %d", _moduleX, _moduleY); } } return p; } +#endif // THE SCAN ROUTINES -int32 Scan(int32 level) { +int32 Router::scan(int32 level) { /********************************************************************* - * Called successively from RouteFinder until no more changes take + * Called successively from routeFinder until no more changes take * place in the grid array, ie he best path has been found * * Scans through every point in the node array and checks if there is @@ -1942,26 +1769,26 @@ int32 Scan(int32 level) { i = 0; do { - if (node[i].dist < node[nnodes].dist && node[i].level == level) { - x1 = node[i].x; - y1 = node[i].y; - k = nnodes; + if (_node[i].dist < _node[_nnodes].dist && _node[i].level == level) { + x1 = _node[i].x; + y1 = _node[i].y; + k = _nnodes; do { - if (node[k].dist > node[i].dist) { - x2 = node[k].x; - y2 = node[k].y; + if (_node[k].dist > _node[i].dist) { + x2 = _node[k].x; + y2 = _node[k].y; if (ABS(x2 - x1) > 4.5 * ABS(y2-y1)) distance = (8 * ABS(x2 - x1) + 18 * ABS(y2 - y1)) / (54 * 8) + 1; else distance = (6 * ABS(x2 - x1) + 36 * ABS(y2 - y1)) / (36 * 14) + 1; - if (distance + node[i].dist < node[nnodes].dist && distance + node[i].dist < node[k].dist) { - if (NewCheck(0, x1, y1, x2, y2)) { - node[k].level = level + 1; - node[k].dist = distance + node[i].dist; - node[k].prev = i; + if (distance + _node[i].dist < _node[_nnodes].dist && distance + _node[i].dist < _node[k].dist) { + if (newCheck(0, x1, y1, x2, y2)) { + _node[k].level = level + 1; + _node[k].dist = distance + _node[i].dist; + _node[k].prev = i; changed = 1; } } @@ -1970,17 +1797,17 @@ int32 Scan(int32 level) { } while (k > 0); } i++; - } while (i < nnodes); + } while (i < _nnodes); return changed; } -int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { +int32 Router::newCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { /********************************************************************* - * NewCheck routine checks if the route between two points can be + * newCheck routine checks if the route between two points can be * achieved without crossing any of the bars in the Bars array. * - * NewCheck differs from check in that that 4 route options are + * newCheck differs from check in that that 4 route options are * considered corresponding to actual walked routes. * * Note distance doesnt take account of shrinking ??? @@ -2019,11 +1846,11 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { // make the route options - if (diagonaly * ldx > diagonalx * ldy) { + if (_diagonaly * ldx > _diagonalx * ldy) { // dir = 1,2 or 2,3 or 5,6 or 6,7 dly = ldy; - dlx = (ldy * diagonalx) / diagonaly; + dlx = (ldy * _diagonalx) / _diagonaly; ldx = ldx - dlx; dlx = dlx * dirX; dly = dly * dirY; @@ -2033,9 +1860,9 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { //options are //square, diagonal a code 1 route - step1 = Check(x1, y1, x1 + ldx, y1); + step1 = check(x1, y1, x1 + ldx, y1); if (step1 != 0) { - step2 = Check(x1 + ldx, y1, x2, y2); + step2 = check(x1 + ldx, y1, x2, y2); if (step2 != 0) { steps = step1 + step2; options = options + 2; @@ -2045,9 +1872,9 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { //diagonal, square a code 2 route if (steps == 0 || status == 1) { - step1 = Check(x1, y1, x1 + dlx, y1 + dly); + step1 = check(x1, y1, x1 + dlx, y1 + dly); if (step1 != 0) { - step2 = Check(x1 + dlx, y2, x2, y2); + step2 = check(x1 + dlx, y2, x2, y2); if (step2 != 0) { steps = step1 + step2; options = options + 4; @@ -2058,11 +1885,11 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { //halfsquare, diagonal, halfsquare a code 0 route if (steps == 0 || status == 1) { - step1 = Check(x1, y1, x1 + ldx / 2, y1); + step1 = check(x1, y1, x1 + ldx / 2, y1); if (step1 != 0) { - step2 = Check(x1 + ldx / 2, y1, x1 + ldx / 2 + dlx, y2); + step2 = check(x1 + ldx / 2, y1, x1 + ldx / 2 + dlx, y2); if (step2 != 0) { - step3 = Check(x1 + ldx / 2 + dlx, y2, x2, y2); + step3 = check(x1 + ldx / 2 + dlx, y2, x2, y2); if (step3 != 0) { steps = step1 + step2 + step3; options++; @@ -2074,11 +1901,11 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { //halfdiagonal, square, halfdiagonal a code 3 route if (steps == 0 || status == 1) { - step1 = Check(x1, y1, x1 + dlx / 2, y1 + dly / 2); + step1 = check(x1, y1, x1 + dlx / 2, y1 + dly / 2); if (step1 != 0) { - step2 = Check(x1 + dlx / 2, y1 + dly / 2, x1 + ldx + dlx / 2, y1 + dly / 2); + step2 = check(x1 + dlx / 2, y1 + dly / 2, x1 + ldx + dlx / 2, y1 + dly / 2); if (step2 != 0) { - step3 = Check(x1 + ldx + dlx / 2, y1 + dly / 2, x2, y2); + step3 = check(x1 + ldx + dlx / 2, y1 + dly / 2, x2, y2); if (step3 != 0) { steps = step1 + step2 + step3; options = options + 8; @@ -2090,7 +1917,7 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { // dir = 7,0 or 0,1 or 3,4 or 4,5 dlx = ldx; - dly = (ldx * diagonaly) / diagonalx; + dly = (ldx * _diagonaly) / _diagonalx; ldy = ldy - dly; dlx = dlx * dirX; dly = dly * dirY; @@ -2100,9 +1927,9 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { //options are //square, diagonal a code 1 route - step1 = Check(x1 ,y1, x1, y1 + ldy); + step1 = check(x1 ,y1, x1, y1 + ldy); if (step1 != 0) { - step2 = Check(x1, y1 + ldy, x2, y2); + step2 = check(x1, y1 + ldy, x2, y2); if (step2 != 0) { steps = step1 + step2; options = options + 2; @@ -2112,9 +1939,9 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { //diagonal, square a code 2 route if (steps == 0 || status == 1) { - step1 = Check(x1, y1, x2, y1 + dly); + step1 = check(x1, y1, x2, y1 + dly); if (step1 != 0) { - step2 = Check(x2, y1 + dly, x2, y2); + step2 = check(x2, y1 + dly, x2, y2); if (step2 != 0) { steps = step1 + step2; options = options + 4; @@ -2125,11 +1952,11 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { //halfsquare, diagonal, halfsquare a code 0 route if (steps == 0 || status == 1) { - step1 = Check(x1, y1, x1, y1 + ldy / 2); + step1 = check(x1, y1, x1, y1 + ldy / 2); if (step1 != 0) { - step2 = Check(x1, y1 + ldy / 2, x2, y1 + ldy / 2 + dly); + step2 = check(x1, y1 + ldy / 2, x2, y1 + ldy / 2 + dly); if (step2 != 0) { - step3 = Check(x2, y1 + ldy / 2 + dly, x2, y2); + step3 = check(x2, y1 + ldy / 2 + dly, x2, y2); if (step3 != 0) { steps = step1 + step2 + step3; options++; @@ -2141,11 +1968,11 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { //halfdiagonal, square, halfdiagonal a code 3 route if (steps == 0 || status == 1) { - step1 = Check(x1, y1, x1 + dlx / 2, y1 + dly / 2); + step1 = check(x1, y1, x1 + dlx / 2, y1 + dly / 2); if (step1 != 0) { - step2 = Check(x1 + dlx / 2, y1 + dly / 2, x1 + dlx / 2, y1 + ldy + dly / 2); + step2 = check(x1 + dlx / 2, y1 + dly / 2, x1 + dlx / 2, y1 + ldy + dly / 2); if (step2 != 0) { - step3 = Check(x1 + dlx / 2, y1 + ldy + dly / 2, x2, y2); + step3 = check(x1 + dlx / 2, y1 + ldy + dly / 2, x2, y2); if (step3 != 0) { steps = step1 + step2 + step3; options = options + 8; @@ -2165,7 +1992,7 @@ int32 NewCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2) { // CHECK ROUTINES -int32 Check(int32 x1, int32 y1, int32 x2, int32 y2) { +int32 Router::check(int32 x1, int32 y1, int32 x2, int32 y2) { // call the fastest line check for the given line // returns 1 if line didn't cross any bars @@ -2173,15 +2000,15 @@ int32 Check(int32 x1, int32 y1, int32 x2, int32 y2) { return 1; if (x1 == x2) - return VertCheck(x1, y1, y2); + return vertCheck(x1, y1, y2); if (y1 == y2) - return HorizCheck(x1, y1, x2); + return horizCheck(x1, y1, x2); - return LineCheck(x1, y1, x2, y2); + return lineCheck(x1, y1, x2, y2); } -int32 LineCheck(int32 x1, int32 y1, int32 x2, int32 y2) { +int32 Router::lineCheck(int32 x1, int32 y1, int32 x2, int32 y2) { int32 dirx; int32 diry; int32 co; @@ -2223,31 +2050,31 @@ int32 LineCheck(int32 x1, int32 y1, int32 x2, int32 y2) { do { // skip if not on module - if (xmax >= bars[i].xmin && xmin <= bars[i].xmax) { + if (xmax >= _bars[i].xmin && xmin <= _bars[i].xmax) { // skip if not on module - if (ymax >= bars[i].ymin && ymin <= bars[i].ymax) { + if (ymax >= _bars[i].ymin && ymin <= _bars[i].ymax) { // okay its a valid line calculate an intersept // wow but all this arithmatic we must have // loads of time // slope it he slope between the two lines - slope = (bars[i].dx * diry) - (bars[i].dy *dirx); + slope = (_bars[i].dx * diry) - (_bars[i].dy *dirx); // assuming parallel lines don't cross if (slope != 0) { // calculate x intercept and check its // on both lines - xc = ((bars[i].co * dirx) - (co * bars[i].dx)) / slope; + xc = ((_bars[i].co * dirx) - (co * _bars[i].dx)) / slope; // skip if not on module if (xc >= xmin - 1 && xc <= xmax + 1) { // skip if not on line - if (xc >= bars[i].xmin - 1 && xc <= bars[i].xmax + 1) { - yc = ((bars[i].co * diry) - (co * bars[i].dy)) / slope; + if (xc >= _bars[i].xmin - 1 && xc <= _bars[i].xmax + 1) { + yc = ((_bars[i].co * diry) - (co * _bars[i].dy)) / slope; // skip if not on module if (yc >= ymin - 1 && yc <= ymax + 1) { // skip if not on line - if (yc >= bars[i].ymin - 1 && yc <= bars[i].ymax + 1) { + if (yc >= _bars[i].ymin - 1 && yc <= _bars[i].ymax + 1) { linesCrossed = 0; } } @@ -2257,12 +2084,12 @@ int32 LineCheck(int32 x1, int32 y1, int32 x2, int32 y2) { } } i++; - } while (i < nbars && linesCrossed); + } while (i < _nbars && linesCrossed); return linesCrossed; } -int32 HorizCheck(int32 x1, int32 y, int32 x2) { +int32 Router::horizCheck(int32 x1, int32 y, int32 x2) { int32 ldy; int32 i; int32 xc; @@ -2285,18 +2112,18 @@ int32 HorizCheck(int32 x1, int32 y, int32 x2) { do { // skip if not on module - if (xmax >= bars[i].xmin && xmin <= bars[i].xmax) { + if (xmax >= _bars[i].xmin && xmin <= _bars[i].xmax) { // skip if not on module - if (y >= bars[i].ymin && y <= bars[i].ymax) { + if (y >= _bars[i].ymin && y <= _bars[i].ymax) { // okay its a valid line calculate an intercept // wow but all this arithmatic we must have // loads of time - if (bars[i].dy == 0) + if (_bars[i].dy == 0) linesCrossed = 0; else { - ldy = y - bars[i].y1; - xc = bars[i].x1 + (bars[i].dx * ldy) / bars[i].dy; + ldy = y - _bars[i].y1; + xc = _bars[i].x1 + (_bars[i].dx * ldy) / _bars[i].dy; // skip if not on module if (xc >= xmin - 1 && xc <= xmax + 1) linesCrossed = 0; @@ -2304,12 +2131,12 @@ int32 HorizCheck(int32 x1, int32 y, int32 x2) { } } i++; - } while (i < nbars && linesCrossed); + } while (i < _nbars && linesCrossed); return linesCrossed; } -int32 VertCheck(int32 x, int32 y1, int32 y2) { +int32 Router::vertCheck(int32 x, int32 y1, int32 y2) { int32 ldx; int32 i; int32 yc; @@ -2331,10 +2158,10 @@ int32 VertCheck(int32 x, int32 y1, int32 y2) { i = 0; do { - if (x >= bars[i].xmin && x <= bars[i].xmax) { + if (x >= _bars[i].xmin && x <= _bars[i].xmax) { // overlapping // skip if not on module - if (ymax >= bars[i].ymin && ymin <= bars[i].ymax) { + if (ymax >= _bars[i].ymin && ymin <= _bars[i].ymax) { // okay its a valid line calculate an intercept // wow but all this arithmatic we must have // loads of time @@ -2342,11 +2169,11 @@ int32 VertCheck(int32 x, int32 y1, int32 y2) { // both lines vertical and overlap in x and y // so they cross - if (bars[i].dx == 0) + if (_bars[i].dx == 0) linesCrossed = 0; else { - ldx = x - bars[i].x1; - yc = bars[i].y1 + (bars[i].dy * ldx) / bars[i].dx; + ldx = x - _bars[i].x1; + yc = _bars[i].y1 + (_bars[i].dy * ldx) / _bars[i].dx; // the intercept overlaps if (yc >= ymin - 1 && yc <= ymax + 1) linesCrossed = 0; @@ -2354,12 +2181,12 @@ int32 VertCheck(int32 x, int32 y1, int32 y2) { } } i++; - } while (i < nbars && linesCrossed); + } while (i < _nbars && linesCrossed); return linesCrossed; } -int32 CheckTarget(int32 x, int32 y) { +int32 Router::checkTarget(int32 x, int32 y) { int32 ldx; int32 ldy; int32 i; @@ -2383,18 +2210,18 @@ int32 CheckTarget(int32 x, int32 y) { do { // overlapping line - if (xmax >= bars[i].xmin && xmin <= bars[i].xmax) { + if (xmax >= _bars[i].xmin && xmin <= _bars[i].xmax) { //overlapping line - if (ymax >= bars[i].ymin && ymin <= bars[i].ymax) { + if (ymax >= _bars[i].ymin && ymin <= _bars[i].ymax) { // okay this line overlaps the target calculate // an y intercept for x // vertical line so we know it overlaps y - if (bars[i].dx == 0) + if (_bars[i].dx == 0) yc = 0; else { - ldx = x - bars[i].x1; - yc = bars[i].y1 + (bars[i].dy * ldx) / bars[i].dx; + ldx = x - _bars[i].x1; + yc = _bars[i].y1 + (_bars[i].dy * ldx) / _bars[i].dx; } // overlapping point for y @@ -2404,11 +2231,11 @@ int32 CheckTarget(int32 x, int32 y) { debug(5, "RouteFail due to target on a line %d %d", x, y); } else { // vertical line so we know it overlaps y - if (bars[i].dy == 0) + if (_bars[i].dy == 0) xc = 0; else { - ldy = y - bars[i].y1; - xc = bars[i].x1 + (bars[i].dx * ldy) / bars[i].dy; + ldy = y - _bars[i].y1; + xc = _bars[i].x1 + (_bars[i].dx * ldy) / _bars[i].dy; } // skip if not on module @@ -2421,56 +2248,56 @@ int32 CheckTarget(int32 x, int32 y) { } } i++; - } while (i < nbars && onLine == 0); + } while (i < _nbars && onLine == 0); return onLine; } // THE SETUP ROUTINES -void LoadWalkData(Object_walkdata *ob_walkdata) { - uint8 direction; +void Router::loadWalkData(Object_walkdata *ob_walkdata) { + int i; uint16 firstFrameOfDirection; uint16 walkFrameNo; - uint32 frameCounter = 0; // starts at frame 0 of mega set (16sep96 JEL) + uint32 frameCounter = 0; // starts at frame 0 of mega set - nWalkFrames = ob_walkdata->nWalkFrames; - usingStandingTurnFrames = ob_walkdata->usingStandingTurnFrames; - usingWalkingTurnFrames = ob_walkdata->usingWalkingTurnFrames; - usingSlowInFrames = ob_walkdata->usingSlowInFrames; - usingSlowOutFrames = ob_walkdata->usingSlowOutFrames; + _nWalkFrames = ob_walkdata->nWalkFrames; + _usingStandingTurnFrames = ob_walkdata->usingStandingTurnFrames; + _usingWalkingTurnFrames = ob_walkdata->usingWalkingTurnFrames; + _usingSlowInFrames = ob_walkdata->usingSlowInFrames; + _usingSlowOutFrames = ob_walkdata->usingSlowOutFrames; // 0 = not using slow out frames; non-zero = using that many frames // for each leading leg for each direction - numberOfSlowOutFrames = usingSlowOutFrames; + _numberOfSlowOutFrames = _usingSlowOutFrames; - memcpy(&numberOfSlowInFrames[0], ob_walkdata->nSlowInFrames, NO_DIRECTIONS * sizeof(numberOfSlowInFrames[0])); - memcpy(&leadingLeg[0], ob_walkdata->leadingLeg, NO_DIRECTIONS * sizeof(leadingLeg[0])); - memcpy(&dx[0], ob_walkdata->dx, NO_DIRECTIONS * (nWalkFrames + 1) * sizeof(dx[0])); - memcpy(&dy[0], ob_walkdata->dy, NO_DIRECTIONS * (nWalkFrames + 1) * sizeof(dy[0])); + memcpy(&_numberOfSlowInFrames[0], ob_walkdata->nSlowInFrames, NO_DIRECTIONS * sizeof(_numberOfSlowInFrames[0])); + memcpy(&_leadingLeg[0], ob_walkdata->leadingLeg, NO_DIRECTIONS * sizeof(_leadingLeg[0])); + memcpy(&_dx[0], ob_walkdata->dx, NO_DIRECTIONS * (_nWalkFrames + 1) * sizeof(_dx[0])); + memcpy(&_dy[0], ob_walkdata->dy, NO_DIRECTIONS * (_nWalkFrames + 1) * sizeof(_dy[0])); - for (direction=0; direction < NO_DIRECTIONS; direction++) { - firstFrameOfDirection = direction * nWalkFrames; + for (i = 0; i < NO_DIRECTIONS; i++) { + firstFrameOfDirection = i * _nWalkFrames; - modX[direction] = 0; - modY[direction] = 0; + _modX[i] = 0; + _modY[i] = 0; - for (walkFrameNo = firstFrameOfDirection; walkFrameNo < firstFrameOfDirection + nWalkFrames / 2; walkFrameNo++) { - // eg. modX[0] is the sum of the x-step sizes for the + for (walkFrameNo = firstFrameOfDirection; walkFrameNo < firstFrameOfDirection + _nWalkFrames / 2; walkFrameNo++) { + // eg. _modX[0] is the sum of the x-step sizes for the // first half of the walk cycle for direction 0 - modX[direction] += dx[walkFrameNo]; - modY[direction] += dy[walkFrameNo]; + _modX[i] += _dx[walkFrameNo]; + _modY[i] += _dy[walkFrameNo]; } } - diagonalx = modX[3]; - diagonaly = modY[3]; + _diagonalx = _modX[3]; + _diagonaly = _modY[3]; // interpret the walk data - framesPerStep = nWalkFrames / 2; - framesPerChar = nWalkFrames * NO_DIRECTIONS; + _framesPerStep = _nWalkFrames / 2; + _framesPerChar = _nWalkFrames * NO_DIRECTIONS; // offset pointers added Oct 30 95 JPS // mega id references removed 16sep96 by JEL @@ -2478,13 +2305,13 @@ void LoadWalkData(Object_walkdata *ob_walkdata) { // WALK FRAMES // start on frame 0 - frameCounter += framesPerChar; + frameCounter += _framesPerChar; // STAND FRAMES // stand frames come after the walk frames // one stand frame for each direction - firstStandFrame = frameCounter; + _firstStandFrame = frameCounter; frameCounter += NO_DIRECTIONS; // STANDING TURN FRAMES - OPTIONAL! @@ -2493,59 +2320,59 @@ void LoadWalkData(Object_walkdata *ob_walkdata) { // standing turn-left frames come after the standing turn-right frames // one for each direction - if (usingStandingTurnFrames) { - firstStandingTurnLeftFrame = frameCounter; + if (_usingStandingTurnFrames) { + _firstStandingTurnLeftFrame = frameCounter; frameCounter += NO_DIRECTIONS; - firstStandingTurnRightFrame = frameCounter; + _firstStandingTurnRightFrame = frameCounter; frameCounter += NO_DIRECTIONS; } else { // refer instead to the normal stand frames - firstStandingTurnLeftFrame = firstStandFrame; - firstStandingTurnRightFrame = firstStandFrame; + _firstStandingTurnLeftFrame = _firstStandFrame; + _firstStandingTurnRightFrame = _firstStandFrame; } // WALKING TURN FRAMES - OPTIONAL! // walking left-turn frames come after the stand frames // walking right-turn frames come after the walking left-turn frames - if (usingWalkingTurnFrames) { - firstWalkingTurnLeftFrame = frameCounter; - frameCounter += framesPerChar; + if (_usingWalkingTurnFrames) { + _firstWalkingTurnLeftFrame = frameCounter; + frameCounter += _framesPerChar; - firstWalkingTurnRightFrame = frameCounter; - frameCounter += framesPerChar; + _firstWalkingTurnRightFrame = frameCounter; + frameCounter += _framesPerChar; } else { - firstWalkingTurnLeftFrame = 0; - firstWalkingTurnRightFrame = 0; + _firstWalkingTurnLeftFrame = 0; + _firstWalkingTurnRightFrame = 0; } // SLOW-IN FRAMES - OPTIONAL! // slow-in frames come after the walking right-turn frames - if (usingSlowInFrames) { + if (_usingSlowInFrames) { // Make note of frame number of first slow-in frame for each // direction. There may be a different number of slow-in // frames in each direction - for (direction = 0; direction < NO_DIRECTIONS; direction++) { - firstSlowInFrame[direction] = frameCounter; - frameCounter += numberOfSlowInFrames[direction]; + for (i = 0; i < NO_DIRECTIONS; i++) { + _firstSlowInFrame[i] = frameCounter; + frameCounter += _numberOfSlowInFrames[i]; } } // SLOW-OUT FRAMES - OPTIONAL! // slow-out frames come after the slow-in frames - if (usingSlowOutFrames) - firstSlowOutFrame = frameCounter; + if (_usingSlowOutFrames) + _firstSlowOutFrame = frameCounter; } // THE ROUTE EXTRACTOR -void ExtractRoute() { +void Router::extractRoute() { /********************************************************************* - * ExtractRoute gets route from the node data after a full scan, route + * extractRoute gets route from the node data after a full scan, route * is written with just the basic way points and direction options for * heading to the next point. *********************************************************************/ @@ -2564,42 +2391,42 @@ void ExtractRoute() { // extract the route from the node data - prev = nnodes; + prev = _nnodes; last = prev; point = O_ROUTE_SIZE - 1; - route[point].x = node[last].x; - route[point].y = node[last].y; + _route[point].x = _node[last].x; + _route[point].y = _node[last].y; do { point--; - prev = node[last].prev; - prevx = node[prev].x; - prevy = node[prev].y; - route[point].x = prevx; - route[point].y = prevy; + prev = _node[last].prev; + prevx = _node[prev].x; + prevy = _node[prev].y; + _route[point].x = prevx; + _route[point].y = prevy; last = prev; } while (prev > 0); // now shuffle route down in the buffer - routeLength = 0; + _routeLength = 0; do { - route[routeLength].x = route[point].x; - route[routeLength].y = route[point].y; + _route[_routeLength].x = _route[point].x; + _route[_routeLength].y = _route[point].y; point++; - routeLength++; + _routeLength++; } while (point < O_ROUTE_SIZE); - routeLength = routeLength - 1; + _routeLength--; // okay the route exists as a series point now put in some directions p = 0; do { - ldx = route[p + 1].x - route[p].x; - ldy = route[p + 1].y - route[p].y; + ldx = _route[p + 1].x - _route[p].x; + ldy = _route[p + 1].y - _route[p].y; dirx = 1; diry = 1; @@ -2613,133 +2440,129 @@ void ExtractRoute() { diry = -1; } - if (diagonaly * ldx > diagonalx * ldy) { + if (_diagonaly * ldx > _diagonalx * ldy) { // dir = 1,2 or 2,3 or 5,6 or 6,7 // 2 or 6 dir = 4 - 2 * dirx; - route[p].dirS = dir; + _route[p].dirS = dir; // 1, 3, 5 or 7 dir = dir + diry * dirx; - route[p].dirD = dir; + _route[p].dirD = dir; } else { // dir = 7,0 or 0,1 or 3,4 or 4,5 // 0 or 4 dir = 2 + 2 * diry; - route[p].dirS = dir; + _route[p].dirS = dir; // 2 or 6 dir = 4 - 2 * dirx; // 1, 3, 5 or 7 dir = dir + diry * dirx; - route[p].dirD = dir; + _route[p].dirD = dir; } p++; - } while (p < routeLength); + } while (p < _routeLength); // set the last dir to continue previous route unless specified - if (targetDir == 8) { + if (_targetDir == 8) { // ANY direction - route[p].dirS = route[p - 1].dirS; - route[p].dirD = route[p - 1].dirD; + _route[p].dirS = _route[p - 1].dirS; + _route[p].dirD = _route[p - 1].dirD; } else { - route[p].dirS = targetDir; - route[p].dirD = targetDir; + _route[p].dirS = _targetDir; + _route[p].dirD = _targetDir; } return; } -void SetUpWalkGrid(Object_mega *ob_mega, int32 x, int32 y, int32 dir) { - int32 i; - +void Router::setUpWalkGrid(Object_mega *ob_mega, int32 x, int32 y, int32 dir) { // get walk grid file + extra grid into 'bars' & 'node' arrays - LoadWalkGrid(); + loadWalkGrid(); // copy the mega structure into the local variables for use in all // subroutines - startX = ob_mega->feet_x; - startY = ob_mega->feet_y; - startDir = ob_mega->current_dir; - targetX = x; - targetY = y; - targetDir = dir; + _startX = ob_mega->feet_x; + _startY = ob_mega->feet_y; + _startDir = ob_mega->current_dir; + _targetX = x; + _targetY = y; + _targetDir = dir; - scaleA = ob_mega->scale_a; - scaleB = ob_mega->scale_b; + _scaleA = ob_mega->scale_a; + _scaleB = ob_mega->scale_b; // mega's current position goes into first node - node[0].x = startX; - node[0].y = startY; - node[0].level = 1; - node[0].prev = 0; - node[0].dist = 0; + _node[0].x = _startX; + _node[0].y = _startY; + _node[0].level = 1; + _node[0].prev = 0; + _node[0].dist = 0; // reset other nodes - for (i = 1; i < nnodes; i++) { - node[i].level = 0; - node[i].prev = 0; - node[i].dist = 9999; + for (int i = 1; i < _nnodes; i++) { + _node[i].level = 0; + _node[i].prev = 0; + _node[i].dist = 9999; } // target position goes into final node - node[nnodes].x = targetX; - node[nnodes].y = targetY; - node[nnodes].level = 0; - node[nnodes].prev = 0; - node[nnodes].dist = 9999; + _node[_nnodes].x = _targetX; + _node[_nnodes].y = _targetY; + _node[_nnodes].level = 0; + _node[_nnodes].prev = 0; + _node[_nnodes].dist = 9999; } #ifdef _SWORD2_DEBUG -void PlotWalkGrid(void) { - int32 j; +void Router::plotWalkGrid(void) { + int32 i; // get walk grid file + extra grid into 'bars' & 'node' arrays - LoadWalkGrid(); + loadWalkGrid(); // lines - for (j = 0; j < nbars; j++) - DrawLine(bars[j].x1, bars[j].y1, bars[j].x2, bars[j].y2, 254); + for (i = 0; i < _nbars; i++) + DrawLine(_bars[i].x1, _bars[i].y1, _bars[i].x2, _bars[i].y2, 254); // nodes // leave node 0 for start node - for (j = 1; j < nnodes; j++) - PlotCross(node[j].x, node[j].y, 184); + for (i = 1; i < _nnodes; i++) + plotCross(_node[i].x, _node[i].y, 184); } -void PlotCross(int16 x, int16 y, uint8 colour) { +void Router::plotCross(int16 x, int16 y, uint8 colour) { DrawLine(x - 1, y - 1, x + 1, y + 1, colour); DrawLine(x + 1, y - 1, x - 1, y + 1, colour); } #endif -void LoadWalkGrid(void) { +void Router::loadWalkGrid(void) { _walkGridHeader floorHeader; - uint32 j; uint8 *fPolygrid; - int entry; uint32 theseBars; uint32 theseNodes; - nbars = 0; // reset counts - nnodes = 1; // leave node 0 for start-node + _nbars = 0; // reset counts + _nnodes = 1; // leave node 0 for start-node // STATIC GRIDS (added/removed by object logics) // go through walkgrid list - for (entry = 0; entry < MAX_WALKGRIDS; entry++) { - if (walkGridList[entry]) { + for (int i = 0; i < MAX_WALKGRIDS; i++) { + if (_walkGridList[i]) { // open walk grid file - fPolygrid = res_man.open(walkGridList[entry]); + fPolygrid = res_man.open(_walkGridList[i]); fPolygrid += sizeof(_standardHeader); memmove((uint8 *) &floorHeader, fPolygrid, sizeof(_walkGridHeader)); fPolygrid += sizeof(_walkGridHeader); @@ -2754,20 +2577,20 @@ void LoadWalkGrid(void) { // check that we're not going to exceed the max // allowed in the complete walkgrid arrays - if (nbars + theseBars >= O_GRID_SIZE) + if (_nbars + theseBars >= O_GRID_SIZE) Con_fatal_error("Adding walkgrid(%d): %d+%d bars exceeds max %d", - walkGridList[entry], nbars, theseBars, + _walkGridList[i], _nbars, theseBars, O_GRID_SIZE); - if (nnodes + theseNodes >= O_GRID_SIZE) + if (_nnodes + theseNodes >= O_GRID_SIZE) Con_fatal_error("Adding walkgrid(%d): %d+%d nodes exceeds max %d", - walkGridList[entry], nnodes, theseBars, + _walkGridList[i], _nnodes, theseBars, O_GRID_SIZE); #endif // lines - memmove((uint8 *) &bars[nbars], fPolygrid, theseBars * sizeof(_barData)); + memmove((uint8 *) &_bars[_nbars], fPolygrid, theseBars * sizeof(_barData)); //move pointer to start of node data fPolygrid += theseBars * sizeof(_barData); @@ -2775,19 +2598,19 @@ void LoadWalkGrid(void) { // nodes // leave node 0 for start node - for (j = 0; j < theseNodes; j++) { - memmove((uint8 *) &node[nnodes + j].x, fPolygrid, 2 * sizeof(int16)); + for (uint j = 0; j < theseNodes; j++) { + memmove((uint8 *) &_node[_nnodes + j].x, fPolygrid, 2 * sizeof(int16)); fPolygrid += 2 * sizeof(int16); } // close walk grid file - res_man.close(walkGridList[entry]); + res_man.close(_walkGridList[i]); // increment counts of total bars & nodes in whole // walkgrid - nbars += theseBars; - nnodes += theseNodes; + _nbars += theseBars; + _nnodes += theseNodes; } } @@ -2798,62 +2621,54 @@ void LoadWalkGrid(void) { // extra lines - memmove((uint8 *) &bars[nbars], (uint8 *) &extraBars[0], nExtraBars * sizeof(_barData)); - nbars += nExtraBars; + memmove((uint8 *) &_bars[_nbars], (uint8 *) &_extraBars[0], _nExtraBars * sizeof(_barData)); + _nbars += _nExtraBars; // extra nodes - memmove((uint8 *) &node[nnodes], (uint8 *) &extraNode[0], nExtraNodes * sizeof(_nodeData)); - nnodes += nExtraNodes; + memmove((uint8 *) &_node[_nnodes], (uint8 *) &_extraNode[0], _nExtraNodes * sizeof(_nodeData)); + _nnodes += _nExtraNodes; } -void ClearWalkGridList(void) { - for (int entry=0; entry < MAX_WALKGRIDS; entry++) - walkGridList[entry] = 0; +void Router::clearWalkGridList(void) { + memset(_walkGridList, 0, ARRAYSIZE(_walkGridList)); } // called from FN_add_walkgrid -void AddWalkGrid(int32 gridResource) { - int entry; +void Router::addWalkGrid(int32 gridResource) { + int i; - // first, scan list to see if this grid is already included + // First, scan the list to see if this grid is already included - entry = 0; - while (entry < MAX_WALKGRIDS && walkGridList[entry] != gridResource) - entry++; - - // if this new resource isn't already in the list, then add it, - // (otherwise finish) + for (i = 0; i < MAX_WALKGRIDS; i++) { + if (_walkGridList[i] == gridResource) + return; + } - if (entry == MAX_WALKGRIDS) { - // scan the list for a free slot - entry = 0; - while (entry < MAX_WALKGRIDS && walkGridList[entry]) - entry++; + // Scan the list for a free slot - // if we found a free slot - if (entry < MAX_WALKGRIDS) - walkGridList[entry] = gridResource; - else - Con_fatal_error("ERROR: walkGridList[] full"); + for (i = 0; i < MAX_WALKGRIDS; i++) { + if (_walkGridList[i] == 0) { + _walkGridList[i] = gridResource; + return; + } } + + Con_fatal_error("ERROR: _walkGridList[] full"); } // called from FN_remove_walkgrid -void RemoveWalkGrid(int32 gridResource) { - int entry; - - // first, scan list to see if this grid is actually there - entry = 0; - while (entry < MAX_WALKGRIDS && walkGridList[entry] != gridResource) - entry++; - - // if we've found it in the list, reset entry to zero (otherwise just - // ignore the request) - if (entry < MAX_WALKGRIDS) - walkGridList[entry] = 0; +void Router::removeWalkGrid(int32 gridResource) { + for (int i = 0; i < MAX_WALKGRIDS; i++) { + if (_walkGridList[i] == gridResource) { + // If we've found it in the list, reset entry to zero. + // Otherwise just ignore the request. + _walkGridList[i] = 0; + break; + } + } } } // End of namespace Sword2 diff --git a/sword2/router.h b/sword2/router.h index 9611f4cf5f..f470ac261d 100644 --- a/sword2/router.h +++ b/sword2/router.h @@ -23,6 +23,14 @@ #include "bs2/memory.h" #include "bs2/object.h" +// This used to be a variable, but it was never set. Actually, it wasn't even +// initialised! +// +// Define this to force the use of slidy router (so solid path not used when +// ending walk in ANY direction) +// +// #define FORCE_SLIDY + namespace Sword2 { #if !defined(__GNUC__) @@ -48,7 +56,8 @@ struct _barData { int16 ymax; int16 dx; // x2 - x1 int16 dy; // y2 - y1 - int32 co; // co = (y1 *dx)- (x1*dy) from an equation for a line y*dx = x*dy + co + int32 co; // co = (y1 * dx) - (x1 * dy) from an equation for a + // line y * dx = x * dy + co } GCC_PACK; struct _nodeData { @@ -63,22 +72,173 @@ struct _nodeData { #pragma END_PACK_STRUCTS #endif -int32 RouteFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, int32 y, int32 dir); +// because we only have 2 megas in the game! +#define TOTAL_ROUTE_SLOTS 2 + +#define MAX_FRAMES_PER_CYCLE 16 +#define NO_DIRECTIONS 8 +#define MAX_FRAMES_PER_CHAR (MAX_FRAMES_PER_CYCLE * NO_DIRECTIONS) +#define ROUTE_END_FLAG 255 + +#define MAX_WALKGRIDS 10 + +#define O_WALKANIM_SIZE 600 // max number of nodes in router output +#define O_GRID_SIZE 200 // max 200 lines & 200 points +#define EXTRA_GRID_SIZE 20 // max 20 lines & 20 points +#define O_ROUTE_SIZE 50 // max number of modules in a route + +typedef struct { + int32 x; + int32 y; + int32 dirS; + int32 dirD; +} _routeData; + +typedef struct { + int32 x; + int32 y; + int32 dir; + int32 num; +} _pathData; + +class Router { +private: + // stores pointers to mem blocks containing routes created & used by + // megas (NULL if slot not in use) + mem *_routeSlots[TOTAL_ROUTE_SLOTS]; + + // because extra bars will be copied into here afer walkgrid loaded + _barData _bars[O_GRID_SIZE + EXTRA_GRID_SIZE]; + _nodeData _node[O_GRID_SIZE + EXTRA_GRID_SIZE]; + + int32 _walkGridList[MAX_WALKGRIDS]; + + int32 _nbars; + int32 _nnodes; + + // area for extra route data to block parts of floors and enable + // routing round mega charaters + + int32 _nExtraBars; + int32 _nExtraNodes; + _barData _extraBars[EXTRA_GRID_SIZE]; + _nodeData _extraNode[EXTRA_GRID_SIZE]; + + int32 _startX; + int32 _startY; + int32 _startDir; + int32 _targetX; + int32 _targetY; + int32 _targetDir; + int32 _scaleA; + int32 _scaleB; + _routeData _route[O_ROUTE_SIZE]; + _pathData _smoothPath[O_ROUTE_SIZE]; + _pathData _modularPath[O_ROUTE_SIZE]; + int32 _routeLength; + + int32 _framesPerStep; + int32 _framesPerChar; + + uint8 _nWalkFrames; // no. of frames per walk cycle + uint8 _usingStandingTurnFrames; // any standing turn frames? + uint8 _usingWalkingTurnFrames; // any walking turn frames? + uint8 _usingSlowInFrames; // any slow-in frames? + uint8 _usingSlowOutFrames; // any slow-out frames? + int32 _dx[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR]; + int32 _dy[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR]; + int8 _modX[NO_DIRECTIONS]; + int8 _modY[NO_DIRECTIONS]; + int32 _diagonalx; + int32 _diagonaly; + + int32 _firstStandFrame; + + int32 _firstStandingTurnLeftFrame; + int32 _firstStandingTurnRightFrame; + + int32 _firstWalkingTurnLeftFrame; // left walking turn + int32 _firstWalkingTurnRightFrame; // right walking turn + + uint32 _firstSlowInFrame[NO_DIRECTIONS]; + uint32 _numberOfSlowInFrames[NO_DIRECTIONS]; + + uint32 _leadingLeg[NO_DIRECTIONS]; -void EarlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata); + int32 _firstSlowOutFrame; -void AllocateRouteMem(void); -_walkData* LockRouteMem(void); -void FloatRouteMem(void); -void FreeRouteMem(void); -void FreeAllRouteMem(void); -void AddWalkGrid(int32 gridResource); -void RemoveWalkGrid(int32 gridResource); -void ClearWalkGridList(void); + // number of slow-out frames on for each leading-leg in each direction + // ie. total number of slow-out frames = (numberOfSlowOutFrames * 2 * + // NO_DIRECTIONS) + + int32 _numberOfSlowOutFrames; + + int32 _stepCount; + + int32 _moduleX; + int32 _moduleY; + int32 _currentDir; + int32 _lastCount; + int32 _frame; + + uint8 returnSlotNo(uint32 megaId); + + int32 getRoute(void); + void extractRoute(void); + void loadWalkGrid(void); + void setUpWalkGrid(Object_mega *ob_mega, int32 x, int32 y, int32 dir); + void loadWalkData(Object_walkdata *ob_walkdata); + int32 scan(int32 level); + + int32 newCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2); + int32 lineCheck(int32 x1, int32 x2, int32 y1, int32 y2); + int32 vertCheck(int32 x, int32 y1, int32 y2); + int32 horizCheck(int32 x1, int32 y, int32 x2); + int32 check(int32 x1, int32 y1, int32 x2, int32 y2); + int32 checkTarget(int32 x, int32 y); + + int32 smoothestPath(void); + int32 slidyPath(void); + + int32 smoothCheck(int32 best, int32 p, int32 dirS, int32 dirD); + + int32 addSlowInFrames(_walkData *walkAnim); + void addSlowOutFrames(_walkData *walkAnim); + void slidyWalkAnimator(_walkData *walkAnim); + +#ifndef FORCE_SLIDY + int32 solidPath(void); + int32 solidWalkAnimator(_walkData *walkAnim); +#endif + +#ifdef _SWORD2_DEBUG + void plotCross(int16 x, int16 y, uint8 colour); +#endif + +public: + Router() : + _nExtraBars(0), _nExtraNodes(0), _diagonalx(0), + _diagonaly(0) {} + + int32 routeFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, int32 y, int32 dir); + + void earlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata); + + void allocateRouteMem(void); + _walkData* lockRouteMem(void); + void floatRouteMem(void); + void freeRouteMem(void); + void freeAllRouteMem(void); + void addWalkGrid(int32 gridResource); + void removeWalkGrid(int32 gridResource); + void clearWalkGridList(void); #ifdef _SWORD2_DEBUG -void PlotWalkGrid(void); -#endif + void plotWalkGrid(void); +#endif +}; + +extern Router router; } // End of namespace Sword2 diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp index 9a2756ace8..2f24fb8c77 100644 --- a/sword2/save_rest.cpp +++ b/sword2/save_rest.cpp @@ -241,7 +241,7 @@ uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) { SaveFileManager *mgr = g_system->get_savefile_manager(); // construct filename - sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo); + sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo); if (!(out = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), true))) { // error: couldn't open file @@ -304,7 +304,7 @@ uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) { uint32 itemsRead; // construct filename - sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo); + sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo); if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) { // error: couldn't open file @@ -469,7 +469,7 @@ uint32 GetSaveDescription(uint16 slotNo, uint8 *description) { SaveFileManager *mgr = g_system->get_savefile_manager(); // construct filename - sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo); + sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo); if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) { // error: couldn't open file @@ -492,7 +492,7 @@ bool SaveExists(uint16 slotNo) { SaveFile *in; // construct filename - sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo); + sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo); if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) { delete mgr; diff --git a/sword2/startup.cpp b/sword2/startup.cpp index 623ff682e7..bf9eb31b51 100644 --- a/sword2/startup.cpp +++ b/sword2/startup.cpp @@ -272,7 +272,7 @@ uint32 Con_start(uint8 *input) { res_man.close(1); // free all the route memory blocks from previous game - FreeAllRouteMem(); + router.freeAllRouteMem(); // if there was speech text, kill the text block if (speech_text_bloc_no) { diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index a143184369..b8b81e3609 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -104,7 +104,7 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) g_sword2 = this; _features = detector->_game.features; _gameId = detector->_game.id; - _game_name = strdup(detector->_gameFileName.c_str()); + _gameName = strdup(detector->_gameFileName.c_str()); _bootParam = ConfMan.getInt("boot_param"); _saveSlot = ConfMan.getInt("save_slot"); _debugLevel = ConfMan.getInt("debuglevel"); @@ -122,6 +122,11 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) g_sound = _sound = new Sound(_mixer); } +Sword2Engine::~Sword2Engine() { + free(_gameName); + delete _sound; +} + void Sword2Engine::errorString(const char *buf1, char *buf2) { strcpy(buf2, buf1); } diff --git a/sword2/sword2.h b/sword2/sword2.h index 8d4da8fc3e..282d8334fe 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -60,8 +60,14 @@ extern uint8 unencoded_name[]; // TODO move stuff into class class Sword2Engine : public Engine { +private: + bool _quit; + uint32 _bootParam; + int32 _saveSlot; + public: Sword2Engine(GameDetector *detector, OSystem *syst); + ~Sword2Engine(); void go(void); void parseEvents(void); void Start_game(void); @@ -69,7 +75,7 @@ public: GameDetector *_detector; uint32 _features; byte _gameId; - char *_game_name; // target name for saves + char *_gameName; // target name for saves Sound *_sound; Common::RandomSource _rnd; @@ -77,12 +83,6 @@ public: uint32 _controlsFontId; uint32 _redFontId; -private: - bool _quit; - uint32 _bootParam; - int32 _saveSlot; - -public: 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 2ce5fd03a0..9122b48555 100644 --- a/sword2/walker.cpp +++ b/sword2/walker.cpp @@ -101,9 +101,9 @@ int32 FN_walk(int32 *params) { // set up mem for _walkData in route_slots[] & set mega's // 'route_slot_id' accordingly - AllocateRouteMem(); + router.allocateRouteMem(); - route = (int8) RouteFinder(ob_mega, ob_walkdata, target_x, target_y, target_dir); + route = (int8) router.routeFinder(ob_mega, ob_walkdata, target_x, target_y, target_dir); // 0 = can't make route to target // 1 = created route @@ -124,7 +124,7 @@ int32 FN_walk(int32 *params) { // (see FN_get_player_savedata() in save_rest.cpp } else { // free up the walkdata mem block - FreeRouteMem(); + router.freeRouteMem(); // 1 means error, no walk created RESULT = 1; @@ -143,7 +143,7 @@ int32 FN_walk(int32 *params) { // ok, thats it - back to script and change screen ob_logic->looping = 0; // so script loop stops - FreeRouteMem(); // free up the walkdata mem block + router.freeRouteMem(); // free up the walkdata mem block // must clear in-case on the new screen there's a walk // instruction (which would get cut short) @@ -167,7 +167,7 @@ int32 FN_walk(int32 *params) { // get pointer to walkanim & current frame position // lock the _walkData array - walkAnim = LockRouteMem(); + walkAnim = router.lockRouteMem(); walk_pc = ob_mega->walk_pc; // if stopping the walk early, overwrite the next step with a @@ -177,7 +177,7 @@ int32 FN_walk(int32 *params) { if (walkAnim[walk_pc].step == 0 && walkAnim[walk_pc + 1].step == 1) { // at the beginning of a step ob_walkdata = (Object_walkdata *) params[3]; - EarlySlowOut(ob_mega, ob_walkdata); + router.earlySlowOut(ob_mega, ob_walkdata); } } @@ -196,7 +196,7 @@ int32 FN_walk(int32 *params) { // '512' is end-marker if (walkAnim[walk_pc + 1].frame == 512) { ob_logic->looping = 0; // so script loop stops - FreeRouteMem(); // free up the walkdata mem block + router.freeRouteMem(); // free up the walkdata mem block // finished walk ob_mega->currently_walking = 0; @@ -237,7 +237,7 @@ int32 FN_walk(int32 *params) { ob_mega->walk_pc++; // allow _walkData array to float about memory again - FloatRouteMem(); + router.floatRouteMem(); // stop the script, but repeat this call next cycle return IR_REPEAT; @@ -299,7 +299,7 @@ int32 FN_walk_to_anim(int32 *params) { pars[2] = params[2]; pars[3] = params[3]; - // walkdata (param 3) is needed for EarlySlowOut if player clicks + // walkdata (param 3) is needed for earlySlowOut if player clicks // elsewhere during the walk // call FN_walk() with target coords set to anim start position @@ -739,7 +739,7 @@ int32 FN_add_walkgrid(int32 *params) { FN_add_to_kill_list(params); } - AddWalkGrid(params[0]); + router.addWalkGrid(params[0]); // Touch the grid, getting it into memory. res_man.open(params[0]); @@ -755,7 +755,7 @@ int32 FN_add_walkgrid(int32 *params) { int32 FN_remove_walkgrid(int32 *params) { // params: 0 id of walkgrid resource - RemoveWalkGrid(params[0]); + router.removeWalkGrid(params[0]); return IR_CONT; } -- cgit v1.2.3