void test_insert_string_data_in_queue1() { Queue* queue = createQueue(); string data1 = "shital" , data2 = "shweta" , data3 = "shabarin"; insertData(queue , &data1 , 1); insertData(queue , &data2 , 5); insertData(queue , &data3 , 2); insertData(queue , &data3 , 3); checkPriority(queue); ASSERT(queue->length == 4); }
void test_insert_float_data_in_queue1() { Queue* queue = createQueue(); Node* node; float data1 = 10.5 , data2 = 20.5 , data3 = 30.5; insertData(queue , &data1 , 1); insertData(queue , &data2 , 5); insertData(queue , &data3 , 2); insertData(queue , &data3 , 3); checkPriority(queue); ASSERT(queue->length == 4); }
void test_insert_integer_data_in_queue1() { Queue* queue = createQueue(); Node* node; int data1 = 10 , data2 = 20 , data3 = 30; insertData(queue , &data1 , 1); insertData(queue , &data2 , 3); insertData(queue , &data3 , 2); insertData(queue , &data3 , 1); checkPriority(queue); ASSERT(queue->length == 4); }
/** * Adjust position of a sprite * This function adjusts the position of a sprite moving it until * certain criteria is matched. According to priority and control line * data, a sprite may not always appear at the location we specified. * This behaviour is also known as the "Budin-Sonneveld effect". * * @param n view table entry number */ void AgiEngine::fixPosition(int n) { VtEntry *v = &_game.viewTable[n]; int count, dir, size; debugC(4, kDebugLevelSprites, "adjusting view table entry #%d (%d,%d)", n, v->xPos, v->yPos); // test horizon if ((~v->flags & IGNORE_HORIZON) && v->yPos <= _game.horizon) v->yPos = _game.horizon + 1; dir = 0; count = size = 1; while (!checkPosition(v) || checkCollision(v) || !checkPriority(v)) { switch (dir) { case 0: // west v->xPos--; if (--count) continue; dir = 1; break; case 1: // south v->yPos++; if (--count) continue; dir = 2; size++; break; case 2: // east v->xPos++; if (--count) continue; dir = 3; break; case 3: // north v->yPos--; if (--count) continue; dir = 0; size++; break; } count = size; } debugC(4, kDebugLevelSprites, "view table entry #%d position adjusted to (%d,%d)", n, v->xPos, v->yPos); }
void test_delete_string_data_in_queue() { Queue* queue = createQueue(); string deletedData; string data1 = "shital" , data2 = "shweta" , data3 = "shabarin"; insertData(queue , &data1 , 1); insertData(queue , &data2 , 5); insertData(queue , &data3 , 2); insertData(queue , &data3 , 3); ASSERT(queue->length == 4); checkPriority(queue); strcpy(deletedData , *(string*)deleteData(queue)); ASSERT(!strcmp(deletedData , "shital")); ASSERT(queue->length == 3); }
void test_delete_float_data_in_queue1() { Queue* queue = createQueue(); float deletedData; float data1 = 10.5 , data2 = 20.5 , data3 = 30.5; insertData(queue , &data1 , 1); insertData(queue , &data2 , 5); insertData(queue , &data3 , 2); insertData(queue , &data3 , 3); ASSERT(queue->length == 4); checkPriority(queue); deletedData = *(float*)deleteData(queue); ASSERT(queue->length == 3); ASSERT(deletedData == 10.5); }
void AgiEngine::fixPosition(ScreenObjEntry *screenObj) { int count, dir, size; debugC(4, kDebugLevelSprites, "adjusting view table entry #%d (%d,%d)", screenObj->objectNr, screenObj->xPos, screenObj->yPos); // test horizon if ((!(screenObj->flags & fIgnoreHorizon)) && screenObj->yPos <= _game.horizon) screenObj->yPos = _game.horizon + 1; dir = 0; count = size = 1; while (!checkPosition(screenObj) || checkCollision(screenObj) || !checkPriority(screenObj)) { switch (dir) { case 0: // west screenObj->xPos--; if (--count) continue; dir = 1; break; case 1: // south screenObj->yPos++; if (--count) continue; dir = 2; size++; break; case 2: // east screenObj->xPos++; if (--count) continue; dir = 3; break; case 3: // north screenObj->yPos--; if (--count) continue; dir = 0; size++; break; } count = size; } debugC(4, kDebugLevelSprites, "view table entry #%d position adjusted to (%d,%d)", screenObj->objectNr, screenObj->xPos, screenObj->yPos); }
/** * Update position of objects * This function updates the position of all animated, updating view * table entries according to its motion type, step size, etc. The * new position must be valid according to the sprite positioning * rules, otherwise the previous position will be kept. */ void AgiEngine::updatePosition() { ScreenObjEntry *screenObj; int x, y, oldX, oldY, border; setVar(VM_VAR_BORDER_CODE, 0); setVar(VM_VAR_BORDER_TOUCH_EGO, 0); setVar(VM_VAR_BORDER_TOUCH_OBJECT, 0); for (screenObj = _game.screenObjTable; screenObj < &_game.screenObjTable[SCREENOBJECTS_MAX]; screenObj++) { if ((screenObj->flags & (fAnimated | fUpdate | fDrawn)) != (fAnimated | fUpdate | fDrawn)) { continue; } if (screenObj->stepTimeCount > 1) { screenObj->stepTimeCount--; continue; } screenObj->stepTimeCount = screenObj->stepTime; x = oldX = screenObj->xPos; y = oldY = screenObj->yPos; // If object has moved, update its position if (!(screenObj->flags & fUpdatePos)) { int dx[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 }; int dy[9] = { 0, -1, -1, 0, 1, 1, 1, 0, -1 }; x += screenObj->stepSize * dx[screenObj->direction]; y += screenObj->stepSize * dy[screenObj->direction]; } // Now check if it touched the borders border = 0; // Check left/right borders if (getVersion() == 0x3086) { // KQ4 interpreter does a different comparison on x // The interpreter before (2.917) and after that (3.098) don't do them that way // This difference is required for at least Sarien bug #192 // KQ4: room 135, hen moves from the center of the screen to the left border, // but it doesn't disappear. if (x <= 0) { x = 0; border = 4; } } else { // regular comparison if (x < 0) { x = 0; border = 4; } } // } else if (v->entry == 0 && x == 0 && v->flags & fAdjEgoXY) { // should not be required // // Extra test to walk west clicking the mouse // x = 0; // border = 4; if (!border) { if (x + screenObj->xSize > SCRIPT_WIDTH) { x = SCRIPT_WIDTH - screenObj->xSize; border = 2; } } // Check top/bottom borders. if (y - screenObj->ySize < -1) { y = screenObj->ySize - 1; border = 1; } else if (y > SCRIPT_HEIGHT - 1) { y = SCRIPT_HEIGHT - 1; border = 3; } else if ((!(screenObj->flags & fIgnoreHorizon)) && y <= _game.horizon) { debugC(4, kDebugLevelSprites, "y = %d, horizon = %d", y, _game.horizon); y = _game.horizon + 1; border = 1; } // Test new position. rollback if test fails screenObj->xPos = x; screenObj->yPos = y; if (checkCollision(screenObj) || !checkPriority(screenObj)) { screenObj->xPos = oldX; screenObj->yPos = oldY; border = 0; fixPosition(screenObj->objectNr); } if (border) { if (isEgoView(screenObj)) { setVar(VM_VAR_BORDER_TOUCH_EGO, border); } else { setVar(VM_VAR_BORDER_CODE, screenObj->objectNr); setVar(VM_VAR_BORDER_TOUCH_OBJECT, border); } if (screenObj->motionType == kMotionMoveObj) { motionMoveObjStop(screenObj); } } screenObj->flags &= ~fUpdatePos; } }
/** * Update position of objects * This function updates the position of all animated, updating view * table entries according to its motion type, step size, etc. The * new position must be valid according to the sprite positioning * rules, otherwise the previous position will be kept. */ void AgiEngine::updatePosition() { VtEntry *v; int x, y, oldX, oldY, border; _game.vars[vBorderCode] = 0; _game.vars[vBorderTouchEgo] = 0; _game.vars[vBorderTouchObj] = 0; for (v = _game.viewTable; v < &_game.viewTable[MAX_VIEWTABLE]; v++) { if ((v->flags & (ANIMATED | UPDATE | DRAWN)) != (ANIMATED | UPDATE | DRAWN)) { continue; } if (v->stepTimeCount != 0) { if (--v->stepTimeCount != 0) continue; } v->stepTimeCount = v->stepTime; x = oldX = v->xPos; y = oldY = v->yPos; // If object has moved, update its position if (~v->flags & UPDATE_POS) { int dx[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 }; int dy[9] = { 0, -1, -1, 0, 1, 1, 1, 0, -1 }; x += v->stepSize * dx[v->direction]; y += v->stepSize * dy[v->direction]; } // Now check if it touched the borders border = 0; // Check left/right borders if (x < 0) { x = 0; border = 4; } else if (x <= 0 && getVersion() == 0x3086) { // KQ4 x = 0; // See Sarien bug #590462 border = 4; } else if (v->entry == 0 && x == 0 && v->flags & ADJ_EGO_XY) { // Extra test to walk west clicking the mouse x = 0; border = 4; } else if (x + v->xSize > _WIDTH) { x = _WIDTH - v->xSize; border = 2; } // Check top/bottom borders. if (y - v->ySize + 1 < 0) { y = v->ySize - 1; border = 1; } else if (y > _HEIGHT - 1) { y = _HEIGHT - 1; border = 3; } else if ((~v->flags & IGNORE_HORIZON) && y <= _game.horizon) { debugC(4, kDebugLevelSprites, "y = %d, horizon = %d", y, _game.horizon); y = _game.horizon + 1; border = 1; } // Test new position. rollback if test fails v->xPos = x; v->yPos = y; if (checkCollision(v) || !checkPriority(v)) { v->xPos = oldX; v->yPos = oldY; border = 0; fixPosition(v->entry); } if (border != 0) { if (isEgoView(v)) { _game.vars[vBorderTouchEgo] = border; } else { _game.vars[vBorderCode] = v->entry; _game.vars[vBorderTouchObj] = border; } if (v->motion == MOTION_MOVE_OBJ) { inDestination(v); } } v->flags &= ~UPDATE_POS; } }