From f8641cf823977fae9c8b5758868760b853301de5 Mon Sep 17 00:00:00 2001 From: Martin Gerhardy Date: Mon, 9 Aug 2021 16:39:54 +0200 Subject: [PATCH] TWINE: renamed members and use constants --- engines/twine/scene/actor.cpp | 11 +++++---- engines/twine/scene/collision.cpp | 8 +++---- engines/twine/scene/grid.cpp | 39 ++++++++++++++++--------------- engines/twine/scene/grid.h | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/engines/twine/scene/actor.cpp b/engines/twine/scene/actor.cpp index b715bf823d3..3c8afe15404 100644 --- a/engines/twine/scene/actor.cpp +++ b/engines/twine/scene/actor.cpp @@ -344,7 +344,7 @@ void Actor::hitActor(int32 actorIdx, int32 actorIdxAttacked, int32 strengthOfHit } } -void Actor::processActorCarrier(int32 actorIdx) { // CheckCarrier +void Actor::processActorCarrier(int32 actorIdx) { ActorStruct *actor = _engine->_scene->getActor(actorIdx); if (!actor->_staticFlags.bIsCarrierActor) { return; @@ -356,7 +356,7 @@ void Actor::processActorCarrier(int32 actorIdx) { // CheckCarrier } } -void Actor::processActorExtraBonus(int32 actorIdx) { // GiveExtraBonus +void Actor::processActorExtraBonus(int32 actorIdx) { ActorStruct *actor = _engine->_scene->getActor(actorIdx); const int bonusSprite = _engine->_extra->getBonusSprite(actor->_bonusParameter); @@ -367,10 +367,11 @@ void Actor::processActorExtraBonus(int32 actorIdx) { // GiveExtraBonus _engine->_extra->addExtraBonus(actor->pos(), ANGLE_90, ANGLE_0, bonusSprite, actor->_bonusAmount); _engine->_sound->playSample(Samples::ItemPopup, 1, actor->pos(), actorIdx); } else { - ActorStruct *sceneHero = _engine->_scene->_sceneHero; + const ActorStruct *sceneHero = _engine->_scene->_sceneHero; const int32 angle = _engine->_movements->getAngleAndSetTargetActorDistance(actor->pos(), sceneHero->pos()); - _engine->_extra->addExtraBonus(actor->_pos.x, actor->_pos.y + actor->_boudingBox.maxs.y, actor->_pos.z, ANGLE_70, angle, bonusSprite, actor->_bonusAmount); - _engine->_sound->playSample(Samples::ItemPopup, 1, actor->_pos.x, actor->_pos.y + actor->_boudingBox.maxs.y, actor->_pos.z, actorIdx); + const IVec3 pos(actor->_pos.x, actor->_pos.y + actor->_boudingBox.maxs.y, actor->_pos.z); + _engine->_extra->addExtraBonus(pos, ANGLE_70, angle, bonusSprite, actor->_bonusAmount); + _engine->_sound->playSample(Samples::ItemPopup, 1, pos, actorIdx); } } diff --git a/engines/twine/scene/collision.cpp b/engines/twine/scene/collision.cpp index c9f8166495f..65c74793661 100644 --- a/engines/twine/scene/collision.cpp +++ b/engines/twine/scene/collision.cpp @@ -123,14 +123,14 @@ void Collision::reajustActorPosition(ShapeType brickShape) { } break; case ShapeType::kDoubleSideStairsLeft1: - if (512 - processActor.x - _collision.x <= processActor.z - _collision.z) { + if (BRICK_SIZE - processActor.x - _collision.x <= processActor.z - _collision.z) { brickShape = ShapeType::kStairsTopLeft; } else { brickShape = ShapeType::kStairsBottomLeft; } break; case ShapeType::kDoubleSideStairsRight1: - if (512 - processActor.x - _collision.x <= processActor.z - _collision.z) { + if (BRICK_SIZE - processActor.x - _collision.x <= processActor.z - _collision.z) { brickShape = ShapeType::kStairsTopRight; } else { brickShape = ShapeType::kStairsBottomRight; @@ -151,14 +151,14 @@ void Collision::reajustActorPosition(ShapeType brickShape) { } break; case ShapeType::kDoubleSideStairsLeft2: - if (512 - processActor.x - _collision.x <= processActor.z - _collision.z) { + if (BRICK_SIZE - processActor.x - _collision.x <= processActor.z - _collision.z) { brickShape = ShapeType::kStairsBottomLeft; } else { brickShape = ShapeType::kStairsTopLeft; } break; case ShapeType::kDoubleSideStairsRight2: - if (512 - processActor.x - _collision.x <= processActor.z - _collision.z) { + if (BRICK_SIZE - processActor.x - _collision.x <= processActor.z - _collision.z) { brickShape = ShapeType::kStairsBottomRight; } else { brickShape = ShapeType::kStairsTopRight; diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp index 5c331e0ba9c..0385713eb0f 100644 --- a/engines/twine/scene/grid.cpp +++ b/engines/twine/scene/grid.cpp @@ -51,7 +51,7 @@ Grid::~Grid() { free(_brickTable[i]); } free(_currentGrid); - free(_currentBll); + free(_currentBlockLibrary); free(_brickInfoBuffer); free(_bricksDataBuffer); } @@ -297,8 +297,8 @@ void Grid::loadGridBricks() { const uint8 currentBitMask = 1 << (7 - (i & 7)); if (currentBitByte & currentBitMask) { - uint32 currentBllOffset = READ_LE_UINT32(_currentBll + currentBllEntryIdx); - const uint8 *currentBllPtr = _currentBll + currentBllOffset; + uint32 currentBllOffset = READ_LE_UINT32(_currentBlockLibrary + currentBllEntryIdx); + const uint8 *currentBllPtr = _currentBlockLibrary + currentBllOffset; const uint32 bllSizeX = *currentBllPtr++; const uint32 bllSizeY = *currentBllPtr++; @@ -444,7 +444,7 @@ bool Grid::initGrid(int32 index) { } // load layouts from file - if (HQR::getAllocEntry(&_currentBll, Resources::HQR_LBA_BLL_FILE, index) == 0) { + if (HQR::getAllocEntry(&_currentBlockLibrary, Resources::HQR_LBA_BLL_FILE, index) == 0) { warning("Failed to load block library index: %i", index); return false; } @@ -453,7 +453,7 @@ bool Grid::initGrid(int32 index) { createGridMask(); - _numberOfBll = READ_LE_INT32(_currentBll) >> 2; + _numberOfBll = READ_LE_INT32(_currentBlockLibrary) >> 2; createGridMap(); @@ -594,28 +594,29 @@ bool Grid::drawBrickSprite(int32 index, int32 posX, int32 posY, const uint8 *ptr const uint8 *Grid::getBlockBufferGround(const IVec3 &pos, int32 &ground) { const IVec3 &collision = updateCollisionCoordinates(pos.x, pos.y, pos.z); - const int32 tempX = collision.x; - int32 tempY = collision.y; - const int32 tempZ = collision.z; - const uint8 *ptr = _blockBuffer + tempY * 2 + tempX * GRID_SIZE_Y * 2 + (tempZ * GRID_SIZE_X) * GRID_SIZE_Y * 2; + const uint8 *ptr = _blockBuffer + + collision.y * sizeof(int16) + + collision.x * GRID_SIZE_Y * sizeof(int16) + + collision.z * GRID_SIZE_X * GRID_SIZE_Y * sizeof(int16); - while (tempY) { + int32 collisionY = collision.y; + while (collisionY) { if (READ_LE_INT16(ptr)) { // found the ground break; } - tempY--; - ptr -= 2; + collisionY--; + ptr -= sizeof(int16); } - _engine->_collision->_collision.y = tempY; - ground = (int16)((tempY + 1) * BRICK_HEIGHT); + _engine->_collision->_collision.y = collisionY; + ground = (int16)((collisionY + 1) * BRICK_HEIGHT); return ptr; } const uint8 *Grid::getBlockLibrary(int32 index) const { - const int32 offset = READ_LE_UINT32(_currentBll + 4 * index); - return (const uint8 *)(_currentBll + offset); + const int32 offset = READ_LE_UINT32(_currentBlockLibrary + 4 * index); + return (const uint8 *)(_currentBlockLibrary + offset); } void Grid::getBrickPos(int32 x, int32 y, int32 z) { @@ -722,7 +723,7 @@ ShapeType Grid::getBrickShape(int32 x, int32 y, int32 z) { uint8 blockIdx = *blockBufferPtr; if (blockIdx) { - const uint8 *blockPtr = _currentBll; + const uint8 *blockPtr = _currentBlockLibrary; blockPtr += READ_LE_UINT32(blockPtr + blockIdx * 4 - 4); blockPtr += 3; @@ -765,7 +766,7 @@ ShapeType Grid::getBrickShapeFull(int32 x, int32 y, int32 z, int32 y2) { uint8 blockIdx = *blockBufferPtr; if (blockIdx) { - const uint8 *blockPtr = _currentBll; + const uint8 *blockPtr = _currentBlockLibrary; blockPtr += READ_LE_UINT32(blockPtr + blockIdx * 4 - 4); blockPtr += 3; @@ -837,7 +838,7 @@ int32 Grid::getBrickSoundType(int32 x, int32 y, int32 z) { uint8 blockIdx = *blockBufferPtr; if (blockIdx) { - const uint8 *blockPtr = _currentBll; + const uint8 *blockPtr = _currentBlockLibrary; blockPtr += READ_LE_UINT32(blockPtr + blockIdx * 4 - 4); blockPtr += 3; diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h index 1d7cd5cfd05..c3f8e9bc89e 100644 --- a/engines/twine/scene/grid.h +++ b/engines/twine/scene/grid.h @@ -159,7 +159,7 @@ private: int32 _currentGridSize = 0; uint8 *_currentGrid = nullptr; /** Current block library pointer */ - uint8 *_currentBll = nullptr; + uint8 *_currentBlockLibrary = nullptr; /** Number of block libraries */ int32 _numberOfBll = 0;