[Scummvm-git-logs] scummvm master -> a7025f0365075cffbeccf482c5f7545c3aa19391
mgerhardy
martin.gerhardy at gmail.com
Wed Aug 11 19:36:14 UTC 2021
This automated email contains information about 7 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
32fa7e9eaa TWINE: return values for some renderer functions
4e862a6142 TWINE: use the returned values and not the member vars
12a432ef7c TWINE: use the returned values
2f7e9f0cf5 TWINE: added blocklibrary parser
598c35ca52 TWINE: removed unused member
e7fc25303b TWINE: updated the bll raw buffer handling
a7025f0365 TWINE: use the block library parser
Commit: 32fa7e9eaa96ae7c5503414731cea669a5515749
https://github.com/scummvm/scummvm/commit/32fa7e9eaa96ae7c5503414731cea669a5515749
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-11T20:45:10+02:00
Commit Message:
TWINE: return values for some renderer functions
Changed paths:
engines/twine/renderer/renderer.cpp
engines/twine/renderer/renderer.h
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index c47b394c98..b54aa30e81 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -65,11 +65,11 @@ void Renderer::init(int32 w, int32 h) {
_holomap_polytab_1_3_ptr = _holomap_polytab_1_3;
}
-void Renderer::projectXYPositionOnScreen(int32 x, int32 y, int32 z) {
+const IVec3 &Renderer::projectXYPositionOnScreen(int32 x, int32 y, int32 z) {
if (_isUsingOrthoProjection == 1) {
_projPos.x = ((x - z) * 24) / BRICK_SIZE + _orthoProjPos.x;
_projPos.y = y;
- return;
+ return _projPos;
}
int32 cz = _baseRotPos.z - z;
if (-1 < cz) {
@@ -80,10 +80,11 @@ void Renderer::projectXYPositionOnScreen(int32 x, int32 y, int32 z) {
}
_projPos.x = (xdelta * _cameraScaleY) / posZ + _orthoProjPos.x;
_projPos.y = y - _baseRotPos.y;
- return;
+ return _projPos;
}
_projPos.x = 0;
_projPos.y = 0;
+ return _projPos;
}
IVec3 &Renderer::projectPositionOnScreen(int32 cX, int32 cY, int32 cZ) {
@@ -178,22 +179,25 @@ void Renderer::setBaseRotation(int32 x, int32 y, int32 z, bool transpose) {
_baseRotPos = _destPos;
}
-void Renderer::getBaseRotationPosition(int32 x, int32 y, int32 z) {
+const IVec3 &Renderer::getBaseRotationPosition(int32 x, int32 y, int32 z) {
_destPos.x = (_baseMatrix.row1.x * x + _baseMatrix.row1.y * y + _baseMatrix.row1.z * z) / SCENE_SIZE_HALF;
_destPos.y = (_baseMatrix.row2.x * x + _baseMatrix.row2.y * y + _baseMatrix.row2.z * z) / SCENE_SIZE_HALF;
_destPos.z = (_baseMatrix.row3.x * x + _baseMatrix.row3.y * y + _baseMatrix.row3.z * z) / SCENE_SIZE_HALF;
+ return _destPos;
}
-void Renderer::getCameraAnglePositions(int32 x, int32 y, int32 z) {
+const IVec3 &Renderer::getCameraAnglePositions(int32 x, int32 y, int32 z) {
_destPos.x = (_baseMatrix.row1.x * x + _baseMatrix.row2.x * y + _baseMatrix.row3.x * z) / SCENE_SIZE_HALF;
_destPos.y = (_baseMatrix.row1.y * x + _baseMatrix.row2.y * y + _baseMatrix.row3.y * z) / SCENE_SIZE_HALF;
_destPos.z = (_baseMatrix.row1.z * x + _baseMatrix.row2.z * y + _baseMatrix.row3.z * z) / SCENE_SIZE_HALF;
+ return _destPos;
}
-void Renderer::translateGroup(int32 x, int32 y, int32 z) {
+const IVec3 &Renderer::translateGroup(int32 x, int32 y, int32 z) {
_destPos.x = (_shadeMatrix.row1.x * x + _shadeMatrix.row1.y * y + _shadeMatrix.row1.z * z) / SCENE_SIZE_HALF;
_destPos.y = (_shadeMatrix.row2.x * x + _shadeMatrix.row2.y * y + _shadeMatrix.row2.z * z) / SCENE_SIZE_HALF;
_destPos.z = _destPos.y;
+ return _destPos;
}
void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ, int32 rotPosX, int32 rotPosY, int32 rotPosZ, int32 param6) {
@@ -210,8 +214,8 @@ void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ,
_baseTransPos = _destPos;
}
-void Renderer::updateCameraAnglePositions(int zShift) {
- getCameraAnglePositions(_baseRotPos.x, _baseRotPos.y, _baseRotPos.z + zShift);
+const IVec3 &Renderer::updateCameraAnglePositions(int zShift) {
+ return getCameraAnglePositions(_baseRotPos.x, _baseRotPos.y, _baseRotPos.z + zShift);
}
IVec3 Renderer::getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const {
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index 174360e673..a3416a114e 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -138,16 +138,16 @@ private:
bool renderAnimatedModel(ModelData *modelData, const BodyData &bodyData, RenderCommand *renderCmds, const IVec3 &angleVec, const IVec3 &renderPos, Common::Rect &modelRect);
void circleFill(int32 x, int32 y, int32 radius, uint8 color);
bool renderModelElements(int32 numOfPrimitives, const BodyData &bodyData, RenderCommand **renderCmds, ModelData *modelData, Common::Rect &modelRect);
- void getCameraAnglePositions(int32 x, int32 y, int32 z);
- inline void getCameraAnglePositions(const IVec3 &vec) {
- getCameraAnglePositions(vec.x, vec.y, vec.z);
+ const IVec3 &getCameraAnglePositions(int32 x, int32 y, int32 z);
+ inline const IVec3 &getCameraAnglePositions(const IVec3 &vec) {
+ return getCameraAnglePositions(vec.x, vec.y, vec.z);
}
void applyRotation(IMatrix3x3 *targetMatrix, const IMatrix3x3 *currentMatrix, const IVec3 &angleVec);
void applyPointsRotation(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *rotationMatrix);
void processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
void applyPointsTranslation(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec);
void processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
- void translateGroup(int32 x, int32 y, int32 z);
+ const IVec3 &translateGroup(int32 x, int32 y, int32 z);
IVec3 _baseTransPos;
IVec3 _orthoProjPos;
@@ -219,10 +219,10 @@ public:
IVec3 getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const;
void setLightVector(int32 angleX, int32 angleY, int32 angleZ);
- void getBaseRotationPosition(int32 x, int32 y, int32 z);
+ const IVec3 &getBaseRotationPosition(int32 x, int32 y, int32 z);
- inline void getBaseRotationPosition(const IVec3& vec) {
- getBaseRotationPosition(vec.x, vec.y, vec.z);
+ inline const IVec3 &getBaseRotationPosition(const IVec3& vec) {
+ return getBaseRotationPosition(vec.x, vec.y, vec.z);
}
void renderPolygons(const CmdRenderPolygon &polygon, Vertex *vertices, int vtop, int vbottom);
@@ -233,13 +233,13 @@ public:
IVec3 &projectPositionOnScreen(int32 cX, int32 cY, int32 cZ);
- inline void projectXYPositionOnScreen(const IVec3& pos) {
- projectXYPositionOnScreen(pos.x, pos.y, pos.z);
+ inline const IVec3 &projectXYPositionOnScreen(const IVec3& pos) {
+ return projectXYPositionOnScreen(pos.x, pos.y, pos.z);
}
- void projectXYPositionOnScreen(int32 x,int32 y,int32 z);
+ const IVec3 &projectXYPositionOnScreen(int32 x,int32 y,int32 z);
void setCameraPosition(int32 x, int32 y, int32 depthOffset, int32 scaleY, int32 scaleZ);
void setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ, int32 rotPosX, int32 rotPosY, int32 rotPosZ, int32 param6);
- void updateCameraAnglePositions(int zShift = 0);
+ const IVec3 &updateCameraAnglePositions(int zShift = 0);
void setBaseTranslation(int32 x, int32 y, int32 z);
void setBaseRotation(int32 x, int32 y, int32 z, bool transpose = false);
Commit: 4e862a614297fad2c46fe33ddc5b96abb1fe8dec
https://github.com/scummvm/scummvm/commit/4e862a614297fad2c46fe33ddc5b96abb1fe8dec
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-11T20:45:10+02:00
Commit Message:
TWINE: use the returned values and not the member vars
Changed paths:
engines/twine/holomap.cpp
diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 838dbd3d8a..2eb92a5ad5 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -432,26 +432,26 @@ void Holomap::renderLocations(int xRot, int yRot, int zRot, bool lower) {
if ((_engine->_gameState->_holomapFlags[locationIdx] & HOLOMAP_CAN_FOCUS) || locationIdx == _engine->_scene->_currentSceneIdx) {
const Location &loc = _locations[locationIdx];
_engine->_renderer->setBaseRotation(loc.angle.x, loc.angle.y, 0);
- _engine->_renderer->getBaseRotationPosition(0, 0, loc.angle.z + 1000);
- int32 xpos1 = _engine->_renderer->_destPos.x;
- int32 ypos1 = _engine->_renderer->_destPos.y;
- int32 zpos1 = _engine->_renderer->_destPos.z;
- _engine->_renderer->getBaseRotationPosition(0, 0, 1500);
- int32 xpos2 = _engine->_renderer->_destPos.x;
- int32 ypos2 = _engine->_renderer->_destPos.y;
- int32 zpos2 = _engine->_renderer->_destPos.z;
+ const IVec3 &destPos = _engine->_renderer->getBaseRotationPosition(0, 0, loc.angle.z + 1000);
+ int32 xpos1 = destPos.x;
+ int32 ypos1 = destPos.y;
+ int32 zpos1 = destPos.z;
+ const IVec3 &destPos2 = _engine->_renderer->getBaseRotationPosition(0, 0, 1500);
+ int32 xpos2 = destPos2.x;
+ int32 ypos2 = destPos2.y;
+ int32 zpos2 = destPos2.z;
_engine->_renderer->setBaseRotation(xRot, yRot, zRot, true);
int32 zpos1_copy = zpos1;
_engine->_renderer->setBaseRotationPos(0, 0, 9500);
- _engine->_renderer->getBaseRotationPosition(xpos1, ypos1, zpos1);
- int32 zpos1_copy2 = _engine->_renderer->_destPos.z;
- _engine->_renderer->getBaseRotationPosition(xpos2, ypos2, zpos2);
+ const IVec3 &destPos3 = _engine->_renderer->getBaseRotationPosition(xpos1, ypos1, zpos1);
+ int32 zpos1_copy2 = destPos3.z;
+ const IVec3 &destPos4 = _engine->_renderer->getBaseRotationPosition(xpos2, ypos2, zpos2);
if (lower) {
- if (zpos1_copy2 > _engine->_renderer->_destPos.z) {
+ if (zpos1_copy2 > destPos4.z) {
continue;
}
} else {
- if (_engine->_renderer->_destPos.z > zpos1_copy2) {
+ if (destPos4.z > zpos1_copy2) {
continue;
}
}
@@ -482,8 +482,8 @@ void Holomap::renderLocations(int xRot, int yRot, int zRot, bool lower) {
bodyData = &_engine->_resources->_holomapTwinsenArrowPtr;
}
if (bodyData != nullptr) {
- int32 angleX = _locations[drawList.actorIdx].angle.x;
- int32 angleY = _locations[drawList.actorIdx].angle.y;
+ const int32 angleX = _locations[drawList.actorIdx].angle.x;
+ const int32 angleY = _locations[drawList.actorIdx].angle.y;
Common::Rect dummy;
_engine->_renderer->renderIsoModel(drawList.x, drawList.y, drawList.z, angleX, angleY, ANGLE_0, *bodyData, dummy);
}
Commit: 12a432ef7c92ecb814b2fc20e6055ed3e119abc5
https://github.com/scummvm/scummvm/commit/12a432ef7c92ecb814b2fc20e6055ed3e119abc5
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-11T20:45:10+02:00
Commit Message:
TWINE: use the returned values
Changed paths:
engines/twine/holomap.cpp
engines/twine/renderer/renderer.cpp
diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 2eb92a5ad5..dcc82bcc3c 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -182,23 +182,23 @@ void Holomap::prepareHolomapPolygons() {
int rotation = 0;
for (int32 stepWidth = 0; stepWidth < ANGLE_11_25; ++stepWidth) {
IVec3* vec = &_holomapSurface[holomapSurfaceArrayIdx++];
- _engine->_renderer->getBaseRotationPosition(vec->x, vec->y, vec->z);
+ const IVec3 &destPos = _engine->_renderer->getBaseRotationPosition(vec->x, vec->y, vec->z);
if (angle != ANGLE_90) {
- _holomapSort[holomapSortArrayIdx].z = _engine->_renderer->_destPos.z;
+ _holomapSort[holomapSortArrayIdx].z = destPos.z;
_holomapSort[holomapSortArrayIdx].projectedPosIdx = _projectedSurfaceIndex;
++holomapSortArrayIdx;
}
- _engine->_renderer->projectXYPositionOnScreen(_engine->_renderer->_destPos);
- _projectedSurfacePositions[_projectedSurfaceIndex].x1 = _engine->_renderer->_projPos.x;
- _projectedSurfacePositions[_projectedSurfaceIndex].y1 = _engine->_renderer->_projPos.y;
+ const IVec3 &projPos = _engine->_renderer->projectXYPositionOnScreen(destPos);
+ _projectedSurfacePositions[_projectedSurfaceIndex].x1 = projPos.x;
+ _projectedSurfacePositions[_projectedSurfaceIndex].y1 = projPos.y;
rotation += ANGLE_11_25;
++_projectedSurfaceIndex;
}
IVec3* vec = &_holomapSurface[holomapSurfaceArrayIdx++];
- _engine->_renderer->getBaseRotationPosition(vec->x, vec->y, vec->z);
- _engine->_renderer->projectXYPositionOnScreen(_engine->_renderer->_destPos);
- _projectedSurfacePositions[_projectedSurfaceIndex].x1 = _engine->_renderer->_projPos.x;
- _projectedSurfacePositions[_projectedSurfaceIndex].y1 = _engine->_renderer->_projPos.y;
+ const IVec3 &destPos = _engine->_renderer->getBaseRotationPosition(vec->x, vec->y, vec->z);
+ const IVec3 &projPos = _engine->_renderer->projectXYPositionOnScreen(destPos);
+ _projectedSurfacePositions[_projectedSurfaceIndex].x1 = projPos.x;
+ _projectedSurfacePositions[_projectedSurfaceIndex].y1 = projPos.y;
rotation += ANGLE_11_25;
++_projectedSurfaceIndex;
}
@@ -272,12 +272,13 @@ void Holomap::drawHolomapText(int32 centerx, int32 top, const char *title) {
void Holomap::renderHolomapPointModel(const IVec3 &angle, int32 x, int32 y) {
_engine->_renderer->setBaseRotation(x, y, 0);
- _engine->_renderer->getBaseRotationPosition(0, 0, 1000);
- const IVec3 destPos = _engine->_renderer->_destPos;
+ // we need a copy here
+ const IVec3 destPos = _engine->_renderer->getBaseRotationPosition(0, 0, 1000);
_engine->_renderer->setBaseTranslation(0, 0, 0);
_engine->_renderer->setBaseRotation(angle);
_engine->_renderer->updateCameraAnglePositions(5300);
// why is this needed? _engine->_renderer->_baseTransPos = _engine->_renderer->_destPos;
+ // TODO: shouldn't the new destpos be used for the model rendering
_engine->_renderer->getBaseRotationPosition(destPos);
_engine->_interface->resetClip();
Common::Rect dummy;
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index b54aa30e81..2c86f3a03c 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -209,9 +209,7 @@ void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ,
_baseRotPos.z += param6;
- updateCameraAnglePositions();
-
- _baseTransPos = _destPos;
+ _baseTransPos = updateCameraAnglePositions();
}
const IVec3 &Renderer::updateCameraAnglePositions(int zShift) {
@@ -1450,9 +1448,7 @@ bool Renderer::renderIsoModel(int32 x, int32 y, int32 z, int32 angleX, int32 ang
renderPos.y = y;
renderPos.z = z;
} else {
- getBaseRotationPosition(x, y, z);
-
- renderPos = _destPos - _baseRotPos;
+ renderPos = getBaseRotationPosition(x, y, z) - _baseRotPos;
}
if (!bodyData.isAnimated()) {
Commit: 2f7e9f0cf573f51896a0c566be4e07b6d25d2409
https://github.com/scummvm/scummvm/commit/2f7e9f0cf573f51896a0c566be4e07b6d25d2409
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-11T21:35:20+02:00
Commit Message:
TWINE: added blocklibrary parser
Changed paths:
A engines/twine/parser/blocklibrary.cpp
A engines/twine/parser/blocklibrary.h
engines/twine/module.mk
diff --git a/engines/twine/module.mk b/engines/twine/module.mk
index 22fd6c2bc8..80c1bff917 100644
--- a/engines/twine/module.mk
+++ b/engines/twine/module.mk
@@ -14,6 +14,7 @@ MODULE_OBJS := \
menu/menuoptions.o \
\
parser/anim.o \
+ parser/blocklibrary.o \
parser/body.o \
parser/brick.o \
parser/entity.o \
diff --git a/engines/twine/parser/blocklibrary.cpp b/engines/twine/parser/blocklibrary.cpp
new file mode 100644
index 0000000000..17bc705b3e
--- /dev/null
+++ b/engines/twine/parser/blocklibrary.cpp
@@ -0,0 +1,70 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "twine/parser/blocklibrary.h"
+#include "common/stream.h"
+
+namespace TwinE {
+
+bool BlockLibraryData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
+ const uint32 numLayouts = stream.readUint32LE() / 4;
+ _layouts.resize(numLayouts);
+ stream.seek(0);
+ for (uint32 i = 0; i < numLayouts; ++i) {
+ BlockData &blockData = _layouts[i];
+ const uint32 offset = stream.readUint32LE();
+ const uint32 nextOffset = stream.pos();
+ if (!stream.seek(offset)) {
+ return false;
+ }
+ if (!parseLayout(blockData, stream, lba1)) {
+ return false;
+ }
+ stream.seek(nextOffset);
+ }
+ return !stream.err();
+}
+
+bool BlockLibraryData::parseLayout(BlockData &blockData, Common::SeekableReadStream &stream, bool lba1) {
+ const uint8 x = stream.readByte();
+ const uint8 y = stream.readByte();
+ const uint8 z = stream.readByte();
+ const int32 numBricks = x * y * z;
+ blockData.entries.resize(numBricks);
+ for (int32 i = 0; i < numBricks; ++i) {
+ BlockDataEntry &blockEntry = blockData.entries[i];
+ blockEntry.brickShape = stream.readByte();
+ blockEntry.brickType = stream.readByte();
+ blockEntry.brickIdx = stream.readUint16LE();
+ blockEntry.sound = bits(blockEntry.brickType, 0, 4);
+ }
+ return !stream.err();
+}
+
+const BlockData *BlockLibraryData::getLayout(int index) const {
+ if (index < 0 || index >= (int)_layouts.size()) {
+ error("Block library index out of range: %i", index);
+ }
+ return &_layouts[index];
+}
+
+} // End of namespace TwinE
diff --git a/engines/twine/parser/blocklibrary.h b/engines/twine/parser/blocklibrary.h
new file mode 100644
index 0000000000..ebbf933424
--- /dev/null
+++ b/engines/twine/parser/blocklibrary.h
@@ -0,0 +1,59 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TWINE_PARSER_BLOCKLIBRARY_H
+#define TWINE_PARSER_BLOCKLIBRARY_H
+
+#include "common/array.h"
+#include "common/stream.h"
+#include "twine/parser/parser.h"
+#include "twine/shared.h"
+
+namespace TwinE {
+
+struct BlockDataEntry {
+ uint8 brickShape;
+ uint8 brickType;
+ /**
+ * Index is not starting a 0 - but at 1.
+ */
+ uint16 brickIdx;
+ uint8 sound;
+};
+
+struct BlockData {
+ Common::Array<BlockDataEntry> entries;
+};
+
+class BlockLibraryData : public Parser {
+private:
+ Common::Array<BlockData> _layouts;
+ bool parseLayout(BlockData &blockData, Common::SeekableReadStream &stream, bool lba1);
+
+public:
+ bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
+ const BlockData *getLayout(int index) const;
+};
+
+} // End of namespace TwinE
+
+#endif
Commit: 598c35ca52d9206ddc01a3e7953856db4b8fa111
https://github.com/scummvm/scummvm/commit/598c35ca52d9206ddc01a3e7953856db4b8fa111
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-11T21:35:20+02:00
Commit Message:
TWINE: removed unused member
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 336febd114..637b1fb00a 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -455,8 +455,6 @@ bool Grid::initGrid(int32 index) {
createGridMask();
- _numberOfBll = READ_LE_INT32(_currentBlockLibrary) >> 2;
-
createGridMap();
return true;
diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h
index cf4084703f..1988b3bb7e 100644
--- a/engines/twine/scene/grid.h
+++ b/engines/twine/scene/grid.h
@@ -157,8 +157,6 @@ private:
uint8 *_currentGrid = nullptr;
/** Current block library pointer */
uint8 *_currentBlockLibrary = nullptr;
- /** Number of block libraries */
- int32 _numberOfBll = 0;
/** Brick data buffer */
BrickEntry *_bricksDataBuffer = nullptr;
Commit: e7fc25303b2f3a0bdff6d0701c500bc1ebee5c47
https://github.com/scummvm/scummvm/commit/e7fc25303b2f3a0bdff6d0701c500bc1ebee5c47
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-11T21:35:20+02:00
Commit Message:
TWINE: updated the bll raw buffer handling
Changed paths:
engines/twine/scene/grid.cpp
engines/twine/scene/grid.h
engines/twine/scene/movements.cpp
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index 637b1fb00a..6611410641 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -285,7 +285,7 @@ void Grid::getSpriteSize(int32 offset, int32 *width, int32 *height, const uint8
void Grid::loadGridBricks() {
uint32 firstBrick = 60000;
uint32 lastBrick = 0;
- uint32 currentBllEntryIdx = 0;
+ uint32 currentBllEntryIdx = 1;
memset(_brickSizeTable, 0, sizeof(_brickSizeTable));
memset(_brickUsageTable, 0, sizeof(_brickUsageTable));
@@ -299,8 +299,7 @@ void Grid::loadGridBricks() {
const uint8 currentBitMask = 1 << (7 - (i & 7));
if (currentBitByte & currentBitMask) {
- uint32 currentBllOffset = READ_LE_UINT32(_currentBlockLibrary + currentBllEntryIdx);
- const uint8 *currentBllPtr = _currentBlockLibrary + currentBllOffset;
+ const uint8 *currentBllPtr = getBlockLibrary(currentBllEntryIdx);
const uint32 bllSizeX = *currentBllPtr++;
const uint32 bllSizeY = *currentBllPtr++;
@@ -329,7 +328,7 @@ void Grid::loadGridBricks() {
}
}
}
- currentBllEntryIdx += 4;
+ ++currentBllEntryIdx;
}
for (uint32 i = firstBrick; i <= lastBrick; i++) {
@@ -614,9 +613,17 @@ const uint8 *Grid::getBlockBufferGround(const IVec3 &pos, int32 &ground) {
return ptr;
}
-const uint8 *Grid::getBlockLibrary(int32 index) const {
- const int32 offset = READ_LE_UINT32(_currentBlockLibrary + 4 * index);
- return (const uint8 *)(_currentBlockLibrary + offset);
+const uint8* Grid::getBlockPointer(int32 blockIdx, int32 brickIdx) const {
+ const uint8 *blockPtr = getBlockLibrary(blockIdx);
+ blockPtr += 3; // x, y, z bytes
+ blockPtr = blockPtr + brickIdx * 4; // each brick index is shape(byte), type(byte), idx(short)
+ return blockPtr;
+}
+
+const uint8 *Grid::getBlockLibrary(int32 blockIdx) const {
+ const uint8 *gridPtr = _currentBlockLibrary;
+ const int32 offset = READ_LE_UINT32(gridPtr + 4 * blockIdx - 4);
+ return (const uint8 *)(gridPtr + offset);
}
void Grid::getBrickPos(int32 x, int32 y, int32 z) {
@@ -625,8 +632,7 @@ void Grid::getBrickPos(int32 x, int32 y, int32 z) {
}
void Grid::drawColumnGrid(int32 blockIdx, int32 brickBlockIdx, int32 x, int32 y, int32 z) {
- const uint8 *blockPtr = getBlockLibrary(blockIdx) + 3 + brickBlockIdx * 4;
-
+ const uint8 *blockPtr = getBlockPointer(blockIdx, brickBlockIdx);
const uint8 brickShape = *((const uint8 *)(blockPtr + 0));
const uint8 brickSound = *((const uint8 *)(blockPtr + 1));
const uint16 brickIdx = READ_LE_UINT16(blockPtr + 2);
@@ -691,7 +697,7 @@ void Grid::redrawGrid() {
for (int32 y = 0; y < GRID_SIZE_Y; y++) {
const uint8 blockIdx = (*map)[z][x][y].blockIdx;
if (blockIdx) {
- drawColumnGrid(blockIdx - 1, (*map)[z][x][y].brickBlockIdx, x, y, z);
+ drawColumnGrid(blockIdx, (*map)[z][x][y].brickBlockIdx, x, y, z);
}
}
}
@@ -721,14 +727,8 @@ ShapeType Grid::getBrickShape(int32 x, int32 y, int32 z) {
uint8 blockIdx = *blockBufferPtr;
if (blockIdx) {
- const uint8 *blockPtr = _currentBlockLibrary;
-
- blockPtr += READ_LE_UINT32(blockPtr + blockIdx * 4 - 4);
- blockPtr += 3;
-
const uint8 tmpBrickIdx = *(blockBufferPtr + 1);
- blockPtr = blockPtr + tmpBrickIdx * 4;
-
+ const uint8 *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
return (ShapeType)*blockPtr;
}
return (ShapeType) * (blockBufferPtr + 1);
@@ -764,14 +764,8 @@ ShapeType Grid::getBrickShapeFull(int32 x, int32 y, int32 z, int32 y2) {
uint8 blockIdx = *blockBufferPtr;
if (blockIdx) {
- const uint8 *blockPtr = _currentBlockLibrary;
-
- blockPtr += READ_LE_UINT32(blockPtr + blockIdx * 4 - 4);
- blockPtr += 3;
-
const uint8 tmpBrickIdx = *(blockBufferPtr + 1);
- blockPtr = blockPtr + tmpBrickIdx * 4;
-
+ const uint8 *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
const ShapeType brickShape = (ShapeType)*blockPtr;
const int32 newY = (y2 + (BRICK_HEIGHT - 1)) / BRICK_HEIGHT;
@@ -836,16 +830,9 @@ int32 Grid::getBrickSoundType(int32 x, int32 y, int32 z) {
uint8 blockIdx = *blockBufferPtr;
if (blockIdx) {
- const uint8 *blockPtr = _currentBlockLibrary;
-
- blockPtr += READ_LE_UINT32(blockPtr + blockIdx * 4 - 4);
- blockPtr += 3;
-
uint8 tmpBrickIdx = *(blockBufferPtr + 1);
- blockPtr = blockPtr + tmpBrickIdx * 4;
- blockPtr++;
-
- return READ_LE_INT16(blockPtr);
+ const uint8 *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
+ return READ_LE_INT16(blockPtr + 1);
}
return 0xF0;
diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h
index 1988b3bb7e..5ba7950ea3 100644
--- a/engines/twine/scene/grid.h
+++ b/engines/twine/scene/grid.h
@@ -260,10 +260,11 @@ public:
/**
* Get block library
- * @param index block library index
+ * @param blockIdx block library index
* @return pointer to the current block index
*/
- const uint8 *getBlockLibrary(int32 index) const;
+ const uint8 *getBlockLibrary(int32 blockIdx) const;
+ const uint8* getBlockPointer(int32 blockIdx, int32 tmpBrickIdx) const;
/** Create grid map from current grid to block library buffer */
void createGridMap();
diff --git a/engines/twine/scene/movements.cpp b/engines/twine/scene/movements.cpp
index 7b6710f8a6..fbdcb56bff 100644
--- a/engines/twine/scene/movements.cpp
+++ b/engines/twine/scene/movements.cpp
@@ -44,10 +44,11 @@ void Movements::getShadowPosition(const IVec3 &pos) {
_processActor.z = pos.z;
ShapeType shadowCollisionType;
- if (*ptr) {
- const uint8 *blockPtr = _engine->_grid->getBlockLibrary(*ptr - 1) + 3 + *(ptr + 1) * 4;
- const ShapeType brickShape = (ShapeType) * ((const uint8 *)(blockPtr));
- shadowCollisionType = brickShape;
+ const int32 blockIdx = *ptr;
+ if (blockIdx) {
+ const int32 brickIdx = *(ptr + 1);
+ const uint8 *blockPtr = _engine->_grid->getBlockPointer(blockIdx, brickIdx);
+ shadowCollisionType = (ShapeType)*blockPtr;
} else {
shadowCollisionType = ShapeType::kNone;
}
Commit: a7025f0365075cffbeccf482c5f7545c3aa19391
https://github.com/scummvm/scummvm/commit/a7025f0365075cffbeccf482c5f7545c3aa19391
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-11T21:35:20+02:00
Commit Message:
TWINE: use the block library parser
Changed paths:
engines/twine/scene/grid.cpp
engines/twine/scene/grid.h
engines/twine/scene/movements.cpp
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index 6611410641..86751e2ae4 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -26,6 +26,7 @@
#include "common/textconsole.h"
#include "twine/debugger/debug_grid.h"
#include "twine/menu/interface.h"
+#include "twine/parser/blocklibrary.h"
#include "twine/renderer/redraw.h"
#include "twine/renderer/renderer.h"
#include "twine/renderer/screens.h"
@@ -53,7 +54,6 @@ Grid::~Grid() {
free(_brickTable[i]);
}
free(_currentGrid);
- free(_currentBlockLibrary);
free(_brickInfoBuffer);
free(_bricksDataBuffer);
}
@@ -299,33 +299,22 @@ void Grid::loadGridBricks() {
const uint8 currentBitMask = 1 << (7 - (i & 7));
if (currentBitByte & currentBitMask) {
- const uint8 *currentBllPtr = getBlockLibrary(currentBllEntryIdx);
-
- const uint32 bllSizeX = *currentBllPtr++;
- const uint32 bllSizeY = *currentBllPtr++;
- const uint32 bllSizeZ = *currentBllPtr++;
-
- const uint32 bllSize = bllSizeX * bllSizeY * bllSizeZ;
-
- for (uint32 j = 0; j < bllSize; j++) {
- /* const uint8 type = * */currentBllPtr++;
- /* const uint8 shape = * */currentBllPtr++;
- uint32 brickIdx = READ_LE_INT16(currentBllPtr);
- currentBllPtr += 2;
-
- if (brickIdx) {
- brickIdx--;
-
- if (brickIdx <= firstBrick) {
- firstBrick = brickIdx;
- }
-
- if (brickIdx > lastBrick) {
- lastBrick = brickIdx;
- }
+ const BlockData *currentBllPtr = getBlockLibrary(currentBllEntryIdx);
+ for (const BlockDataEntry &entry : currentBllPtr->entries) {
+ uint16 brickIdx = entry.brickIdx;
+ if (!brickIdx) {
+ continue;
+ }
+ brickIdx--;
+ if (brickIdx <= firstBrick) {
+ firstBrick = brickIdx;
+ }
- _brickUsageTable[brickIdx] = 1;
+ if (brickIdx > lastBrick) {
+ lastBrick = brickIdx;
}
+
+ _brickUsageTable[brickIdx] = 1;
}
}
++currentBllEntryIdx;
@@ -445,7 +434,7 @@ bool Grid::initGrid(int32 index) {
}
// load layouts from file
- if (HQR::getAllocEntry(&_currentBlockLibrary, Resources::HQR_LBA_BLL_FILE, index) == 0) {
+ if (!_currentBlockLibrary.loadFromHQR(Resources::HQR_LBA_BLL_FILE, index, _engine->isLBA1())) {
warning("Failed to load block library index: %i", index);
return false;
}
@@ -613,17 +602,13 @@ const uint8 *Grid::getBlockBufferGround(const IVec3 &pos, int32 &ground) {
return ptr;
}
-const uint8* Grid::getBlockPointer(int32 blockIdx, int32 brickIdx) const {
- const uint8 *blockPtr = getBlockLibrary(blockIdx);
- blockPtr += 3; // x, y, z bytes
- blockPtr = blockPtr + brickIdx * 4; // each brick index is shape(byte), type(byte), idx(short)
- return blockPtr;
+const BlockDataEntry* Grid::getBlockPointer(int32 blockIdx, int32 brickIdx) const {
+ const BlockData *blockPtr = getBlockLibrary(blockIdx);
+ return &blockPtr->entries[brickIdx];
}
-const uint8 *Grid::getBlockLibrary(int32 blockIdx) const {
- const uint8 *gridPtr = _currentBlockLibrary;
- const int32 offset = READ_LE_UINT32(gridPtr + 4 * blockIdx - 4);
- return (const uint8 *)(gridPtr + offset);
+const BlockData *Grid::getBlockLibrary(int32 blockIdx) const {
+ return _currentBlockLibrary.getLayout(blockIdx - 1);
}
void Grid::getBrickPos(int32 x, int32 y, int32 z) {
@@ -632,10 +617,10 @@ void Grid::getBrickPos(int32 x, int32 y, int32 z) {
}
void Grid::drawColumnGrid(int32 blockIdx, int32 brickBlockIdx, int32 x, int32 y, int32 z) {
- const uint8 *blockPtr = getBlockPointer(blockIdx, brickBlockIdx);
- const uint8 brickShape = *((const uint8 *)(blockPtr + 0));
- const uint8 brickSound = *((const uint8 *)(blockPtr + 1));
- const uint16 brickIdx = READ_LE_UINT16(blockPtr + 2);
+ const BlockDataEntry *blockPtr = getBlockPointer(blockIdx, brickBlockIdx);
+ const uint8 brickShape = blockPtr->brickShape;
+ const uint8 brickSound = blockPtr->brickType;
+ const uint16 brickIdx = blockPtr->brickIdx;
if (!brickIdx) {
return;
}
@@ -728,8 +713,8 @@ ShapeType Grid::getBrickShape(int32 x, int32 y, int32 z) {
if (blockIdx) {
const uint8 tmpBrickIdx = *(blockBufferPtr + 1);
- const uint8 *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
- return (ShapeType)*blockPtr;
+ const BlockDataEntry *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
+ return (ShapeType)blockPtr->brickShape;
}
return (ShapeType) * (blockBufferPtr + 1);
}
@@ -765,8 +750,8 @@ ShapeType Grid::getBrickShapeFull(int32 x, int32 y, int32 z, int32 y2) {
if (blockIdx) {
const uint8 tmpBrickIdx = *(blockBufferPtr + 1);
- const uint8 *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
- const ShapeType brickShape = (ShapeType)*blockPtr;
+ const BlockDataEntry *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
+ const ShapeType brickShape = (ShapeType)blockPtr->brickShape;
const int32 newY = (y2 + (BRICK_HEIGHT - 1)) / BRICK_HEIGHT;
int32 currY = collision.y;
@@ -831,8 +816,8 @@ int32 Grid::getBrickSoundType(int32 x, int32 y, int32 z) {
if (blockIdx) {
uint8 tmpBrickIdx = *(blockBufferPtr + 1);
- const uint8 *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
- return READ_LE_INT16(blockPtr + 1);
+ const BlockDataEntry *blockPtr = getBlockPointer(blockIdx, tmpBrickIdx);
+ return blockPtr->brickType;
}
return 0xF0;
diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h
index 5ba7950ea3..3b8fb009b3 100644
--- a/engines/twine/scene/grid.h
+++ b/engines/twine/scene/grid.h
@@ -24,6 +24,7 @@
#define TWINE_SCENE_GRID_H
#include "common/scummsys.h"
+#include "twine/parser/blocklibrary.h"
#include "twine/parser/sprite.h"
#include "twine/shared.h"
#include "twine/twine.h"
@@ -155,8 +156,8 @@ private:
/** Current grid pointer */
int32 _currentGridSize = 0;
uint8 *_currentGrid = nullptr;
- /** Current block library pointer */
- uint8 *_currentBlockLibrary = nullptr;
+ /** Current block library */
+ BlockLibraryData _currentBlockLibrary;
/** Brick data buffer */
BrickEntry *_bricksDataBuffer = nullptr;
@@ -263,8 +264,8 @@ public:
* @param blockIdx block library index
* @return pointer to the current block index
*/
- const uint8 *getBlockLibrary(int32 blockIdx) const;
- const uint8* getBlockPointer(int32 blockIdx, int32 tmpBrickIdx) const;
+ const BlockData *getBlockLibrary(int32 blockIdx) const;
+ const BlockDataEntry* getBlockPointer(int32 blockIdx, int32 tmpBrickIdx) const;
/** Create grid map from current grid to block library buffer */
void createGridMap();
diff --git a/engines/twine/scene/movements.cpp b/engines/twine/scene/movements.cpp
index fbdcb56bff..43bdc29e65 100644
--- a/engines/twine/scene/movements.cpp
+++ b/engines/twine/scene/movements.cpp
@@ -47,8 +47,8 @@ void Movements::getShadowPosition(const IVec3 &pos) {
const int32 blockIdx = *ptr;
if (blockIdx) {
const int32 brickIdx = *(ptr + 1);
- const uint8 *blockPtr = _engine->_grid->getBlockPointer(blockIdx, brickIdx);
- shadowCollisionType = (ShapeType)*blockPtr;
+ const BlockDataEntry *blockPtr = _engine->_grid->getBlockPointer(blockIdx, brickIdx);
+ shadowCollisionType = (ShapeType)blockPtr->brickShape;
} else {
shadowCollisionType = ShapeType::kNone;
}
More information about the Scummvm-git-logs
mailing list