[Scummvm-git-logs] scummvm master -> 5f2383e3c416146234d0a6d6606ba039a70ba24f
mgerhardy
martin.gerhardy at gmail.com
Sat Dec 26 11:11:30 UTC 2020
This automated email contains information about 11 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
236dca8f9a TWINE: replaced magic number with constant
1356ae5fdf TWINE: renamed variables
05e86f562e TWINE: format the code
0d1965d443 TWINE: unified writing of fps for text loops
174bbd1d59 TWINE: replaced magic numbers
2cfad1618f TWINE: prepare extraction into constants
9eb0c1fd10 TWINE: use constants for magic values
f4fa272b26 TWINE: replaced magic numbers
438deb671f TWINE: use constants for magic numbers
968d3b1ba2 TWINE: prepare to extract magic numbers to constants
5f2383e3c4 TWINE: fixed rendering errors for brick sprites
Commit: 236dca8f9aa3f7605da6748563e8639c6abdbf1a
https://github.com/scummvm/scummvm/commit/236dca8f9aa3f7605da6748563e8639c6abdbf1a
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: replaced magic number with constant
Changed paths:
engines/twine/scene/grid.cpp
engines/twine/scene/grid.h
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index c2c92c2016..07815cd2bb 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -637,7 +637,7 @@ void Grid::drawColumnGrid(int32 blockIdx, int32 brickBlockIdx, int32 x, int32 y,
int32 brickBuffIdx = (brickPixelPosX + 24) / 24;
- if (brickInfoBuffer[brickBuffIdx] >= 150) {
+ if (brickInfoBuffer[brickBuffIdx] >= MAXBRICKS) {
warning("GRID: brick buffer exceeded");
return;
}
diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h
index 3619c80d5e..7d6d2720b7 100644
--- a/engines/twine/scene/grid.h
+++ b/engines/twine/scene/grid.h
@@ -75,6 +75,7 @@ struct BrickEntry {
#define GRID_SIZE_Z GRID_SIZE_X
#define NUMBRICKENTRIES (1 + (SCREEN_WIDTH + 24) / 24)
+#define MAXBRICKS 150
class TwinEEngine;
@@ -156,7 +157,7 @@ private:
int32 numberOfBll = 0;
/** Brick data buffer */
- BrickEntry bricksDataBuffer[NUMBRICKENTRIES][150];
+ BrickEntry bricksDataBuffer[NUMBRICKENTRIES][MAXBRICKS];
/** Brick info buffer */
int16 brickInfoBuffer[NUMBRICKENTRIES]{0};
Commit: 1356ae5fdfa95c0266d89584a4172fd7c1227e2d
https://github.com/scummvm/scummvm/commit/1356ae5fdfa95c0266d89584a4172fd7c1227e2d
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: renamed variables
Changed paths:
engines/twine/scene/grid.cpp
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index 07815cd2bb..8f7a5f3f8f 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -521,12 +521,12 @@ void Grid::drawBrickSprite(int32 index, int32 posX, int32 posY, const uint8 *ptr
//if (left >= textWindowLeft-2 && top >= textWindowTop-2 && right <= textWindowRight-2 && bottom <= textWindowBottom-2) // crop
{
- for (int32 y = top; y < maxY; y++) {
- uint8 vc3 = *(ptr++);
- for (int32 c2 = 0; c2 < vc3; c2++) {
- const uint8 temp = *ptr++;
- const uint8 iterations = bits(temp, 0, 6) + 1;
- const uint8 type = bits(temp, 6, 2);
+ for (int32 y = top; y < maxY; ++y) {
+ const uint8 rleAmount = *ptr++;
+ for (int32 run = 0; run < rleAmount; ++run) {
+ const uint8 rleMask = *ptr++;
+ const uint8 iterations = bits(rleMask, 0, 6) + 1;
+ const uint8 type = bits(rleMask, 6, 2);
if (type == 0) {
x += iterations;
continue;
Commit: 05e86f562e1187cf181208a19394316547921d38
https://github.com/scummvm/scummvm/commit/05e86f562e1187cf181208a19394316547921d38
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: format the code
Changed paths:
engines/twine/renderer/redraw.cpp
engines/twine/renderer/renderer.cpp
engines/twine/twine.cpp
diff --git a/engines/twine/renderer/redraw.cpp b/engines/twine/renderer/redraw.cpp
index 89906d02f4..2c15c5aa58 100644
--- a/engines/twine/renderer/redraw.cpp
+++ b/engines/twine/renderer/redraw.cpp
@@ -24,21 +24,21 @@
#include "common/memstream.h"
#include "common/textconsole.h"
#include "graphics/surface.h"
-#include "twine/parser/sprite.h"
-#include "twine/scene/actor.h"
-#include "twine/scene/animations.h"
#include "twine/audio/sound.h"
-#include "twine/scene/collision.h"
#include "twine/debugger/debug_scene.h"
-#include "twine/scene/grid.h"
-#include "twine/resources/hqr.h"
#include "twine/input.h"
#include "twine/menu/interface.h"
#include "twine/menu/menu.h"
-#include "twine/scene/movements.h"
+#include "twine/parser/sprite.h"
#include "twine/renderer/renderer.h"
#include "twine/renderer/screens.h"
+#include "twine/resources/hqr.h"
#include "twine/resources/resources.h"
+#include "twine/scene/actor.h"
+#include "twine/scene/animations.h"
+#include "twine/scene/collision.h"
+#include "twine/scene/grid.h"
+#include "twine/scene/movements.h"
#include "twine/scene/scene.h"
#include "twine/text.h"
@@ -424,7 +424,7 @@ void Redraw::processDrawListActorSprites(const DrawListStruct &drawCmd, bool bgR
const int32 spriteHeight = spritePtr.surface().h;
// calculate sprite position on screen
- const SpriteDim* dim = _engine->_resources->spriteBoundingBox.dim(actor->entity);
+ const SpriteDim *dim = _engine->_resources->spriteBoundingBox.dim(actor->entity);
renderRect.left = _engine->_renderer->projPosX + dim->x;
renderRect.top = _engine->_renderer->projPosY + dim->y;
renderRect.right = renderRect.left + spriteWidth;
@@ -483,7 +483,7 @@ void Redraw::processDrawListExtras(const DrawListStruct &drawCmd) {
const int32 spriteHeight = spritePtr.surface().h;
// calculate sprite position on screen
- const SpriteDim* dim = _engine->_resources->spriteBoundingBox.dim(extra->info0);
+ const SpriteDim *dim = _engine->_resources->spriteBoundingBox.dim(extra->info0);
renderRect.left = _engine->_renderer->projPosX + dim->x;
renderRect.top = _engine->_renderer->projPosY + dim->y;
renderRect.right = renderRect.left + spriteWidth;
@@ -574,7 +574,7 @@ void Redraw::renderOverlays() {
const int32 spriteWidth = spritePtr.surface().w;
const int32 spriteHeight = spritePtr.surface().h;
- const SpriteDim* dim = _engine->_resources->spriteBoundingBox.dim(overlay->info0);
+ const SpriteDim *dim = _engine->_resources->spriteBoundingBox.dim(overlay->info0);
renderRect.left = dim->x + overlay->x;
renderRect.top = dim->y + overlay->y;
renderRect.right = renderRect.left + spriteWidth;
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 8a79dd5ef1..916d3a53d2 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -105,9 +105,9 @@ void Renderer::getBaseRotationPosition(int32 x, int32 y, int32 z) {
}
void Renderer::setBaseRotation(int32 x, int32 y, int32 z) {
- double Xradians = (double)((ANGLE_90 - x) % ANGLE_360) * 2 * M_PI / ANGLE_360;
- double Yradians = (double)((ANGLE_90 - y) % ANGLE_360) * 2 * M_PI / ANGLE_360;
- double Zradians = (double)((ANGLE_90 - z) % ANGLE_360) * 2 * M_PI / ANGLE_360;
+ const double Xradians = (double)((ANGLE_90 - x) % ANGLE_360) * 2 * M_PI / ANGLE_360;
+ const double Yradians = (double)((ANGLE_90 - y) % ANGLE_360) * 2 * M_PI / ANGLE_360;
+ const double Zradians = (double)((ANGLE_90 - z) % ANGLE_360) * 2 * M_PI / ANGLE_360;
baseMatrix.row1[0] = (int32)(sin(Zradians) * sin(Yradians) * 16384);
baseMatrix.row1[1] = (int32)(-cos(Zradians) * 16384);
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index 1b3f9b7337..af703b0c1a 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -43,30 +43,30 @@
#include "graphics/pixelformat.h"
#include "graphics/surface.h"
#include "gui/debugger.h"
-#include "twine/scene/actor.h"
-#include "twine/scene/animations.h"
#include "twine/audio/music.h"
#include "twine/audio/sound.h"
-#include "twine/scene/collision.h"
#include "twine/debugger/console.h"
#include "twine/debugger/debug.h"
#include "twine/debugger/debug_grid.h"
#include "twine/debugger/debug_scene.h"
-#include "twine/scene/extra.h"
#include "twine/flamovies.h"
-#include "twine/scene/gamestate.h"
-#include "twine/scene/grid.h"
#include "twine/holomap.h"
-#include "twine/resources/hqr.h"
#include "twine/input.h"
#include "twine/menu/interface.h"
#include "twine/menu/menu.h"
#include "twine/menu/menuoptions.h"
-#include "twine/scene/movements.h"
#include "twine/renderer/redraw.h"
#include "twine/renderer/renderer.h"
#include "twine/renderer/screens.h"
+#include "twine/resources/hqr.h"
#include "twine/resources/resources.h"
+#include "twine/scene/actor.h"
+#include "twine/scene/animations.h"
+#include "twine/scene/collision.h"
+#include "twine/scene/extra.h"
+#include "twine/scene/gamestate.h"
+#include "twine/scene/grid.h"
+#include "twine/scene/movements.h"
#include "twine/scene/scene.h"
#include "twine/script/script_life_v1.h"
#include "twine/script/script_move_v1.h"
Commit: 0d1965d44390c0df8c6de57c71f0d60996dd62d0
https://github.com/scummvm/scummvm/commit/0d1965d44390c0df8c6de57c71f0d60996dd62d0
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: unified writing of fps for text loops
Changed paths:
engines/twine/scene/gamestate.cpp
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index 824e0a5a12..c6a0869137 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -332,7 +332,7 @@ void GameState::processFoundItem(int32 item) {
ScopedKeyMap uiKeyMap(_engine, uiKeyMapId);
for (;;) {
- ScopedFPS fps(1000 / 15);
+ ScopedFPS fps(66);
_engine->_interface->resetClip();
_engine->_redraw->currNumOfRedrawBox = 0;
_engine->_redraw->blitBackgroundAreas();
Commit: 174bbd1d59be8bfdedfa7a0d799b8600a956477a
https://github.com/scummvm/scummvm/commit/174bbd1d59be8bfdedfa7a0d799b8600a956477a
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: replaced magic numbers
Changed paths:
engines/twine/scene/grid.cpp
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index 8f7a5f3f8f..995fa12561 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -393,7 +393,7 @@ void Grid::createGridMap() {
for (int32 z = 0; z < GRID_SIZE_Z; z++) {
int32 blockOffset = currOffset;
- const int32 gridIdx = z << 6;
+ const int32 gridIdx = z * GRID_SIZE_X;
for (int32 x = 0; x < GRID_SIZE_X; x++) {
const int32 gridOffset = READ_LE_UINT16(currentGrid + 2 * (x + gridIdx));
@@ -573,7 +573,7 @@ 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;
- return blockBuffer + tempY * 2 + tempX * GRID_SIZE_Y * 2 + (tempZ << 6) * GRID_SIZE_Y * 2;
+ return blockBuffer + tempY * 2 + tempX * GRID_SIZE_Y * 2 + (tempZ * GRID_SIZE_X) * GRID_SIZE_Y * 2;
}
const uint8 *Grid::getBlockBufferGround(int32 x, int32 y, int32 z, int16 &ground) const {
@@ -581,7 +581,7 @@ const uint8 *Grid::getBlockBufferGround(int32 x, int32 y, int32 z, int16 &ground
const int32 tempX = _engine->_collision->collisionX;
int32 tempY = _engine->_collision->collisionY;
const int32 tempZ = _engine->_collision->collisionZ;
- const uint8 *ptr = blockBuffer + tempY * 2 + tempX * GRID_SIZE_Y * 2 + (tempZ << 6) * GRID_SIZE_Y * 2;
+ const uint8 *ptr = blockBuffer + tempY * 2 + tempX * GRID_SIZE_Y * 2 + (tempZ * GRID_SIZE_X) * GRID_SIZE_Y * 2;
while (tempY) {
if (READ_LE_INT16(ptr)) { // found the ground
@@ -704,7 +704,7 @@ ShapeType Grid::getBrickShape(int32 x, int32 y, int32 z) {
uint8 *blockBufferPtr = blockBuffer;
blockBufferPtr += _engine->_collision->collisionX * GRID_SIZE_Y * 2;
blockBufferPtr += _engine->_collision->collisionY * 2;
- blockBufferPtr += (_engine->_collision->collisionZ << 7) * GRID_SIZE_Y;
+ blockBufferPtr += (_engine->_collision->collisionZ * GRID_SIZE_X * 2) * GRID_SIZE_Y;
uint8 blockIdx = *blockBufferPtr;
@@ -746,7 +746,7 @@ ShapeType Grid::getBrickShapeFull(int32 x, int32 y, int32 z, int32 y2) {
uint8 *blockBufferPtr = blockBuffer;
blockBufferPtr += _engine->_collision->collisionX * GRID_SIZE_Y * 2;
blockBufferPtr += _engine->_collision->collisionY * 2;
- blockBufferPtr += (_engine->_collision->collisionZ << 7) * GRID_SIZE_Y;
+ blockBufferPtr += (_engine->_collision->collisionZ * GRID_SIZE_X * 2) * GRID_SIZE_Y;
uint8 blockIdx = *blockBufferPtr;
@@ -818,7 +818,7 @@ int32 Grid::getBrickSoundType(int32 x, int32 y, int32 z) { // getPos2
const uint8 *blockBufferPtr = blockBuffer;
blockBufferPtr += _engine->_collision->collisionX * GRID_SIZE_Y * 2;
blockBufferPtr += _engine->_collision->collisionY * 2;
- blockBufferPtr += (_engine->_collision->collisionZ << 7) * GRID_SIZE_Y;
+ blockBufferPtr += (_engine->_collision->collisionZ * GRID_SIZE_X * 2) * GRID_SIZE_Y;
uint8 blockIdx = *blockBufferPtr;
Commit: 2cfad1618f52659ce7ee07f3a04efd9b9610865f
https://github.com/scummvm/scummvm/commit/2cfad1618f52659ce7ee07f3a04efd9b9610865f
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: prepare extraction into constants
Changed paths:
engines/twine/audio/sound.cpp
engines/twine/renderer/redraw.cpp
engines/twine/scene/animations.cpp
engines/twine/scene/collision.cpp
engines/twine/scene/extra.cpp
engines/twine/scene/gamestate.cpp
engines/twine/scene/grid.cpp
engines/twine/scene/grid.h
engines/twine/scene/scene.cpp
engines/twine/script/script_life_v1.cpp
engines/twine/twine.cpp
diff --git a/engines/twine/audio/sound.cpp b/engines/twine/audio/sound.cpp
index b92261b9bd..3a87615d9d 100644
--- a/engines/twine/audio/sound.cpp
+++ b/engines/twine/audio/sound.cpp
@@ -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);
diff --git a/engines/twine/renderer/redraw.cpp b/engines/twine/renderer/redraw.cpp
index 2c15c5aa58..0d4cc12b9e 100644
--- a/engines/twine/renderer/redraw.cpp
+++ b/engines/twine/renderer/redraw.cpp
@@ -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);
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index dcf8e6a1f5..0b27190ac2 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -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);
diff --git a/engines/twine/scene/collision.cpp b/engines/twine/scene/collision.cpp
index 32099da48e..3fd43950f1 100644
--- a/engines/twine/scene/collision.cpp
+++ b/engines/twine/scene/collision.cpp
@@ -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) {
diff --git a/engines/twine/scene/extra.cpp b/engines/twine/scene/extra.cpp
index 530d09d0a8..1695883ca5 100644
--- a/engines/twine/scene/extra.cpp
+++ b/engines/twine/scene/extra.cpp
@@ -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;
}
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index c6a0869137..43012caf2d 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -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();
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index 995fa12561..b82170cf08 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -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++) {
diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h
index 7d6d2720b7..9e87a088b7 100644
--- a/engines/twine/scene/grid.h
+++ b/engines/twine/scene/grid.h
@@ -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
diff --git a/engines/twine/scene/scene.cpp b/engines/twine/scene/scene.cpp
index 5ac3644812..dea9f941a8 100644
--- a/engines/twine/scene/scene.cpp
+++ b/engines/twine/scene/scene.cpp
@@ -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;
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index af597a397a..934a5e29d4 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -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;
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index af703b0c1a..adba2cd3b3 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -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;
Commit: 9eb0c1fd1092835e430c4cf4c15e084a4f6b4999
https://github.com/scummvm/scummvm/commit/9eb0c1fd1092835e430c4cf4c15e084a4f6b4999
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: use constants for magic values
Changed paths:
engines/twine/audio/sound.cpp
engines/twine/scene/animations.cpp
engines/twine/scene/collision.cpp
engines/twine/scene/extra.cpp
engines/twine/scene/gamestate.cpp
engines/twine/scene/grid.cpp
engines/twine/scene/scene.cpp
engines/twine/twine.cpp
diff --git a/engines/twine/audio/sound.cpp b/engines/twine/audio/sound.cpp
index 3a87615d9d..3ee3c33663 100644
--- a/engines/twine/audio/sound.cpp
+++ b/engines/twine/audio/sound.cpp
@@ -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 * 512;
- const int32 camY = _engine->_grid->newCameraY * 256;
- const int32 camZ = _engine->_grid->newCameraZ * 512;
+ const int32 camX = _engine->_grid->newCameraX * BRICK_SIZE;
+ const int32 camY = _engine->_grid->newCameraY * BRICK_HEIGHT;
+ const int32 camZ = _engine->_grid->newCameraZ * BRICK_SIZE;
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);
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index 0b27190ac2..eeeadb975a 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -717,7 +717,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
if (brickShape != ShapeType::kSolid) {
_engine->_collision->reajustActorPosition(brickShape);
} /*else { // this shouldn't happen (collision should avoid it)
- actor->y = processActorY = (processActorY / 256) * 256 + 256; // go upper
+ actor->y = processActorY = (processActorY / BRICK_HEIGHT) * BRICK_HEIGHT + BRICK_HEIGHT; // go upper
}*/
}
@@ -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 * 256) + 256;
+ _engine->_movements->processActorY = (_engine->_collision->collisionY * BRICK_HEIGHT) + BRICK_HEIGHT;
} 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);
diff --git a/engines/twine/scene/collision.cpp b/engines/twine/scene/collision.cpp
index 3fd43950f1..378e8adc99 100644
--- a/engines/twine/scene/collision.cpp
+++ b/engines/twine/scene/collision.cpp
@@ -112,9 +112,9 @@ void Collision::reajustActorPosition(ShapeType brickShape) {
return;
}
- const int32 brkX = (collisionX * 512) - 256;
- const int32 brkY = collisionY * 256;
- const int32 brkZ = (collisionZ * 512) - 256;
+ const int32 brkX = (collisionX * BRICK_SIZE) - BRICK_HEIGHT;
+ const int32 brkY = collisionY * BRICK_HEIGHT;
+ const int32 brkZ = (collisionZ * BRICK_SIZE) - BRICK_HEIGHT;
// double-side stairs
if (brickShape >= ShapeType::kDoubleSideStairsTop1 && brickShape <= ShapeType::kDoubleSideStairsRight2) {
diff --git a/engines/twine/scene/extra.cpp b/engines/twine/scene/extra.cpp
index 1695883ca5..8fe1cf7483 100644
--- a/engines/twine/scene/extra.cpp
+++ b/engines/twine/scene/extra.cpp
@@ -862,7 +862,7 @@ void Extra::processExtras() {
if (process) {
const BoundingBox *bbox = _engine->_resources->spriteBoundingBox.bbox(extra->info0);
- extra->y = (_engine->_collision->collisionY * 256) + 256 - bbox->mins.y;
+ extra->y = (_engine->_collision->collisionY * BRICK_HEIGHT) + BRICK_HEIGHT - bbox->mins.y;
extra->type &= ~(ExtraType::STOP_COL | ExtraType::FLY);
continue;
}
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index 43012caf2d..e5eb4c7f4b 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -268,9 +268,9 @@ bool GameState::saveGame(Common::WriteStream *file) {
}
void GameState::processFoundItem(int32 item) {
- _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;
+ _engine->_grid->newCameraX = (_engine->_scene->sceneHero->x + BRICK_HEIGHT) / BRICK_SIZE;
+ _engine->_grid->newCameraY = (_engine->_scene->sceneHero->y + BRICK_HEIGHT) / BRICK_HEIGHT;
+ _engine->_grid->newCameraZ = (_engine->_scene->sceneHero->z + BRICK_HEIGHT) / BRICK_SIZE;
// 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 * 512;
- const int32 itemCameraY = _engine->_grid->newCameraY * 256;
- const int32 itemCameraZ = _engine->_grid->newCameraZ * 512;
+ const int32 itemCameraX = _engine->_grid->newCameraX * BRICK_SIZE;
+ const int32 itemCameraY = _engine->_grid->newCameraY * BRICK_HEIGHT;
+ const int32 itemCameraZ = _engine->_grid->newCameraZ * BRICK_SIZE;
_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 + 256) / 512;
- int32 itemY = _engine->_scene->sceneHero->y / 256;
+ const int32 itemX = (_engine->_scene->sceneHero->x + BRICK_HEIGHT) / BRICK_SIZE;
+ int32 itemY = _engine->_scene->sceneHero->y / BRICK_HEIGHT;
if (_engine->_scene->sceneHero->brickShape() != ShapeType::kNone) {
itemY++;
}
- const int32 itemZ = (_engine->_scene->sceneHero->z + 256) / 512;
+ const int32 itemZ = (_engine->_scene->sceneHero->z + BRICK_HEIGHT) / BRICK_SIZE;
_engine->_grid->drawOverModelActor(itemX, itemY, itemZ);
_engine->flip();
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index b82170cf08..b3385cf433 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -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 + 256) / 512;
- const int32 tempY = y / 256;
- const int32 tempZ = (z + 256) / 512;
+ const int32 tempX = (x + BRICK_HEIGHT) / BRICK_SIZE;
+ const int32 tempY = y / BRICK_HEIGHT;
+ const int32 tempZ = (z + BRICK_HEIGHT) / BRICK_SIZE;
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) * 256);
+ ground = (int16)((tempY + 1) * BRICK_HEIGHT);
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 * 512;
- cameraY = newCameraY * 256;
- cameraZ = newCameraZ * 512;
+ cameraX = newCameraX * BRICK_SIZE;
+ cameraY = newCameraY * BRICK_HEIGHT;
+ cameraZ = newCameraZ * BRICK_SIZE;
_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 + 256) / 512;
- _engine->_collision->collisionY = y / 256;
- _engine->_collision->collisionZ = (z + 256) / 512;
+ _engine->_collision->collisionX = (x + BRICK_HEIGHT) / BRICK_SIZE;
+ _engine->_collision->collisionY = y / BRICK_HEIGHT;
+ _engine->_collision->collisionZ = (z + BRICK_HEIGHT) / BRICK_SIZE;
}
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) / 256;
+ const int32 newY = (y2 + (BRICK_HEIGHT - 1)) / BRICK_HEIGHT;
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) / 256;
+ const int32 newY = (y2 + (BRICK_HEIGHT - 1)) / BRICK_HEIGHT;
int32 currY = _engine->_collision->collisionY;
for (int32 i = 0; i < newY; i++) {
diff --git a/engines/twine/scene/scene.cpp b/engines/twine/scene/scene.cpp
index dea9f941a8..8061d9891f 100644
--- a/engines/twine/scene/scene.cpp
+++ b/engines/twine/scene/scene.cpp
@@ -356,9 +356,9 @@ void Scene::changeScene() {
_sampleAmbienceTime = 0;
ActorStruct *followedActor = getActor(currentlyFollowedActor);
- _engine->_grid->newCameraX = followedActor->x / 512;
- _engine->_grid->newCameraY = followedActor->y / 256;
- _engine->_grid->newCameraZ = followedActor->z / 512;
+ _engine->_grid->newCameraX = followedActor->x / BRICK_SIZE;
+ _engine->_grid->newCameraY = followedActor->y / BRICK_HEIGHT;
+ _engine->_grid->newCameraZ = followedActor->z / BRICK_SIZE;
_engine->_gameState->magicBallIdx = -1;
_engine->_movements->heroMoved = true;
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index adba2cd3b3..07894ed18e 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -614,13 +614,13 @@ void TwinEEngine::centerScreenOnActor() {
}
ActorStruct *actor = _scene->getActor(_scene->currentlyFollowedActor);
- _renderer->projectPositionOnScreen(actor->x - (_grid->newCameraX * 512),
- actor->y - (_grid->newCameraY * 256),
- actor->z - (_grid->newCameraZ * 512));
+ _renderer->projectPositionOnScreen(actor->x - (_grid->newCameraX * BRICK_SIZE),
+ actor->y - (_grid->newCameraY * BRICK_HEIGHT),
+ actor->z - (_grid->newCameraZ * BRICK_SIZE));
if (_renderer->projPosX < 80 || _renderer->projPosX >= SCREEN_WIDTH - 60 || _renderer->projPosY < 80 || _renderer->projPosY >= SCREEN_HEIGHT - 50) {
- _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;
+ _grid->newCameraX = ((actor->x + BRICK_HEIGHT) / BRICK_SIZE) + (((actor->x + BRICK_HEIGHT) / BRICK_SIZE) - _grid->newCameraX) / 2;
+ _grid->newCameraY = actor->y / BRICK_HEIGHT;
+ _grid->newCameraZ = ((actor->z + BRICK_HEIGHT) / BRICK_SIZE) + (((actor->z + BRICK_HEIGHT) / BRICK_SIZE) - _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 / 512;
- _grid->newCameraY = currentlyFollowedActor->y / 256;
- _grid->newCameraZ = currentlyFollowedActor->z / 512;
+ _grid->newCameraX = currentlyFollowedActor->x / BRICK_SIZE;
+ _grid->newCameraY = currentlyFollowedActor->y / BRICK_HEIGHT;
+ _grid->newCameraZ = currentlyFollowedActor->z / BRICK_SIZE;
_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 / 512);
- _grid->newCameraY = (_scene->sceneHero->y / 256);
- _grid->newCameraZ = (_scene->sceneHero->z / 512);
+ _grid->newCameraX = (_scene->sceneHero->x / BRICK_SIZE);
+ _grid->newCameraY = (_scene->sceneHero->y / BRICK_HEIGHT);
+ _grid->newCameraZ = (_scene->sceneHero->z / BRICK_SIZE);
_scene->heroPositionType = ScenePositionType::kReborn;
@@ -990,7 +990,7 @@ void TwinEEngine::setPalette(const uint32 *palette) {
out += 3;
in += 4;
}
- g_system->getPaletteManager()->setPalette(pal, 0, 256);
+ g_system->getPaletteManager()->setPalette(pal, 0, NUMOFCOLORS);
flip();
}
Commit: f4fa272b2660f11f288c33afebd9ede24223d9e1
https://github.com/scummvm/scummvm/commit/f4fa272b2660f11f288c33afebd9ede24223d9e1
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: replaced magic numbers
Changed paths:
engines/twine/renderer/renderer.cpp
engines/twine/scene/grid.h
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 916d3a53d2..9919df41bc 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -31,6 +31,7 @@
#include "twine/renderer/shadeangletab.h"
#include "twine/scene/actor.h"
#include "twine/scene/movements.h"
+#include "twine/scene/grid.h"
#include "twine/shared.h"
#include "twine/twine.h"
@@ -370,8 +371,8 @@ FORCEINLINE int16 clamp(int16 x, int16 a, int16 b) {
}
void Renderer::computeBoundingBox(Vertex *vertices, int32 numVertices, int &vleft, int &vright, int &vtop, int &vbottom) const {
- vleft = vtop = 32767;
- vright = vbottom = -32768;
+ vleft = vtop = SCENE_SIZE_MAX;
+ vright = vbottom = SCENE_SIZE_MIN;
for (int32 i = 0; i < numVertices; i++) {
vertices[i].x = clamp(vertices[i].x, 0, SCREEN_WIDTH - 1);
@@ -1421,10 +1422,10 @@ bool Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 ang
renderAngleZ = angleZ;
// model render size reset
- _engine->_redraw->renderRect.left = 32767;
- _engine->_redraw->renderRect.top = 32767;
- _engine->_redraw->renderRect.right = -32767;
- _engine->_redraw->renderRect.bottom = -32767;
+ _engine->_redraw->renderRect.left = SCENE_SIZE_MAX;
+ _engine->_redraw->renderRect.top = SCENE_SIZE_MAX;
+ _engine->_redraw->renderRect.right = SCENE_SIZE_MIN;
+ _engine->_redraw->renderRect.bottom = SCENE_SIZE_MIN;
if (isUsingOrhoProjection) {
renderX = x;
diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h
index 9e87a088b7..9a6f12c655 100644
--- a/engines/twine/scene/grid.h
+++ b/engines/twine/scene/grid.h
@@ -74,6 +74,11 @@ struct BrickEntry {
/** Grip Z size */
#define GRID_SIZE_Z GRID_SIZE_X
+// short max
+#define SCENE_SIZE_MAX (BRICK_SIZE * GRID_SIZE_X - 1)
+// short min
+#define SCENE_SIZE_MIN (-BRICK_SIZE * GRID_SIZE_X)
+
#define BRICK_SIZE 512
#define BRICK_HEIGHT 256
Commit: 438deb671fb11f3d45ffa7539437285ef693527e
https://github.com/scummvm/scummvm/commit/438deb671fb11f3d45ffa7539437285ef693527e
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: use constants for magic numbers
Changed paths:
engines/twine/renderer/redraw.cpp
engines/twine/renderer/renderer.cpp
engines/twine/scene/animations.cpp
engines/twine/scene/collision.cpp
engines/twine/scene/grid.h
engines/twine/script/script_life_v1.cpp
diff --git a/engines/twine/renderer/redraw.cpp b/engines/twine/renderer/redraw.cpp
index 0d4cc12b9e..473c191e9a 100644
--- a/engines/twine/renderer/redraw.cpp
+++ b/engines/twine/renderer/redraw.cpp
@@ -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 + 256) / 512;
- const int32 tmpY = drawCmd.y / 256;
- const int32 tmpZ = (drawCmd.z + 256) / 512;
+ const int32 tmpX = (drawCmd.x + BRICK_HEIGHT) / BRICK_SIZE;
+ const int32 tmpY = drawCmd.y / BRICK_HEIGHT;
+ const int32 tmpZ = (drawCmd.z + BRICK_HEIGHT) / BRICK_SIZE;
_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 + 256) / 512;
- int32 tempY = actor->y / 256;
- const int32 tempZ = (actor->z + 256) / 512;
+ const int32 tempX = (actor->x + BRICK_HEIGHT) / BRICK_SIZE;
+ int32 tempY = actor->y / BRICK_HEIGHT;
+ const int32 tempZ = (actor->z + BRICK_HEIGHT) / BRICK_SIZE;
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 + 256) / 512;
- const int32 tmpY = actor->lastY / 256;
- const int32 tmpZ = (actor->lastZ + 256) / 512;
+ const int32 tmpX = (actor->lastX + BRICK_HEIGHT) / BRICK_SIZE;
+ const int32 tmpY = actor->lastY / BRICK_HEIGHT;
+ const int32 tmpZ = (actor->lastZ + BRICK_HEIGHT) / BRICK_SIZE;
_engine->_grid->drawOverSpriteActor(tmpX, tmpY, tmpZ);
} else {
- 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;
+ const int32 tmpX = (actor->x + actor->boudingBox.x.topRight + BRICK_HEIGHT) / BRICK_SIZE;
+ int32 tmpY = actor->y / BRICK_HEIGHT;
+ const int32 tmpZ = (actor->z + actor->boudingBox.z.topRight + BRICK_HEIGHT) / BRICK_SIZE;
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 + 256) / 512;
- const int32 tmpY = drawCmd.y / 256;
- const int32 tmpZ = (drawCmd.z + 256) / 512;
+ const int32 tmpX = (drawCmd.x + BRICK_HEIGHT) / BRICK_SIZE;
+ const int32 tmpY = drawCmd.y / BRICK_HEIGHT;
+ const int32 tmpZ = (drawCmd.z + BRICK_HEIGHT) / BRICK_SIZE;
_engine->_grid->drawOverModelActor(tmpX, tmpY, tmpZ);
addRedrawArea(_engine->_interface->textWindow.left, _engine->_interface->textWindow.top, renderRect.right, renderRect.bottom);
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 9919df41bc..7bf8d4fdb2 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -46,8 +46,8 @@ Renderer::Renderer(TwinEEngine *engine) : _engine(engine), shadeAngleTab3(&shade
int32 Renderer::projectPositionOnScreen(int32 cX, int32 cY, int32 cZ) {
if (isUsingOrhoProjection) {
- projPosX = ((cX - cZ) * 24) / 512 + orthoProjX;
- projPosY = (((cX + cZ) * 12) - cY * 30) / 512 + orthoProjY;
+ projPosX = ((cX - cZ) * 24) / BRICK_SIZE + orthoProjX;
+ projPosY = (((cX + cZ) * 12) - cY * 30) / BRICK_SIZE + orthoProjY;
projPosZ = cZ - cY - cX;
return 1;
}
@@ -1253,8 +1253,8 @@ bool Renderer::renderAnimatedModel(ModelData *modelData, const uint8 *bodyPtr, R
const int32 coY = pointPtr->y + renderY;
const int32 coZ = -(pointPtr->z + renderZ);
- pointPtrDest->x = (coX + coZ) * 24 / 512 + orthoProjX;
- pointPtrDest->y = (((coX - coZ) * 12) - coY * 30) / 512 + orthoProjY;
+ pointPtrDest->x = (coX + coZ) * 24 / BRICK_SIZE + orthoProjX;
+ pointPtrDest->y = (((coX - coZ) * 12) - coY * 30) / BRICK_SIZE + orthoProjY;
pointPtrDest->z = coZ - coX - coY;
if (pointPtrDest->x < _engine->_redraw->renderRect.left) {
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index eeeadb975a..f50cc8ccd4 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -757,7 +757,7 @@ void Animations::processActorAnimations(int32 actorIdx) { // DoAnim
_engine->_renderer->destZ += _engine->_movements->processActorZ;
if (_engine->_renderer->destX >= 0 && _engine->_renderer->destZ >= 0 && _engine->_renderer->destX <= 0x7E00 && _engine->_renderer->destZ <= 0x7E00) {
- if (_engine->_grid->getBrickShape(_engine->_renderer->destX, _engine->_movements->processActorY + 256, _engine->_renderer->destZ) != ShapeType::kNone && _engine->cfgfile.WallCollision) { // avoid wall hit damage
+ if (_engine->_grid->getBrickShape(_engine->_renderer->destX, _engine->_movements->processActorY + BRICK_HEIGHT, _engine->_renderer->destZ) != ShapeType::kNone && _engine->cfgfile.WallCollision) { // avoid wall hit damage
_engine->_extra->addExtraSpecial(actor->x, actor->y + 1000, actor->z, ExtraSpecialType::kHitStars);
initAnim(AnimationTypes::kBigHit, 2, AnimationTypes::kStanding, currentlyProcessedActorIdx);
diff --git a/engines/twine/scene/collision.cpp b/engines/twine/scene/collision.cpp
index 378e8adc99..2b6abcc867 100644
--- a/engines/twine/scene/collision.cpp
+++ b/engines/twine/scene/collision.cpp
@@ -186,16 +186,16 @@ void Collision::reajustActorPosition(ShapeType brickShape) {
if (brickShape >= ShapeType::kStairsTopLeft && brickShape <= ShapeType::kStairsBottomRight) {
switch (brickShape) {
case ShapeType::kStairsTopLeft:
- _engine->_movements->processActorY = brkY + getAverageValue(0, 256, 512, _engine->_movements->processActorX - brkX);
+ _engine->_movements->processActorY = brkY + getAverageValue(0, BRICK_HEIGHT, BRICK_SIZE, _engine->_movements->processActorX - brkX);
break;
case ShapeType::kStairsTopRight:
- _engine->_movements->processActorY = brkY + getAverageValue(0, 256, 512, _engine->_movements->processActorZ - brkZ);
+ _engine->_movements->processActorY = brkY + getAverageValue(0, BRICK_HEIGHT, BRICK_SIZE, _engine->_movements->processActorZ - brkZ);
break;
case ShapeType::kStairsBottomLeft:
- _engine->_movements->processActorY = brkY + getAverageValue(256, 0, 512, _engine->_movements->processActorZ - brkZ);
+ _engine->_movements->processActorY = brkY + getAverageValue(BRICK_HEIGHT, 0, BRICK_SIZE, _engine->_movements->processActorZ - brkZ);
break;
case ShapeType::kStairsBottomRight:
- _engine->_movements->processActorY = brkY + getAverageValue(256, 0, 512, _engine->_movements->processActorX - brkX);
+ _engine->_movements->processActorY = brkY + getAverageValue(BRICK_HEIGHT, 0, BRICK_SIZE, _engine->_movements->processActorX - brkX);
break;
default:
break;
@@ -450,7 +450,7 @@ void Collision::stopFalling() { // ReceptionObj()
if (IS_HERO(_engine->_animations->currentlyProcessedActorIdx)) {
const int32 fall = _engine->_scene->heroYBeforeFall - _engine->_movements->processActorY;
- if (fall >= 2048) {
+ if (fall >= BRICK_HEIGHT * 8) {
_engine->_extra->addExtraSpecial(_engine->_actor->processActorPtr->x, _engine->_actor->processActorPtr->y + 1000, _engine->_actor->processActorPtr->z, ExtraSpecialType::kHitStars);
_engine->_actor->processActorPtr->life--;
_engine->_animations->initAnim(AnimationTypes::kLandingHit, 2, AnimationTypes::kStanding, _engine->_animations->currentlyProcessedActorIdx);
diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h
index 9a6f12c655..c5d2b66d5d 100644
--- a/engines/twine/scene/grid.h
+++ b/engines/twine/scene/grid.h
@@ -178,6 +178,9 @@ private:
int32 blockBufferSize = 0;
uint8 *blockBuffer = nullptr;
+ uint8 *getBlockBuffer(int32 x, int32 y, int32 z);
+
+ void updateCollisionCoordinates(int32 x, int32 y, int32 z);
public:
Grid(TwinEEngine *engine);
~Grid();
@@ -185,14 +188,11 @@ public:
/** Grid block entry types */
typedef struct BlockEntry blockMap[GRID_SIZE_X][GRID_SIZE_Z][GRID_SIZE_Y];
- uint8 *getBlockBuffer(int32 x, int32 y, int32 z);
/**
* search down until either ground is found or lower border of the cube is reached
*/
const uint8 *getBlockBufferGround(int32 x, int32 y, int32 z, int16 &ground) const;
- void updateCollisionCoordinates(int32 x, int32 y, int32 z);
-
/** New grid camera X coordinates */
int32 newCameraX = 0;
/** New grid camera Y coordinates */
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index 934a5e29d4..f015a87c7c 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -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 / 512;
- engine->_grid->newCameraY = followedActor->y / 256;
- engine->_grid->newCameraZ = followedActor->z / 512;
+ engine->_grid->newCameraX = followedActor->x / BRICK_SIZE;
+ engine->_grid->newCameraY = followedActor->y / BRICK_HEIGHT;
+ engine->_grid->newCameraZ = followedActor->z / BRICK_SIZE;
engine->_scene->currentlyFollowedActor = followedActorIdx;
engine->_redraw->reqBgRedraw = true;
Commit: 968d3b1ba28af1553a7c662f1cde49bb464625d8
https://github.com/scummvm/scummvm/commit/968d3b1ba28af1553a7c662f1cde49bb464625d8
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: prepare to extract magic numbers to constants
Changed paths:
engines/twine/renderer/renderer.cpp
engines/twine/scene/grid.cpp
engines/twine/scene/movements.cpp
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 7bf8d4fdb2..25dd7b2269 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -100,9 +100,9 @@ void Renderer::setOrthoProjection(int32 x, int32 y, int32 z) {
}
void Renderer::getBaseRotationPosition(int32 x, int32 y, int32 z) {
- destX = (baseMatrix.row1[0] * x + baseMatrix.row1[1] * y + baseMatrix.row1[2] * z) >> 14;
- destY = (baseMatrix.row2[0] * x + baseMatrix.row2[1] * y + baseMatrix.row2[2] * z) >> 14;
- destZ = (baseMatrix.row3[0] * x + baseMatrix.row3[1] * y + baseMatrix.row3[2] * z) >> 14;
+ destX = (baseMatrix.row1[0] * x + baseMatrix.row1[1] * y + baseMatrix.row1[2] * z) / 16384;
+ destY = (baseMatrix.row2[0] * x + baseMatrix.row2[1] * y + baseMatrix.row2[2] * z) / 16384;
+ destZ = (baseMatrix.row3[0] * x + baseMatrix.row3[1] * y + baseMatrix.row3[2] * z) / 16384;
}
void Renderer::setBaseRotation(int32 x, int32 y, int32 z) {
@@ -136,9 +136,9 @@ void Renderer::setBaseRotation(int32 x, int32 y, int32 z) {
}
void Renderer::getCameraAnglePositions(int32 x, int32 y, int32 z) {
- destX = (baseMatrix.row1[0] * x + baseMatrix.row2[0] * y + baseMatrix.row3[0] * z) >> 14;
- destY = (baseMatrix.row1[1] * x + baseMatrix.row2[1] * y + baseMatrix.row3[1] * z) >> 14;
- destZ = (baseMatrix.row1[2] * x + baseMatrix.row2[2] * y + baseMatrix.row3[2] * z) >> 14;
+ destX = (baseMatrix.row1[0] * x + baseMatrix.row2[0] * y + baseMatrix.row3[0] * z) / 16384;
+ destY = (baseMatrix.row1[1] * x + baseMatrix.row2[1] * y + baseMatrix.row3[1] * z) / 16384;
+ destZ = (baseMatrix.row1[2] * x + baseMatrix.row2[2] * y + baseMatrix.row3[2] * z) / 16384;
}
void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ, int32 rotPosX, int32 rotPosY, int32 rotPosZ, int32 param6) {
@@ -171,12 +171,12 @@ void Renderer::applyRotation(Matrix *targetMatrix, const Matrix *currentMatrix)
matrix1.row2[0] = currentMatrix->row2[0];
matrix1.row3[0] = currentMatrix->row3[0];
- matrix1.row1[1] = (currentMatrix->row1[2] * angleVar2 + currentMatrix->row1[1] * angleVar1) >> 14;
- matrix1.row1[2] = (currentMatrix->row1[2] * angleVar1 - currentMatrix->row1[1] * angleVar2) >> 14;
- matrix1.row2[1] = (currentMatrix->row2[2] * angleVar2 + currentMatrix->row2[1] * angleVar1) >> 14;
- matrix1.row2[2] = (currentMatrix->row2[2] * angleVar1 - currentMatrix->row2[1] * angleVar2) >> 14;
- matrix1.row3[1] = (currentMatrix->row3[2] * angleVar2 + currentMatrix->row3[1] * angleVar1) >> 14;
- matrix1.row3[2] = (currentMatrix->row3[2] * angleVar1 - currentMatrix->row3[1] * angleVar2) >> 14;
+ matrix1.row1[1] = (currentMatrix->row1[2] * angleVar2 + currentMatrix->row1[1] * angleVar1) / 16384;
+ matrix1.row1[2] = (currentMatrix->row1[2] * angleVar1 - currentMatrix->row1[1] * angleVar2) / 16384;
+ matrix1.row2[1] = (currentMatrix->row2[2] * angleVar2 + currentMatrix->row2[1] * angleVar1) / 16384;
+ matrix1.row2[2] = (currentMatrix->row2[2] * angleVar1 - currentMatrix->row2[1] * angleVar2) / 16384;
+ matrix1.row3[1] = (currentMatrix->row3[2] * angleVar2 + currentMatrix->row3[1] * angleVar1) / 16384;
+ matrix1.row3[2] = (currentMatrix->row3[2] * angleVar1 - currentMatrix->row3[1] * angleVar2) / 16384;
} else {
matrix1 = *currentMatrix;
}
@@ -191,12 +191,12 @@ void Renderer::applyRotation(Matrix *targetMatrix, const Matrix *currentMatrix)
matrix2.row2[2] = matrix1.row2[2];
matrix2.row3[2] = matrix1.row3[2];
- matrix2.row1[0] = (matrix1.row1[1] * angleVar2 + matrix1.row1[0] * angleVar1) >> 14;
- matrix2.row1[1] = (matrix1.row1[1] * angleVar1 - matrix1.row1[0] * angleVar2) >> 14;
- matrix2.row2[0] = (matrix1.row2[1] * angleVar2 + matrix1.row2[0] * angleVar1) >> 14;
- matrix2.row2[1] = (matrix1.row2[1] * angleVar1 - matrix1.row2[0] * angleVar2) >> 14;
- matrix2.row3[0] = (matrix1.row3[1] * angleVar2 + matrix1.row3[0] * angleVar1) >> 14;
- matrix2.row3[1] = (matrix1.row3[1] * angleVar1 - matrix1.row3[0] * angleVar2) >> 14;
+ matrix2.row1[0] = (matrix1.row1[1] * angleVar2 + matrix1.row1[0] * angleVar1) / 16384;
+ matrix2.row1[1] = (matrix1.row1[1] * angleVar1 - matrix1.row1[0] * angleVar2) / 16384;
+ matrix2.row2[0] = (matrix1.row2[1] * angleVar2 + matrix1.row2[0] * angleVar1) / 16384;
+ matrix2.row2[1] = (matrix1.row2[1] * angleVar1 - matrix1.row2[0] * angleVar2) / 16384;
+ matrix2.row3[0] = (matrix1.row3[1] * angleVar2 + matrix1.row3[0] * angleVar1) / 16384;
+ matrix2.row3[1] = (matrix1.row3[1] * angleVar1 - matrix1.row3[0] * angleVar2) / 16384;
} else {
matrix2 = matrix1;
}
@@ -211,13 +211,13 @@ void Renderer::applyRotation(Matrix *targetMatrix, const Matrix *currentMatrix)
targetMatrix->row2[1] = matrix2.row2[1];
targetMatrix->row3[1] = matrix2.row3[1];
- targetMatrix->row1[0] = (matrix2.row1[0] * angleVar1 - matrix2.row1[2] * angleVar2) >> 14;
- targetMatrix->row1[2] = (matrix2.row1[0] * angleVar2 + matrix2.row1[2] * angleVar1) >> 14;
- targetMatrix->row2[0] = (matrix2.row2[0] * angleVar1 - matrix2.row2[2] * angleVar2) >> 14;
- targetMatrix->row2[2] = (matrix2.row2[0] * angleVar2 + matrix2.row2[2] * angleVar1) >> 14;
+ targetMatrix->row1[0] = (matrix2.row1[0] * angleVar1 - matrix2.row1[2] * angleVar2) / 16384;
+ targetMatrix->row1[2] = (matrix2.row1[0] * angleVar2 + matrix2.row1[2] * angleVar1) / 16384;
+ targetMatrix->row2[0] = (matrix2.row2[0] * angleVar1 - matrix2.row2[2] * angleVar2) / 16384;
+ targetMatrix->row2[2] = (matrix2.row2[0] * angleVar2 + matrix2.row2[2] * angleVar1) / 16384;
- targetMatrix->row3[0] = (matrix2.row3[0] * angleVar1 - matrix2.row3[2] * angleVar2) >> 14;
- targetMatrix->row3[2] = (matrix2.row3[0] * angleVar2 + matrix2.row3[2] * angleVar1) >> 14;
+ targetMatrix->row3[0] = (matrix2.row3[0] * angleVar1 - matrix2.row3[2] * angleVar2) / 16384;
+ targetMatrix->row3[2] = (matrix2.row3[0] * angleVar2 + matrix2.row3[2] * angleVar1) / 16384;
} else {
*targetMatrix = matrix2;
}
@@ -231,9 +231,9 @@ void Renderer::applyPointsRotation(const pointTab *pointsPtr, int32 numPoints, p
const int32 tmpY = pointsPtr->y;
const int32 tmpZ = pointsPtr->z;
- destPoints->x = ((rotationMatrix->row1[0] * tmpX + rotationMatrix->row1[1] * tmpY + rotationMatrix->row1[2] * tmpZ) >> 14) + destX;
- destPoints->y = ((rotationMatrix->row2[0] * tmpX + rotationMatrix->row2[1] * tmpY + rotationMatrix->row2[2] * tmpZ) >> 14) + destY;
- destPoints->z = ((rotationMatrix->row3[0] * tmpX + rotationMatrix->row3[1] * tmpY + rotationMatrix->row3[2] * tmpZ) >> 14) + destZ;
+ destPoints->x = ((rotationMatrix->row1[0] * tmpX + rotationMatrix->row1[1] * tmpY + rotationMatrix->row1[2] * tmpZ) / 16384) + destX;
+ destPoints->y = ((rotationMatrix->row2[0] * tmpX + rotationMatrix->row2[1] * tmpY + rotationMatrix->row2[2] * tmpZ) / 16384) + destY;
+ destPoints->z = ((rotationMatrix->row3[0] * tmpX + rotationMatrix->row3[1] * tmpY + rotationMatrix->row3[2] * tmpZ) / 16384) + destZ;
destPoints++;
pointsPtr++;
@@ -284,9 +284,9 @@ void Renderer::applyPointsTranslation(const pointTab *pointsPtr, int32 numPoints
const int32 tmpY = pointsPtr->y + renderAngleY;
const int32 tmpZ = pointsPtr->z + renderAngleX;
- destPoints->x = ((translationMatrix->row1[0] * tmpX + translationMatrix->row1[1] * tmpY + translationMatrix->row1[2] * tmpZ) >> 14) + destX;
- destPoints->y = ((translationMatrix->row2[0] * tmpX + translationMatrix->row2[1] * tmpY + translationMatrix->row2[2] * tmpZ) >> 14) + destY;
- destPoints->z = ((translationMatrix->row3[0] * tmpX + translationMatrix->row3[1] * tmpY + translationMatrix->row3[2] * tmpZ) >> 14) + destZ;
+ destPoints->x = ((translationMatrix->row1[0] * tmpX + translationMatrix->row1[1] * tmpY + translationMatrix->row1[2] * tmpZ) / 16384) + destX;
+ destPoints->y = ((translationMatrix->row2[0] * tmpX + translationMatrix->row2[1] * tmpY + translationMatrix->row2[2] * tmpZ) / 16384) + destY;
+ destPoints->z = ((translationMatrix->row3[0] * tmpX + translationMatrix->row3[1] * tmpY + translationMatrix->row3[2] * tmpZ) / 16384) + destZ;
destPoints++;
pointsPtr++;
@@ -331,7 +331,7 @@ void Renderer::translateGroup(int16 ax, int16 bx, int16 cx) {
eax = shadeMatrix.row1[2];
eax *= ecx;
eax += edi;
- eax >>= 14;
+ eax /= 16384;
destX = eax;
@@ -343,7 +343,7 @@ void Renderer::translateGroup(int16 ax, int16 bx, int16 cx) {
eax = shadeMatrix.row2[2];
eax *= ecx;
eax += edi;
- eax >>= 14;
+ eax /= 16384;
destY = eax;
destZ = eax;
}
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index b3385cf433..9a24176813 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -152,7 +152,7 @@ void Grid::drawOverModelActor(int32 x, int32 y, int32 z) {
for (int32 j = copyBlockPhysLeft; j <= copyBlockPhysRight; j++) {
for (int32 i = 0; i < brickInfoBuffer[j]; i++) {
- BrickEntry *currBrickEntry = &bricksDataBuffer[j][i];
+ const BrickEntry *currBrickEntry = &bricksDataBuffer[j][i];
if (currBrickEntry->posY + 38 > _engine->_interface->textWindow.top && currBrickEntry->posY <= _engine->_interface->textWindow.bottom && currBrickEntry->y >= y) {
if (currBrickEntry->x + currBrickEntry->z > z + x) {
diff --git a/engines/twine/scene/movements.cpp b/engines/twine/scene/movements.cpp
index 9cdeded142..03a0d20099 100644
--- a/engines/twine/scene/movements.cpp
+++ b/engines/twine/scene/movements.cpp
@@ -112,7 +112,7 @@ int32 Movements::getAngleAndSetTargetActorDistance(int32 x1, int32 z1, int32 x2,
return 0;
}
- const int32 destAngle = (difZ << 14) / targetActorDistance;
+ const int32 destAngle = (difZ * 16384) / targetActorDistance;
int32 startAngle = ANGLE_0;
// stopAngle = 0x100;
Commit: 5f2383e3c416146234d0a6d6606ba039a70ba24f
https://github.com/scummvm/scummvm/commit/5f2383e3c416146234d0a6d6606ba039a70ba24f
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2020-12-26T11:53:26+01:00
Commit Message:
TWINE: fixed rendering errors for brick sprites
https://bugs.scummvm.org/ticket/12024
Changed paths:
engines/twine/renderer/redraw.cpp
engines/twine/resources/resources.h
engines/twine/scene/grid.cpp
diff --git a/engines/twine/renderer/redraw.cpp b/engines/twine/renderer/redraw.cpp
index 473c191e9a..0b18086dae 100644
--- a/engines/twine/renderer/redraw.cpp
+++ b/engines/twine/renderer/redraw.cpp
@@ -415,13 +415,15 @@ void Redraw::processDrawListActors(const DrawListStruct &drawCmd, bool bgRedraw)
void Redraw::processDrawListActorSprites(const DrawListStruct &drawCmd, bool bgRedraw) {
int32 actorIdx = drawCmd.actorIdx;
ActorStruct *actor = _engine->_scene->getActor(actorIdx);
- const SpriteData &spritePtr = _engine->_resources->spriteData[actor->entity];
+ const SpriteData &spriteData = _engine->_resources->spriteData[actor->entity];
+ // TODO: using the raw pointer and not the SpriteData surface here is a workaround for issue https://bugs.scummvm.org/ticket/12024
+ const uint8 *spritePtr = _engine->_resources->spriteTable[actor->entity];
// get actor position on screen
_engine->_renderer->projectPositionOnScreen(actor->x - _engine->_grid->cameraX, actor->y - _engine->_grid->cameraY, actor->z - _engine->_grid->cameraZ);
- const int32 spriteWidth = spritePtr.surface().w;
- const int32 spriteHeight = spritePtr.surface().h;
+ const int32 spriteWidth = spriteData.surface().w;
+ const int32 spriteHeight = spriteData.surface().h;
// calculate sprite position on screen
const SpriteDim *dim = _engine->_resources->spriteBoundingBox.dim(actor->entity);
@@ -438,7 +440,7 @@ void Redraw::processDrawListActorSprites(const DrawListStruct &drawCmd, bool bgR
}
if (_engine->_interface->textWindow.left <= _engine->_interface->textWindow.right && _engine->_interface->textWindow.top <= _engine->_interface->textWindow.bottom) {
- _engine->_grid->drawSprite(renderRect.left, renderRect.top, spritePtr);
+ _engine->_grid->drawSprite(0, renderRect.left, renderRect.top, spritePtr);
actor->dynamicFlags.bIsVisible = 1;
diff --git a/engines/twine/resources/resources.h b/engines/twine/resources/resources.h
index dca46e0342..3eb1441be1 100644
--- a/engines/twine/resources/resources.h
+++ b/engines/twine/resources/resources.h
@@ -142,11 +142,6 @@ private:
void preloadAnimations();
void preloadSamples();
- /** Table with all loaded sprites */
- uint8 *spriteTable[NUM_SPRITES] {nullptr};
- /** Table with all loaded sprite sizes */
- uint32 spriteSizeTable[NUM_SPRITES] {0};
-
public:
Resources(TwinEEngine *engine) : _engine(engine) {}
~Resources();
@@ -156,6 +151,10 @@ public:
/** Table with all loaded samples sizes */
uint32 inventorySizeTable[NUM_INVENTORY_ITEMS] {0};
+ /** Table with all loaded sprites */
+ uint8 *spriteTable[NUM_SPRITES] {nullptr};
+ /** Table with all loaded sprite sizes */
+ uint32 spriteSizeTable[NUM_SPRITES] {0};
SpriteData spriteData[NUM_SPRITES];
/** Table with all loaded animations */
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index 9a24176813..468a460da9 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -492,7 +492,7 @@ void Grid::drawSprite(int32 posX, int32 posY, const SpriteData &ptr) {
return;
}
- _engine->frontVideoBuffer.transBlitFrom(ptr.surface(), Common::Point(left, top));
+ _engine->frontVideoBuffer.transBlitFrom(ptr.surface(), Common::Point(left, top), 0);
}
// WARNING: Rewrite this function to have better performance
More information about the Scummvm-git-logs
mailing list