TWINE: prepare extraction into constants

This commit is contained in:
Martin Gerhardy 2020-12-24 15:06:48 +01:00
parent 174bbd1d59
commit 2cfad1618f
11 changed files with 65 additions and 62 deletions

View file

@ -49,9 +49,9 @@ void Sound::setSamplePosition(int32 channelIdx, int32 x, int32 y, int32 z) {
if (channelIdx < 0 || channelIdx >= NUM_CHANNELS) {
return;
}
const int32 camX = _engine->_grid->newCameraX << 9;
const int32 camY = _engine->_grid->newCameraY << 8;
const int32 camZ = _engine->_grid->newCameraZ << 9;
const int32 camX = _engine->_grid->newCameraX * 512;
const int32 camY = _engine->_grid->newCameraY * 256;
const int32 camZ = _engine->_grid->newCameraZ * 512;
int32 distance = _engine->_movements->getDistance3D(camX, camY, camZ, x, y, z);
distance = _engine->_collision->getAverageValue(0, distance, 10000, 255);
const byte targetVolume = CLIP<byte>(255 - distance, 0, 255);

View file

@ -343,9 +343,9 @@ void Redraw::processDrawListShadows(const DrawListStruct &drawCmd) {
_engine->_grid->drawSprite(drawCmd.offset, renderRect.left, renderRect.top, _engine->_resources->spriteShadowPtr);
}
const int32 tmpX = (drawCmd.x + 0x100) >> 9;
const int32 tmpY = drawCmd.y >> 8;
const int32 tmpZ = (drawCmd.z + 0x100) >> 9;
const int32 tmpX = (drawCmd.x + 256) / 512;
const int32 tmpY = drawCmd.y / 256;
const int32 tmpZ = (drawCmd.z + 256) / 512;
_engine->_grid->drawOverModelActor(tmpX, tmpY, tmpZ);
@ -388,9 +388,9 @@ void Redraw::processDrawListActors(const DrawListStruct &drawCmd, bool bgRedraw)
if (_engine->_interface->textWindow.left <= _engine->_interface->textWindow.right && _engine->_interface->textWindow.top <= _engine->_interface->textWindow.bottom) {
actor->dynamicFlags.bIsVisible = 1;
const int32 tempX = (actor->x + 0x100) >> 9;
int32 tempY = actor->y >> 8;
const int32 tempZ = (actor->z + 0x100) >> 9;
const int32 tempX = (actor->x + 256) / 512;
int32 tempY = actor->y / 256;
const int32 tempZ = (actor->z + 256) / 512;
if (actor->brickShape() != ShapeType::kNone) {
tempY++;
}
@ -443,14 +443,14 @@ void Redraw::processDrawListActorSprites(const DrawListStruct &drawCmd, bool bgR
actor->dynamicFlags.bIsVisible = 1;
if (actor->staticFlags.bUsesClipping) {
const int32 tmpX = (actor->lastX + 0x100) >> 9;
const int32 tmpY = actor->lastY >> 8;
const int32 tmpZ = (actor->lastZ + 0x100) >> 9;
const int32 tmpX = (actor->lastX + 256) / 512;
const int32 tmpY = actor->lastY / 256;
const int32 tmpZ = (actor->lastZ + 256) / 512;
_engine->_grid->drawOverSpriteActor(tmpX, tmpY, tmpZ);
} else {
const int32 tmpX = (actor->x + actor->boudingBox.x.topRight + 0x100) >> 9;
int32 tmpY = actor->y >> 8;
const int32 tmpZ = (actor->z + actor->boudingBox.z.topRight + 0x100) >> 9;
const int32 tmpX = (actor->x + actor->boudingBox.x.topRight + 256) / 512;
int32 tmpY = actor->y / 256;
const int32 tmpZ = (actor->z + actor->boudingBox.z.topRight + 256) / 512;
if (actor->brickShape() != ShapeType::kNone) {
tmpY++;
}
@ -495,9 +495,9 @@ void Redraw::processDrawListExtras(const DrawListStruct &drawCmd) {
_engine->_interface->setClip(renderRect);
if (_engine->_interface->textWindow.left <= _engine->_interface->textWindow.right && _engine->_interface->textWindow.top <= _engine->_interface->textWindow.bottom) {
const int32 tmpX = (drawCmd.x + 0x100) >> 9;
const int32 tmpY = drawCmd.y >> 8;
const int32 tmpZ = (drawCmd.z + 0x100) >> 9;
const int32 tmpX = (drawCmd.x + 256) / 512;
const int32 tmpY = drawCmd.y / 256;
const int32 tmpZ = (drawCmd.z + 256) / 512;
_engine->_grid->drawOverModelActor(tmpX, tmpY, tmpZ);
addRedrawArea(_engine->_interface->textWindow.left, _engine->_interface->textWindow.top, renderRect.right, renderRect.bottom);

View file

@ -777,7 +777,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
if (brickShape == ShapeType::kSolid) {
if (actor->dynamicFlags.bIsFalling) {
_engine->_collision->stopFalling();
_engine->_movements->processActorY = (_engine->_collision->collisionY << 8) + 0x100;
_engine->_movements->processActorY = (_engine->_collision->collisionY * 256) + 256;
} else {
if (IS_HERO(actorIdx) && _engine->_actor->heroBehaviour == HeroBehaviourType::kAthletic && actor->anim == AnimationTypes::kForward && _engine->cfgfile.WallCollision) { // avoid wall hit damage
_engine->_extra->addExtraSpecial(actor->x, actor->y + 1000, actor->z, ExtraSpecialType::kHitStars);

View file

@ -112,9 +112,9 @@ void Collision::reajustActorPosition(ShapeType brickShape) {
return;
}
const int32 brkX = (collisionX << 9) - 0x100;
const int32 brkY = collisionY << 8;
const int32 brkZ = (collisionZ << 9) - 0x100;
const int32 brkX = (collisionX * 512) - 256;
const int32 brkY = collisionY * 256;
const int32 brkZ = (collisionZ * 512) - 256;
// double-side stairs
if (brickShape >= ShapeType::kDoubleSideStairsTop1 && brickShape <= ShapeType::kDoubleSideStairsRight2) {

View file

@ -862,7 +862,7 @@ void Extra::processExtras() {
if (process) {
const BoundingBox *bbox = _engine->_resources->spriteBoundingBox.bbox(extra->info0);
extra->y = (_engine->_collision->collisionY << 8) + 0x100 - bbox->mins.y;
extra->y = (_engine->_collision->collisionY * 256) + 256 - bbox->mins.y;
extra->type &= ~(ExtraType::STOP_COL | ExtraType::FLY);
continue;
}

View file

@ -268,9 +268,9 @@ bool GameState::saveGame(Common::WriteStream *file) {
}
void GameState::processFoundItem(int32 item) {
_engine->_grid->newCameraX = (_engine->_scene->sceneHero->x + 0x100) >> 9;
_engine->_grid->newCameraY = (_engine->_scene->sceneHero->y + 0x100) >> 8;
_engine->_grid->newCameraZ = (_engine->_scene->sceneHero->z + 0x100) >> 9;
_engine->_grid->newCameraX = (_engine->_scene->sceneHero->x + 256) / 512;
_engine->_grid->newCameraY = (_engine->_scene->sceneHero->y + 256) / 256;
_engine->_grid->newCameraZ = (_engine->_scene->sceneHero->z + 256) / 512;
// Hide hero in scene
_engine->_scene->sceneHero->staticFlags.bIsHidden = 1;
@ -279,19 +279,19 @@ void GameState::processFoundItem(int32 item) {
_engine->_screens->copyScreen(_engine->frontVideoBuffer, _engine->workVideoBuffer);
const int32 itemCameraX = _engine->_grid->newCameraX << 9;
const int32 itemCameraY = _engine->_grid->newCameraY << 8;
const int32 itemCameraZ = _engine->_grid->newCameraZ << 9;
const int32 itemCameraX = _engine->_grid->newCameraX * 512;
const int32 itemCameraY = _engine->_grid->newCameraY * 256;
const int32 itemCameraZ = _engine->_grid->newCameraZ * 512;
_engine->_renderer->renderIsoModel(_engine->_scene->sceneHero->x - itemCameraX, _engine->_scene->sceneHero->y - itemCameraY, _engine->_scene->sceneHero->z - itemCameraZ, 0, 0x80, 0, _engine->_actor->bodyTable[_engine->_scene->sceneHero->entity]);
_engine->_interface->setClip(_engine->_redraw->renderRect);
const int32 itemX = (_engine->_scene->sceneHero->x + 0x100) >> 9;
int32 itemY = _engine->_scene->sceneHero->y >> 8;
const int32 itemX = (_engine->_scene->sceneHero->x + 256) / 512;
int32 itemY = _engine->_scene->sceneHero->y / 256;
if (_engine->_scene->sceneHero->brickShape() != ShapeType::kNone) {
itemY++;
}
const int32 itemZ = (_engine->_scene->sceneHero->z + 0x100) >> 9;
const int32 itemZ = (_engine->_scene->sceneHero->z + 256) / 512;
_engine->_grid->drawOverModelActor(itemX, itemY, itemZ);
_engine->flip();

View file

@ -570,9 +570,9 @@ void Grid::drawBrickSprite(int32 index, int32 posX, int32 posY, const uint8 *ptr
}
uint8 *Grid::getBlockBuffer(int32 x, int32 y, int32 z) {
const int32 tempX = (x + 0x100) >> 9;
const int32 tempY = y >> 8;
const int32 tempZ = (z + 0x100) >> 9;
const int32 tempX = (x + 256) / 512;
const int32 tempY = y / 256;
const int32 tempZ = (z + 256) / 512;
return blockBuffer + tempY * 2 + tempX * GRID_SIZE_Y * 2 + (tempZ * GRID_SIZE_X) * GRID_SIZE_Y * 2;
}
@ -592,7 +592,7 @@ const uint8 *Grid::getBlockBufferGround(int32 x, int32 y, int32 z, int16 &ground
}
_engine->_collision->collisionY = tempY;
ground = (int16)((tempY + 1) << 8);
ground = (int16)((tempY + 1) * 256);
return ptr;
}
@ -659,9 +659,9 @@ void Grid::drawColumnGrid(int32 blockIdx, int32 brickBlockIdx, int32 x, int32 y,
void Grid::redrawGrid() {
blockMap *map = (blockMap *)blockBuffer;
cameraX = newCameraX << 9;
cameraY = newCameraY << 8;
cameraZ = newCameraZ << 9;
cameraX = newCameraX * 512;
cameraY = newCameraY * 256;
cameraZ = newCameraZ * 512;
_engine->_renderer->projectPositionOnScreen(-cameraX, -cameraY, -cameraZ);
@ -723,9 +723,9 @@ ShapeType Grid::getBrickShape(int32 x, int32 y, int32 z) {
}
void Grid::updateCollisionCoordinates(int32 x, int32 y, int32 z) {
_engine->_collision->collisionX = (x + 0x100) >> 9;
_engine->_collision->collisionY = y >> 8;
_engine->_collision->collisionZ = (z + 0x100) >> 9;
_engine->_collision->collisionX = (x + 256) / 512;
_engine->_collision->collisionY = y / 256;
_engine->_collision->collisionZ = (z + 256) / 512;
}
ShapeType Grid::getBrickShapeFull(int32 x, int32 y, int32 z, int32 y2) {
@ -761,7 +761,7 @@ ShapeType Grid::getBrickShapeFull(int32 x, int32 y, int32 z, int32 y2) {
const ShapeType brickShape = (ShapeType)*blockPtr;
const int32 newY = (y2 + 255) >> 8;
const int32 newY = (y2 + 255) / 256;
int32 currY = _engine->_collision->collisionY;
for (int32 i = 0; i < newY; i++) {
@ -781,7 +781,7 @@ ShapeType Grid::getBrickShapeFull(int32 x, int32 y, int32 z, int32 y2) {
}
const ShapeType brickShape = (ShapeType) * (blockBufferPtr + 1);
const int32 newY = (y2 + 255) >> 8;
const int32 newY = (y2 + 255) / 256;
int32 currY = _engine->_collision->collisionY;
for (int32 i = 0; i < newY; i++) {

View file

@ -74,6 +74,9 @@ struct BrickEntry {
/** Grip Z size */
#define GRID_SIZE_Z GRID_SIZE_X
#define BRICK_SIZE 512
#define BRICK_HEIGHT 256
#define NUMBRICKENTRIES (1 + (SCREEN_WIDTH + 24) / 24)
#define MAXBRICKS 150

View file

@ -356,9 +356,9 @@ void Scene::changeScene() {
_sampleAmbienceTime = 0;
ActorStruct *followedActor = getActor(currentlyFollowedActor);
_engine->_grid->newCameraX = followedActor->x >> 9;
_engine->_grid->newCameraY = followedActor->y >> 8;
_engine->_grid->newCameraZ = followedActor->z >> 9;
_engine->_grid->newCameraX = followedActor->x / 512;
_engine->_grid->newCameraY = followedActor->y / 256;
_engine->_grid->newCameraZ = followedActor->z / 512;
_engine->_gameState->magicBallIdx = -1;
_engine->_movements->heroMoved = true;

View file

@ -708,9 +708,9 @@ static int32 lCAM_FOLLOW(TwinEEngine *engine, LifeScriptContext &ctx) {
if (engine->_scene->currentlyFollowedActor != followedActorIdx) {
const ActorStruct *followedActor = engine->_scene->getActor(followedActorIdx);
engine->_grid->newCameraX = followedActor->x >> 9;
engine->_grid->newCameraY = followedActor->y >> 8;
engine->_grid->newCameraZ = followedActor->z >> 9;
engine->_grid->newCameraX = followedActor->x / 512;
engine->_grid->newCameraY = followedActor->y / 256;
engine->_grid->newCameraZ = followedActor->z / 512;
engine->_scene->currentlyFollowedActor = followedActorIdx;
engine->_redraw->reqBgRedraw = true;

View file

@ -614,13 +614,13 @@ void TwinEEngine::centerScreenOnActor() {
}
ActorStruct *actor = _scene->getActor(_scene->currentlyFollowedActor);
_renderer->projectPositionOnScreen(actor->x - (_grid->newCameraX << 9),
actor->y - (_grid->newCameraY << 8),
actor->z - (_grid->newCameraZ << 9));
_renderer->projectPositionOnScreen(actor->x - (_grid->newCameraX * 512),
actor->y - (_grid->newCameraY * 256),
actor->z - (_grid->newCameraZ * 512));
if (_renderer->projPosX < 80 || _renderer->projPosX >= SCREEN_WIDTH - 60 || _renderer->projPosY < 80 || _renderer->projPosY >= SCREEN_HEIGHT - 50) {
_grid->newCameraX = ((actor->x + 0x100) >> 9) + (((actor->x + 0x100) >> 9) - _grid->newCameraX) / 2;
_grid->newCameraY = actor->y >> 8;
_grid->newCameraZ = ((actor->z + 0x100) >> 9) + (((actor->z + 0x100) >> 9) - _grid->newCameraZ) / 2;
_grid->newCameraX = ((actor->x + 256) / 512) + (((actor->x + 256) / 512) - _grid->newCameraX) / 2;
_grid->newCameraY = actor->y / 256;
_grid->newCameraZ = ((actor->z + 256) / 512) + (((actor->z + 256) / 512) - _grid->newCameraZ) / 2;
if (_grid->newCameraX >= GRID_SIZE_X) {
_grid->newCameraX = GRID_SIZE_X - 1;
@ -732,9 +732,9 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
// Recenter Screen
if (_input->isActionActive(TwinEActionType::RecenterScreenOnTwinsen) && !disableScreenRecenter) {
const ActorStruct *currentlyFollowedActor = _scene->getActor(_scene->currentlyFollowedActor);
_grid->newCameraX = currentlyFollowedActor->x >> 9;
_grid->newCameraY = currentlyFollowedActor->y >> 8;
_grid->newCameraZ = currentlyFollowedActor->z >> 9;
_grid->newCameraX = currentlyFollowedActor->x / 512;
_grid->newCameraY = currentlyFollowedActor->y / 256;
_grid->newCameraZ = currentlyFollowedActor->z / 512;
_redraw->reqBgRedraw = true;
}
@ -876,9 +876,9 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration
_scene->needChangeScene = _scene->currentSceneIdx;
_gameState->inventoryMagicPoints = _gameState->magicLevelIdx * 20;
_grid->newCameraX = (_scene->sceneHero->x >> 9);
_grid->newCameraY = (_scene->sceneHero->y >> 8);
_grid->newCameraZ = (_scene->sceneHero->z >> 9);
_grid->newCameraX = (_scene->sceneHero->x / 512);
_grid->newCameraY = (_scene->sceneHero->y / 256);
_grid->newCameraZ = (_scene->sceneHero->z / 512);
_scene->heroPositionType = ScenePositionType::kReborn;