diff options
author | Oliver Kiehl | 2003-04-27 22:15:35 +0000 |
---|---|---|
committer | Oliver Kiehl | 2003-04-27 22:15:35 +0000 |
commit | 28009de449919a849c14db95f004802d05c4aa35 (patch) | |
tree | 5bb192fa4b94ed7f2f577307522d5101ad0d0c97 /sky | |
parent | 34be8be611bbbfa5bc9f7711b00d2e23e1aa9295 (diff) | |
download | scummvm-rg350-28009de449919a849c14db95f004802d05c4aa35.tar.gz scummvm-rg350-28009de449919a849c14db95f004802d05c4aa35.tar.bz2 scummvm-rg350-28009de449919a849c14db95f004802d05c4aa35.zip |
fixed autoroute a bit (still doesn't work correctly but at least it doesn't
segfault) and linked it to SkyLogic
svn-id: r7167
Diffstat (limited to 'sky')
-rw-r--r-- | sky/autoroute.cpp | 26 | ||||
-rw-r--r-- | sky/logic.cpp | 20 | ||||
-rw-r--r-- | sky/logic.h | 6 |
3 files changed, 27 insertions, 25 deletions
diff --git a/sky/autoroute.cpp b/sky/autoroute.cpp index 5a3196995f..41e03e6e6e 100644 --- a/sky/autoroute.cpp +++ b/sky/autoroute.cpp @@ -41,7 +41,7 @@ SkyAutoRoute::~SkyAutoRoute(void) { uint16 SkyAutoRoute::checkBlock(uint16 *blockPos) { uint16 fieldVal, retVal = 0; - fieldVal = blockPos[1]; // field to the right + fieldVal = blockPos[1]; // field to the right if ((!(fieldVal & 0x8000)) && (fieldVal != 0)) retVal = fieldVal; fieldVal = (blockPos - 1)[0]; // field to the left if ((!(fieldVal & 0x8000)) && (fieldVal != 0) && (fieldVal > retVal)) retVal = fieldVal; @@ -63,8 +63,8 @@ uint16 SkyAutoRoute::autoRoute(Compact *cpt, uint16 **pSaveRoute) { uint8 stretch1, stretch2; // bl / bh stretch1 = 0; - //FIXME: don't know if this is uint16 or uint32 (endian problem) - stretch2 = (uint8)*(uint32 *)SkyCompact::getCompactElem(cpt, C_GRID_WIDTH + cpt->extCompact->megaSet); + MegaSet *mega = (MegaSet *)SkyCompact::getCompactElem(cpt, C_GRID_WIDTH + cpt->extCompact->megaSet); + stretch2 = (uint8)(mega->gridWidth & 0xff); uint16 cnt; //First clear the bottom line and right hand edge of next line @@ -113,7 +113,7 @@ uint16 SkyAutoRoute::autoRoute(Compact *cpt, uint16 **pSaveRoute) { stretch1 = 0; // clear stretch factor gridCntY--; } - } while(gridCntX || gridCntY); + } while(gridCntY); for (cnt = 0; cnt < ROUTE_GRID_WIDTH-1; cnt++) _routeGrid[cnt] = 0; // clear top line (right hand edge already done @@ -193,12 +193,12 @@ uint16 SkyAutoRoute::autoRoute(Compact *cpt, uint16 **pSaveRoute) { //postBlockX <<= 1; postBlockY <<= 1; // multiply by 2 uint16 *routeDestCalc; routeDestCalc = postBlockY * ROUTE_GRID_WIDTH + postBlockX + _routeGrid; - routeDestCalc += ROUTE_GRID_WIDTH+1; // skip blank edges (what?) + routeDestCalc += ROUTE_GRID_WIDTH+1; // skip blank edges (what?) //initBlockX <<= 1; initBlockY <<= 1; uint16 *routeSrcCalc; routeSrcCalc = initBlockY * ROUTE_GRID_WIDTH + initBlockX + _routeGrid; - routeSrcCalc += ROUTE_GRID_WIDTH+1; // skip blank edges + routeSrcCalc += ROUTE_GRID_WIDTH+1; // skip blank edges routeSrcCalc[0] = 1; //start this one off // means: mark the block we start from as accessible @@ -225,12 +225,12 @@ uint16 SkyAutoRoute::autoRoute(Compact *cpt, uint16 **pSaveRoute) { cnty = numLines; uint16 *yPushedSrc = routeSrcCalc; do { // wallow_x - cntx = numCols; + cntx = numCols; uint16 *xPushedSrc = routeSrcCalc; do { // wallow if (!routeSrcCalc[0]) { // block wasn't yet done - blockRet = checkBlock(routeSrcCalc); + blockRet = checkBlock(routeSrcCalc); if (blockRet > 0) { // this block is accessible routeSrcCalc[0] = blockRet; @@ -247,7 +247,7 @@ uint16 SkyAutoRoute::autoRoute(Compact *cpt, uint16 **pSaveRoute) { foundRoute = false; if (!routeDestCalc[0]) { - // we have done a section, see if we want to shift backwards (what?) + // we have done a section, see if we want to shift backwards (what?) if (numLines < ROUTE_GRID_HEIGHT-4) { routeSrcCalc -= directionY; numLines++; @@ -258,12 +258,12 @@ uint16 SkyAutoRoute::autoRoute(Compact *cpt, uint16 **pSaveRoute) { } } else foundRoute = true; } while ((!foundRoute) && gridChanged); - + if (!routeDestCalc[0]) { // no route exists from routeSrc to routeDest return 2; } - // ok, we know now that it's possible to get from the start position to the desired + // ok, we know now that it's possible to get from the start position to the desired // destination. Let's see how. uint16 *saveRoute = routeData+(ROUTE_SPACE >> 1)-1; // route_space is given in bytes so >> 1 saveRoute[0] = 0; // route is null terminated @@ -329,7 +329,7 @@ uint16 SkyAutoRoute::autoRoute(Compact *cpt, uint16 **pSaveRoute) { error("AutoRoute:: Can't find way backwards through _routeGrid"); } } while (!routeDone); - // the route is done. if there was an initial x/y movement tag it onto the start + // the route is done. if there was an initial x/y movement tag it onto the start if (initX < 0) { saveRoute -= 4; saveRoute[1] = RIGHTY; @@ -340,7 +340,7 @@ uint16 SkyAutoRoute::autoRoute(Compact *cpt, uint16 **pSaveRoute) { saveRoute[0] = (initX+7)&0xFFF8; } // I wonder why initY isn't checked - // saveRoute should now point to routeData + // saveRoute should now point to routeData if (routeData > saveRoute) error("Autoroute: Internal pointer error! routeData overflow."); *pSaveRoute = saveRoute; return 1; diff --git a/sky/logic.cpp b/sky/logic.cpp index 455b1a4c35..30e03f18a5 100644 --- a/sky/logic.cpp +++ b/sky/logic.cpp @@ -47,9 +47,10 @@ static const LogicTable logicTable[] = { &SkyLogic::simpleAnim, // 16 Module anim without x,y's }; -SkyLogic::SkyLogic(SkyDisk *skyDisk, SkyGrid *grid) { +SkyLogic::SkyLogic(SkyDisk *skyDisk, SkyGrid *skyGrid) { _skyDisk = skyDisk; - _grid = grid; + _skyGrid = skyGrid; + _skyAutoRoute = new SkyAutoRoute(_skyGrid); for (uint i = 0; i < sizeof(_moduleList)/sizeof(uint16*); i++) _moduleList[i] = 0; @@ -61,6 +62,9 @@ SkyLogic::SkyLogic(SkyDisk *skyDisk, SkyGrid *grid) { void SkyLogic::engine() { Compact *compact2 = SkyState::fetchCompact(141); // logic list + printf("XXXXXXX: loading grids\n"); + _skyGrid->loadGrids(); + while (compact2->logic) { // 0 means end of list if (compact2->logic == 0xffff) { // Change logic data address @@ -78,13 +82,13 @@ void SkyLogic::engine() { // ok, here we process the logic bit system if (_compact->status & (1 << 7)) - _grid->removeObjectFromWalk(_compact); + _skyGrid->removeObjectFromWalk(_compact); SkyDebug::logic(_compact->logic); (this->*logicTable[_compact->logic]) (); if (_compact->status & (1 << 7)) - _grid->objectToWalk(_compact); + _skyGrid->objectToWalk(_compact); // a sync sent to the compact is available for one cycle // only. that cycle has just ended so remove the sync. @@ -123,12 +127,8 @@ void SkyLogic::logicScript() { } void SkyLogic::autoRoute() { - error("autoRoute unimplemented"); - uint16 *route; - route = 0; - - warning("autoRoute unimplemented"); - uint32 ret = 0; // = autoRoute(route); + uint16 *route = 0; + uint16 ret = _skyAutoRoute->autoRoute(_compact, &route); _compact->logic = L_SCRIPT; // continue the script diff --git a/sky/logic.h b/sky/logic.h index 8e3ad1ea2b..9914159a60 100644 --- a/sky/logic.h +++ b/sky/logic.h @@ -25,10 +25,11 @@ #include "sky/sky.h" #include "sky/disk.h" #include "sky/grid.h" +#include "sky/autoroute.h" class SkyLogic { public: - SkyLogic(SkyDisk *skyDisk, SkyGrid *grid); + SkyLogic(SkyDisk *skyDisk, SkyGrid *skyGrid); void engine(); void lreturn(); @@ -181,7 +182,8 @@ protected: uint32 _scriptVariables[838]; SkyDisk *_skyDisk; - SkyGrid *_grid; + SkyGrid *_skyGrid; + SkyAutoRoute *_skyAutoRoute; }; #endif |