[Scummvm-git-logs] scummvm master -> df0adb9ddf1bedb1d3a9a458390fcf56bb83f28e

mduggan noreply at scummvm.org
Sat May 6 07:49:45 UTC 2023


This automated email contains information about 6 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4f80aa65d2 TETRAEDGE: Fix aspect ratio of computer puzzles
58ddc72537 TETRAEDGE: Fix potential crash on marker update
99668f5161 TETRAEDGE: Fix Amerzone font rendering
4fc9b914e0 TETRAEDGE: Remove some dead code
1c5e05ae69 MATH: Add Frustum::isTriangleInside utility function
df0adb9ddf TETRAEDGE: Mostly fix rendering of Amerzone objects


Commit: 4f80aa65d2d2426e50adfcf2179470d72e12d0c0
    https://github.com/scummvm/scummvm/commit/4f80aa65d2d2426e50adfcf2179470d72e12d0c0
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-05-06T16:46:13+09:00

Commit Message:
TETRAEDGE: Fix aspect ratio of computer puzzles

Changed paths:
    engines/tetraedge/game/puzzle_computer_hydra.cpp
    engines/tetraedge/game/puzzle_computer_pwd.cpp


diff --git a/engines/tetraedge/game/puzzle_computer_hydra.cpp b/engines/tetraedge/game/puzzle_computer_hydra.cpp
index 89dc710cb03..6d8623c7eea 100644
--- a/engines/tetraedge/game/puzzle_computer_hydra.cpp
+++ b/engines/tetraedge/game/puzzle_computer_hydra.cpp
@@ -73,6 +73,7 @@ bool PuzzleComputerHydra::enterChecklistScreen() {
 	exitSelectMode();
 	_checklistStep = 0;
 	_gui.layoutChecked("checklist")->setVisible(true);
+	_gui.layoutChecked("checklist")->setRatioMode(TeILayout::RATIO_MODE_NONE);
 	_gui.spriteLayoutChecked("title")->load("2D/puzzles/Computer_Hydra/CHECKLIST.png");
 	_gui.spriteLayoutChecked("infos")->setVisible(false);
 	clearChecklistScreen();
@@ -88,6 +89,7 @@ bool PuzzleComputerHydra::enterCoordinatesScreen() {
 	_enteredCoord[1] = -1;
 	_enteredCoord[2] = -1;
 	_gui.spriteLayoutChecked("coordinates")->setVisible(true);
+	_gui.spriteLayoutChecked("coordinates")->setRatioMode(TeILayout::RATIO_MODE_NONE);
 	_gui.spriteLayoutChecked("titleCoordinates")->load("2D/puzzles/Computer_Hydra/ENTERDETAILS.png");
 	_gui.spriteLayoutChecked("title")->setVisible(false);
 	_gui.spriteLayoutChecked("infos")->setVisible(false);
@@ -114,6 +116,7 @@ bool PuzzleComputerHydra::enterSelectMode() {
 	_transitionTimer.alarmSignal().remove(this, &PuzzleComputerHydra::enterSelectMode);
 	exitChecklistScreen();
 	_gui.layoutChecked("modeSelect")->setVisible(true);
+	_gui.layoutChecked("modeSelect")->setRatioMode(TeILayout::RATIO_MODE_NONE);
 	_gui.spriteLayoutChecked("title")->load("2D/puzzles/Computer_Hydra/CHOOSEMODE.png");
 	_gui.spriteLayoutChecked("infos")->setVisible(false);
 	return true;
@@ -139,7 +142,6 @@ bool PuzzleComputerHydra::exitCoordinatesScreen() {
 	_gui.buttonLayoutChecked("button8")->setEnable(false);
 	_gui.buttonLayoutChecked("button9")->setEnable(false);
 	_gui.buttonLayoutChecked("cancel")->setEnable(false);
-	_gui.buttonLayoutChecked("exit")->setEnable(false);
 	_gui.spriteLayoutChecked("digit1")->setVisible(false);
 	_gui.spriteLayoutChecked("digit2")->setVisible(false);
 	_gui.spriteLayoutChecked("digit3")->setVisible(false);
@@ -166,6 +168,7 @@ bool PuzzleComputerHydra::hideUnavailableModeMsg() {
 
 void PuzzleComputerHydra::initAll() {
 	_gui.spriteLayoutChecked("screenBase")->setVisible(true);
+	_gui.spriteLayoutChecked("screenBase")->setRatioMode(TeILayout::RATIO_MODE_NONE);
 	_gui.spriteLayoutChecked("title")->setVisible(true);
 	_gui.spriteLayoutChecked("infos")->setVisible(false);
 	_gui.buttonLayoutChecked("confirmDestination")->setVisible(false);
@@ -354,13 +357,13 @@ bool PuzzleComputerHydra::onButtonBoatClicked() {
 
 bool PuzzleComputerHydra::onButtonCancelClicked() {
 	if (_axisNo <= 0)
-		return false;
+		return true;
 	const Common::String dname = Common::String::format("digit%d", _axisNo);
 	_gui.spriteLayoutChecked(dname)->setVisible(false);
 	_axisNo--;
 	_enteredCoord[_axisNo] = -1;
 	_gui.spriteLayoutChecked("infosCoordinates")->setVisible(false);
-	return false;
+	return true;
 }
 
 bool PuzzleComputerHydra::onButtonGrappleClicked() {
diff --git a/engines/tetraedge/game/puzzle_computer_pwd.cpp b/engines/tetraedge/game/puzzle_computer_pwd.cpp
index 28217e4590c..5f8ddcc5bb8 100644
--- a/engines/tetraedge/game/puzzle_computer_pwd.cpp
+++ b/engines/tetraedge/game/puzzle_computer_pwd.cpp
@@ -37,6 +37,7 @@ PuzzleComputerPwd::PuzzleComputerPwd() : _nDigits(0) {
 void PuzzleComputerPwd::enter() {
 	_gui.load("GUI/PuzzleComputerPwd.lua");
 	g_engine->getApplication()->frontLayout().addChild(_gui.layoutChecked("puzzleComputerPassword"));
+	_gui.layoutChecked("background")->setRatioMode(TeILayout::RATIO_MODE_NONE);
 	_gui.spriteLayoutChecked("background")->setVisible(true);
 	_gui.buttonLayoutChecked("button0")->setEnable(true);
 	_gui.buttonLayoutChecked("button1")->setEnable(true);


Commit: 58ddc725377f0f365843c301ca29916222df7ced
    https://github.com/scummvm/scummvm/commit/58ddc725377f0f365843c301ca29916222df7ced
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-05-06T16:46:13+09:00

Commit Message:
TETRAEDGE: Fix potential crash on marker update

Changed paths:
    engines/tetraedge/te/te_warp.cpp


diff --git a/engines/tetraedge/te/te_warp.cpp b/engines/tetraedge/te/te_warp.cpp
index 74610c46c20..ba14cd26888 100644
--- a/engines/tetraedge/te/te_warp.cpp
+++ b/engines/tetraedge/te/te_warp.cpp
@@ -190,6 +190,7 @@ void TeWarp::configMarker(const Common::String &objname, int markerImgNo, long m
 		btnUp->play();
 		warpMarker->marker()->visible(true);
 		// Ensure markers appear below menus and videos.
+		frontLayout.removeChild(&warpMarker->marker()->button());
 		frontLayout.addChildBefore(&warpMarker->marker()->button(), frontLayout.child(0));
 	}
 }


Commit: 99668f51613ec01bdfd8ce69afb3f4b8e4d43c9d
    https://github.com/scummvm/scummvm/commit/99668f51613ec01bdfd8ce69afb3f4b8e4d43c9d
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-05-06T16:46:13+09:00

Commit Message:
TETRAEDGE: Fix Amerzone font rendering

Changed paths:
    engines/tetraedge/te/te_font2.cpp


diff --git a/engines/tetraedge/te/te_font2.cpp b/engines/tetraedge/te/te_font2.cpp
index 17320b3282c..6650fed25e0 100644
--- a/engines/tetraedge/te/te_font2.cpp
+++ b/engines/tetraedge/te/te_font2.cpp
@@ -156,13 +156,21 @@ void TeFont2::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32
 
 	Common::Rect srcRect;
 	srcRect.left = (int)g._vec.x();
-	srcRect.top = _texture.h - (int)g._vec.y();
+	srcRect.top = _texture.h - (int)g._vec.y() - g._ySz;
 	srcRect.right = srcRect.left + g._xSz;
 	srcRect.bottom = srcRect.top + g._ySz;
 
 	int dstX = x + g._xOff;
 	int dstY = _maxHeight - g._yOff;
 
+	if (dstX + srcRect.width() > dst->w)
+		srcRect.right = srcRect.left + (dst->w - dstX);
+	if (dstY + srcRect.height() > dst->h)
+		srcRect.bottom = srcRect.top + (dst->h - dstY);
+
+	debug("TeFont2::drawChar %c (%d, %d) from (%d,%d-%d,%d)", chr, x, y,
+			srcRect.left, srcRect.top, srcRect.right, srcRect.bottom);
+
 	dst->copyRectToSurface(_texture, dstX, dstY, srcRect);
 }
 
@@ -203,7 +211,7 @@ Common::Rect TeFont2::getBoundingBox(uint32 chr) const {
 
 	Common::Rect rect;
 	rect.left = (int)_glyphs[chr]._xOff;
-	rect.right = rect.left + (int)_glyphs[chr]._xAdvance;
+	rect.right = rect.left + _glyphs[chr]._xSz;
 	rect.top = _maxHeight - _glyphs[chr]._yOff;
 	rect.bottom = _maxHeight;
 	return rect;


Commit: 4fc9b914e0973de189aed426f342d23cb38dc699
    https://github.com/scummvm/scummvm/commit/4fc9b914e0973de189aed426f342d23cb38dc699
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-05-06T16:46:14+09:00

Commit Message:
TETRAEDGE: Remove some dead code

Changed paths:
    engines/tetraedge/te/te_3d_object2.cpp


diff --git a/engines/tetraedge/te/te_3d_object2.cpp b/engines/tetraedge/te/te_3d_object2.cpp
index a5f753e353b..5611fd96f29 100644
--- a/engines/tetraedge/te/te_3d_object2.cpp
+++ b/engines/tetraedge/te/te_3d_object2.cpp
@@ -145,13 +145,14 @@ void Te3DObject2::removeChild(Te3DObject2 *child) {
 		_children[i]->setParent(nullptr);
 		_children.remove_at(i);
 		_childListChangedSignal.call();
-	} else {
+	} /*else {
+		// Print a warning?
+		// This happens on every scene change so this is a bit too noisy.
 		Common::String cname("nullptr");
 		if (child)
 			cname = child->name();
-		// This happens on every scene change so this is a bit too noisy.
-		// debug("Request to remove child (%s) which is not a child of this (%s).", cname.c_str(), name().c_str());
-	}
+		debug("Request to remove child (%s) which is not a child of this (%s).", cname.c_str(), name().c_str());
+	}*/
 }
 
 bool Te3DObject2::onWorldVisibleChangedSlot() {


Commit: 1c5e05ae69a4f92dedd9e4fd2affbd29c7326685
    https://github.com/scummvm/scummvm/commit/1c5e05ae69a4f92dedd9e4fd2affbd29c7326685
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-05-06T16:47:50+09:00

Commit Message:
MATH: Add Frustum::isTriangleInside utility function

Changed paths:
    math/frustum.cpp
    math/frustum.h


diff --git a/math/frustum.cpp b/math/frustum.cpp
index a733e4d8b96..0fd85097776 100644
--- a/math/frustum.cpp
+++ b/math/frustum.cpp
@@ -89,4 +89,17 @@ bool Frustum::isInside(const Math::AABB &aabb) const {
 	return true;
 }
 
+bool Frustum::isTriangleInside(const Math::Vector3d &v0, const Math::Vector3d &v1, const Math::Vector3d &v2) const {
+	for (int i = 0; i < 6; ++i) {
+		const Plane &plane = _planes[i];
+		// Inside if any point is above the plane. On the plane is in
+		if (plane.getSignedDistance(v0) < 0.0f
+				&& plane.getSignedDistance(v1) < 0.0f
+				&& plane.getSignedDistance(v2) < 0.0f)
+			return false;
+	}
+	return true;
+}
+
+
 }
diff --git a/math/frustum.h b/math/frustum.h
index 2484ba7084f..810a35c52a9 100644
--- a/math/frustum.h
+++ b/math/frustum.h
@@ -28,12 +28,14 @@
 
 namespace Math {
 
+/* A volume defined by 6 planes */
 class Frustum {
 public:
 	Frustum();
 
 	void setup(const Math::Matrix4 &matrix);
 	bool isInside(const Math::AABB &aabb) const;
+	bool isTriangleInside(const Math::Vector3d &v0, const Math::Vector3d &v1, const Math::Vector3d &v2) const;
 
 private:
 	Math::Plane _planes[6];


Commit: df0adb9ddf1bedb1d3a9a458390fcf56bb83f28e
    https://github.com/scummvm/scummvm/commit/df0adb9ddf1bedb1d3a9a458390fcf56bb83f28e
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2023-05-06T16:48:32+09:00

Commit Message:
TETRAEDGE: Mostly fix rendering of Amerzone objects

Mostly.. they still pop in and out a bit so Frustum is probably not right.

Changed paths:
    engines/tetraedge/te/te_frustum.cpp
    engines/tetraedge/te/te_frustum.h
    engines/tetraedge/te/te_matrix4x4.cpp
    engines/tetraedge/te/te_matrix4x4.h
    engines/tetraedge/te/te_pick_mesh.cpp
    engines/tetraedge/te/te_pick_mesh.h
    engines/tetraedge/te/te_ray_intersection.cpp
    engines/tetraedge/te/te_scene_warp.cpp
    engines/tetraedge/te/te_warp.cpp
    engines/tetraedge/te/te_warp.h
    engines/tetraedge/te/te_warp_bloc.cpp


diff --git a/engines/tetraedge/te/te_frustum.cpp b/engines/tetraedge/te/te_frustum.cpp
index a2630ff81de..eac6b574e4e 100644
--- a/engines/tetraedge/te/te_frustum.cpp
+++ b/engines/tetraedge/te/te_frustum.cpp
@@ -26,69 +26,12 @@ namespace Tetraedge {
 TeFrustum::TeFrustum() {
 }
 
-void TeFrustum::computeNormal(unsigned int val) {
-	error("TODO: implement TeFrustum::computeNormal");
-}
-
-void TeFrustum::extractPlanAdd(const TeMatrix4x4 &matrix, uint dest, uint col) {
-	_m[dest * 4 + 0] = matrix(0, 3) - matrix(0, col);
-	_m[dest * 4 + 1] = matrix(1, 3) - matrix(1, col);
-	_m[dest * 4 + 2] = matrix(2, 3) - matrix(2, col);
-	_m[dest * 4 + 3] = matrix(3, 3) - matrix(3, col);
-}
-
-void TeFrustum::extractPlanSub(const TeMatrix4x4 &matrix, uint dest, uint col) {
-	_m[dest * 4 + 0] = matrix(0, 3) + matrix(0, col);
-	_m[dest * 4 + 1] = matrix(1, 3) + matrix(1, col);
-	_m[dest * 4 + 2] = matrix(2, 3) + matrix(2, col);
-	_m[dest * 4 + 3] = matrix(3, 3) + matrix(3, col);
-}
-
-bool TeFrustum::pointIsIn(const TeVector3f32 &pt) const {
-	error("TODO: Implement TeFrustum::pointIsIn");
-}
-
-float TeFrustum::planeLen(int num) const {
-	assert(num >= 0 && num < 6);
-	const float *p = _m + num * 4;
-	float result = (float)sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2]);
-	if (result == 0)
-		result = 1e-08f;
-	return result;
-}
-
-bool TeFrustum::sphereIsIn(const TeVector3f32 &vec, float f) const {
-	error("TODO: Implement TeFrustum::sphereIsIn");
-}
-
-bool TeFrustum::triangleIsIn(const TeVector3f32 *verts) const {
-	for (unsigned int p = 0; p < 6; p++) {
-		bool inside = true;
-		for (unsigned int v = 0; v < 3; v++) {
-			const float *pm = _m + p * 4;
-			if(pm[0] * verts[v].x() + pm[1] * verts[v].y() +
-				pm[2] * verts[v].z() + pm[3] >= 0.0)
-					inside = false;
-		}
-		if (!inside)
-			return false;
-	}
-	
-	return true;
-}
-
-void TeFrustum::update(TeCamera *camera) {
-	const TeMatrix4x4 camMatrix = camera->worldTransformationMatrix();
-	for (unsigned int plane = 0; plane < 6; plane++) {
-		if (plane % 2)
-			extractPlanAdd(camMatrix, plane, plane / 2);
-		else
-			extractPlanSub(camMatrix, plane, plane / 2);
-		float len = planeLen(plane);
-		float *p = _m + plane * 4;
-		for (int i = 0; i < 4; i++)
-			p[i] /= len;
-	}
+void TeFrustum::update(TeCamera &cam) {
+	const TeMatrix4x4 camProjMatrix = cam.projectionMatrix();
+	TeMatrix4x4 camWorldMatrix = cam.worldTransformationMatrix();
+	camWorldMatrix.inverse();
+	const TeMatrix4x4 camProjWorld = camProjMatrix * camWorldMatrix;
+	setup(camProjWorld.toScummVMMatrix());
 }
 
 
diff --git a/engines/tetraedge/te/te_frustum.h b/engines/tetraedge/te/te_frustum.h
index d06d2eac23c..45c36ae4b2f 100644
--- a/engines/tetraedge/te/te_frustum.h
+++ b/engines/tetraedge/te/te_frustum.h
@@ -22,28 +22,24 @@
 #ifndef TETRAEDGE_TE_TE_FRUSTUM_H
 #define TETRAEDGE_TE_TE_FRUSTUM_H
 
+#include "math/frustum.h"
+
 #include "tetraedge/te/te_camera.h"
 #include "tetraedge/te/te_vector3f32.h"
 #include "tetraedge/te/te_matrix4x4.h"
 
 namespace Tetraedge {
 
-class TeFrustum {
+class TeFrustum : public Math::Frustum {
 public:
 	TeFrustum();
 
-	void computeNormal(unsigned int val);
-	void extractPlanAdd(const TeMatrix4x4 &matrix, uint param_2, uint param_3);
-	void extractPlanSub(const TeMatrix4x4 &matrix, uint param_2, uint param_3);
-	bool pointIsIn(const TeVector3f32 &pt) const;
-	bool sphereIsIn(const TeVector3f32 &vec, float f) const;
-	bool triangleIsIn(const TeVector3f32 *vertexes) const;
-	void update(TeCamera *camera);
-
-private:
-	float planeLen(int num) const;
-	float _m[24];
+	// unused..
+	//void computeNormal(unsigned int val);
+	//bool pointIsIn(const TeVector3f32 &pt) const;
+	//bool sphereIsIn(const TeVector3f32 &vec, float f) const;
 
+	void update(TeCamera &camera);
 };
 
 } // end namespace Tetraedge
diff --git a/engines/tetraedge/te/te_matrix4x4.cpp b/engines/tetraedge/te/te_matrix4x4.cpp
index afaadaa1324..13e58a0c591 100644
--- a/engines/tetraedge/te/te_matrix4x4.cpp
+++ b/engines/tetraedge/te/te_matrix4x4.cpp
@@ -159,7 +159,6 @@ TeVector3f32 TeMatrix4x4::operator*(const TeVector3f32 &mul) const {
 			 (d[2] * x + d[6] * y + d[10] * z + d[14]) / w);
 }
 
-
 Common::String TeMatrix4x4::toString() const {
 	const float *data = getData();
 	return Common::String::format("[[%.03f %.03f %.03f %.03f]  [%.03f %.03f %.03f %.03f]  [%.03f %.03f %.03f %.03f]  [%.03f %.03f %.03f %.03f]]",
@@ -169,6 +168,12 @@ Common::String TeMatrix4x4::toString() const {
 								  data[3], data[7], data[11], data[15]);
 }
 
+Math::Matrix<4, 4> TeMatrix4x4::toScummVMMatrix() const {
+	const TeMatrix4x4 trans = transpose();
+	Math::Matrix<4, 4> retval;
+	retval.setData(trans.getData());
+	return retval;
+}
 
 TeMatrix4x4 TeMatrix4x4::transpose() const {
 	TeMatrix4x4 ret;
@@ -182,7 +187,6 @@ TeMatrix4x4 TeMatrix4x4::transpose() const {
 	return ret;
 }
 
-
 bool TeMatrix4x4::inverse() {
 	TeMatrix4x4 invMatrix;
 	float *inv = invMatrix.getData();
diff --git a/engines/tetraedge/te/te_matrix4x4.h b/engines/tetraedge/te/te_matrix4x4.h
index 6d9d4599973..59d03445f01 100644
--- a/engines/tetraedge/te/te_matrix4x4.h
+++ b/engines/tetraedge/te/te_matrix4x4.h
@@ -30,7 +30,8 @@ namespace Tetraedge {
 
 class TeTRS;
 
-/* A 4x4 matrix, but stored in *column-major* order to match
+/**
+ * A 4x4 matrix, but stored in *column-major* order to match
  * OpenGL (and the original engine)
  */
 class TeMatrix4x4 {
@@ -65,6 +66,7 @@ public:
 	TeVector3f32 mult4x3(const TeVector3f32 &vec) const;
 
 	Common::String toString() const;
+	Math::Matrix<4, 4> toScummVMMatrix() const;
 
 	void setValue(int row, int col, float val) {
 		operator()(row, col) = val;
diff --git a/engines/tetraedge/te/te_pick_mesh.cpp b/engines/tetraedge/te/te_pick_mesh.cpp
index 49ea1d975e6..2f30a52a246 100644
--- a/engines/tetraedge/te/te_pick_mesh.cpp
+++ b/engines/tetraedge/te/te_pick_mesh.cpp
@@ -27,15 +27,15 @@
 
 namespace Tetraedge {
 
-TePickMesh::TePickMesh() : _flag(true) {
+TePickMesh::TePickMesh() : _enabled(true) {
 }
 
-TePickMesh::TePickMesh(const TePickMesh &other) : _flag(true) {
+TePickMesh::TePickMesh(const TePickMesh &other) : _enabled(true) {
 	copy(other);
 }
 
 void TePickMesh::copy(const TePickMesh &other) {
-	_flag = other._flag;
+	_enabled = other._enabled;
 	_name = other._name;
 	_v1 = other._v1;
 	_v2 = other._v2;
@@ -54,8 +54,8 @@ void TePickMesh::getTriangle(uint triNum, TeVector3f32 &v1, TeVector3f32 &v2, Te
 	v3 = _verticies[triNum * 3 + 2];
 }
 
-bool TePickMesh::intersect(const Math::Ray &ray, TeVector3f32 &ptOut, float &lenOut) {
-	if (!_flag || _verticies.empty())
+bool TePickMesh::intersect(const Math::Ray &ray, TeVector3f32 &ptOut, float &lenOut) const {
+	if (!_enabled || _verticies.empty())
 		return false;
 	float nearest = FLT_MAX;
 	for (uint i = 0; i < _verticies.size() / 3; i++) {
diff --git a/engines/tetraedge/te/te_pick_mesh.h b/engines/tetraedge/te/te_pick_mesh.h
index 6bd868a4fc5..11783130075 100644
--- a/engines/tetraedge/te/te_pick_mesh.h
+++ b/engines/tetraedge/te/te_pick_mesh.h
@@ -35,7 +35,7 @@ public:
 	// void create(); // unused
 	void destroy();
 	void getTriangle(uint triNum, TeVector3f32 &v1, TeVector3f32 &v2, TeVector3f32 &v3) const;
-	bool intersect(const Math::Ray &ray, TeVector3f32 &ptOut, float &lenOut);
+	bool intersect(const Math::Ray &ray, TeVector3f32 &ptOut, float &lenOut) const;
 	void nbTriangles(uint nTriangles);
 	TePickMesh &operator+=(const TePickMesh &other);
 	TePickMesh &operator=(const TePickMesh &other);
@@ -43,13 +43,13 @@ public:
 	void setTriangle(uint triNum, const TeVector3f32 &v1, const TeVector3f32 &v2, const TeVector3f32 &v3);
 
 	void setName(const Common::String &name) { _name = name; }
-	void setFlag(bool val) { _flag = val; }
-	bool flag() const { return _flag; }
+	void setEnabled(bool val) { _enabled = val; }
+	bool enabled() const { return _enabled; }
 	const Common::String &name() const { return _name; }
 	uint nTriangles() const { return _verticies.size() / 3; }
 
 private:
-	bool _flag;
+	bool _enabled;
 	Common::Array<TeVector3f32> _verticies;
 	Common::String _name;
 	TeVector3f32 _v1;
diff --git a/engines/tetraedge/te/te_ray_intersection.cpp b/engines/tetraedge/te/te_ray_intersection.cpp
index aaf3f55a724..a3139ab5cd2 100644
--- a/engines/tetraedge/te/te_ray_intersection.cpp
+++ b/engines/tetraedge/te/te_ray_intersection.cpp
@@ -37,7 +37,7 @@ TePickMesh *getMesh(const Math::Ray ray, const Common::Array<TePickMesh *> &pick
 	TePickMesh *bestMesh = nullptr;
 
 	for (auto *mesh : pickMeshes) {
-		if (!mesh->flag())
+		if (!mesh->enabled())
 			continue;
 		for (uint i = 0; i < mesh->nTriangles(); i++) {
 			TeVector3f32 v1;
diff --git a/engines/tetraedge/te/te_scene_warp.cpp b/engines/tetraedge/te/te_scene_warp.cpp
index cb427b6f3d2..04c5890e1fd 100644
--- a/engines/tetraedge/te/te_scene_warp.cpp
+++ b/engines/tetraedge/te/te_scene_warp.cpp
@@ -42,28 +42,28 @@ void TeSceneWarp::close() {
 }
 
 const TeSceneWarp::Animation *TeSceneWarp::getAnimation(const Common::String &name) {
-	for (auto &anim : _animations)
+	for (const auto &anim : _animations)
 		if (anim._name == name)
 			return &anim;
 	return nullptr;
 }
 
 const TeSceneWarp::Exit *TeSceneWarp::getExit(const Common::String &linkedWarp) {
-	for (auto &exit : _exits)
+	for (const auto &exit : _exits)
 		if (exit._linkedWarp == linkedWarp)
 			return &exit;
 	return nullptr;
 }
 
 const TeSceneWarp::Object *TeSceneWarp::getObject(const Common::String &name) {
-	for (auto &object : _objects)
+	for (const auto &object : _objects)
 		if (object._name == name)
 			return &object;
 	return nullptr;
 }
 
 const TeSceneWarp::WarpEvent *TeSceneWarp::getWarpEvent(const Common::String &name) {
-	for (auto &warpEvent : _warpEvents)
+	for (const auto &warpEvent : _warpEvents)
 		if (warpEvent._name == name)
 			return &warpEvent;
 	return nullptr;
diff --git a/engines/tetraedge/te/te_warp.cpp b/engines/tetraedge/te/te_warp.cpp
index ba14cd26888..0717676a583 100644
--- a/engines/tetraedge/te/te_warp.cpp
+++ b/engines/tetraedge/te/te_warp.cpp
@@ -36,7 +36,7 @@ namespace Tetraedge {
 bool TeWarp::debug = false;
 
 TeWarp::TeWarp() : _visible1(false), _loaded(false), _preloaded(false),
-	_numAnims(0), _someXVal(0), _someYVal(0), _someMeshX(0), _someMeshY(0),
+	_someXVal(0), _someYVal(0), _someMeshX(0), _someMeshY(0),
 	_renderWarpBlocs(true), _xCount(0), _yCount(0), _clickedPickMesh(nullptr),
 	_clickedAnimData(nullptr), _markersActive(true) {
 }
@@ -129,7 +129,7 @@ void TeWarp::checkObjectEvents() {
 			TePickMesh &pickMesh = animData._frameDatas[animData._curFrameNo]._pickMesh;
 			TeVector3f32 intersectPt;
 			float intersectLen;
-			if (pickMesh.flag() && pickMesh.intersect(mouseRay, intersectPt, intersectLen)) {
+			if (pickMesh.enabled() && pickMesh.intersect(mouseRay, intersectPt, intersectLen)) {
 				_markerValidatedSignal.call(pickMesh.name());
 				break;
 			}
@@ -196,9 +196,9 @@ void TeWarp::configMarker(const Common::String &objname, int markerImgNo, long m
 }
 
 TeWarp::AnimData *TeWarp::findAnimation(const Common::String &objname) {
-	for (uint i = 0; i < _numAnims; i++) {
-		if (_loadedAnimData[i]._name == objname)
-			return _loadedAnimData.data() + i;
+	for (auto &anim : _loadedAnimData) {
+		if (anim._name == objname)
+			return &anim;
 	}
 	return nullptr;
 }
@@ -217,9 +217,9 @@ TeWarp::Exit *TeWarp::findExit(const Common::String &objname, bool flag) {
 	return nullptr;
 }
 
-bool TeWarp::hasObjectOrAnim(const Common::String &objname) {
-	for (uint i = 0; i < _numAnims; i++) {
-		if (_loadedAnimData[i]._name == objname)
+bool TeWarp::hasObjectOrAnim(const Common::String &objname) const {
+	for (const auto &anim : _loadedAnimData) {
+		if (anim._name == objname)
 			return true;
 	}
 	return false;
@@ -262,11 +262,13 @@ void TeWarp::load(const Common::String &path, bool flag) {
 	_texEncodingType = _file.readPascalString();
 	_xCount = _file.readUint32LE();
 	_yCount = _file.readUint32LE();
-	_numAnims = _file.readUint32LE();
+	uint32 numAnims = _file.readUint32LE();
 	_someXVal = _file.readUint32LE();
 	_someYVal = _file.readUint32LE();
 	_someMeshX = _file.readUint32LE();
 	_someMeshY = _file.readUint32LE();
+	if (_xCount > 1000 || _yCount > 1000 || numAnims > 1000)
+		error("Improbable values in TeWarp data xCount %d yCount %d numAnims %d", _xCount, _yCount, numAnims);
 	_warpBlocs.resize(_xCount * _yCount * 6);
 	for (uint i = 0; i < _xCount * _yCount * 6; i++) {
 		TeWarpBloc::CubeFace face = static_cast<TeWarpBloc::CubeFace>(_file.readByte());
@@ -279,9 +281,9 @@ void TeWarp::load(const Common::String &path, bool flag) {
 			_warpBlocs[i].create(face, _xCount, _yCount, offset);
 		}
 	}
-	_loadedAnimData.resize(_numAnims);
-	_putAnimData.reserve(_numAnims);
-	for (uint i = 0; i < _numAnims; i++) {
+	_loadedAnimData.resize(numAnims);
+	_putAnimData.reserve(numAnims);
+	for (uint i = 0; i < numAnims; i++) {
 		char aname[5];
 		_file.read(aname, 4);
 		aname[4] = '\0';
@@ -317,7 +319,7 @@ void TeWarp::load(const Common::String &path, bool flag) {
 						uint yoff = _file.readUint16LE();
 						addQuadToPickMesh(tmpMesh, m * 2, face, TeVector2s32(xoff, yoff), _someMeshX, _someMeshY);
 					}
-					tmpMesh.setFlag(true);
+					tmpMesh.setEnabled(true);
 					if (frameData._pickMesh.name().empty()) {
 						frameData._pickMesh = tmpMesh;
 					} else {
@@ -325,8 +327,8 @@ void TeWarp::load(const Common::String &path, bool flag) {
 					}
 				}
 			}
-			frameData._warpBlocs.resize(frameData._numWarpBlocs);
-			for (int k = 0; k < frameData._numWarpBlocs; k++) {
+			frameData._warpBlocs.resize(warpBlocs.size());
+			for (uint k = 0; k < frameData._warpBlocs.size(); k++) {
 				frameData._warpBlocs[k] = warpBlocs[k];
 			}
 		}
@@ -347,12 +349,12 @@ bool TeWarp::onMouseLeftDown(const Common::Point &pt) {
 	_clickedAnimData = nullptr;
 
 	bool hitAnimData = false;
-	FrameData *frameData = nullptr;
-	for (auto &animData : _loadedAnimData) {
+	const FrameData *frameData = nullptr;
+	for (const auto &animData : _loadedAnimData) {
 		frameData = &(animData._frameDatas[animData._curFrameNo]);
 		TeVector3f32 interesctPt;
 		float intersectDist;
-		if (frameData->_pickMesh.flag() && frameData->_pickMesh.intersect(mouseRay, interesctPt, intersectDist)) {
+		if (frameData->_pickMesh.enabled() && frameData->_pickMesh.intersect(mouseRay, interesctPt, intersectDist)) {
 			_clickedAnimData = &animData;
 			hitAnimData = true;
 			break;
@@ -362,13 +364,13 @@ bool TeWarp::onMouseLeftDown(const Common::Point &pt) {
 	if (!hitAnimData) {
 		_clickedPickMesh = TeRayIntersection::getMesh(mouseRay, _pickMeshes2, FLT_MAX, 0, nullptr);
 		if (_clickedPickMesh) {
-			Exit *exit = findExit(_clickedPickMesh->name(), true);
+			const Exit *exit = findExit(_clickedPickMesh->name(), true);
 			_warpMarkers[exit->_markerId]->marker()->button().setEnable(false);
 		}
 		return false;
 	}
 
-	AnimData *data = findAnimation(frameData->_pickMesh.name());
+	const AnimData *data = findAnimation(frameData->_pickMesh.name());
 	for (auto &markerId : data->_markerIds) {
 		_warpMarkers[markerId]->marker()->button().setEnable(false);
 	}
@@ -388,10 +390,11 @@ void TeWarp::putObject(const Common::String &name, bool enable) {
 				break;
 			}
 		}
+		animData._enabled = true;
 		if (!alreadyAdded)
 			_putAnimData.push_back(&animData);
 		for (auto &frameData : animData._frameDatas) {
-			frameData._pickMesh.setFlag(enable);
+			frameData._pickMesh.setEnabled(enable);
 		}
 		found = true;
 	}
@@ -402,10 +405,10 @@ void TeWarp::putObject(const Common::String &name, bool enable) {
 void TeWarp::update() {
 	if (!_visible1 || !_file.isOpen())
 		return;
-	Application *app = g_engine->getApplication();
-	_frustum.update(app->mainWindowCamera());
-	for (uint i = 0; i < _xCount * _yCount * 6; i++) {
-		_warpBlocs[i].loadTexture(_file, _texEncodingType);
+	//Application *app = g_engine->getApplication();
+	_frustum.update(_camera);
+	for (auto &bloc : _warpBlocs) {
+		bloc.loadTexture(_file, _texEncodingType);
 	}
 
 	for (auto &anim : _loadedAnimData) {
@@ -428,7 +431,7 @@ void TeWarp::update() {
 				anim._frameDatas[lastFrame]._loadedTexCount = 0;
 			}
 		}
-		anim._frameDatas[anim._curFrameNo];
+		anim._frameDatas[anim._curFrameNo].loadTextures(_frustum, _file, _texEncodingType);
 	}
 }
 
@@ -438,7 +441,7 @@ void TeWarp::sendExit(TeWarp::Exit &exit) {
 	mesh->setName(exit._linkedWarpPath);
 	mesh->nbTriangles(exit._warpBlockList.size() * 2);
 	uint trinum = 0;
-	for (auto &block : exit._warpBlockList) {
+	for (const auto &block : exit._warpBlockList) {
 		addQuadToPickMesh(*mesh, trinum, block._face, block._offset, block._x, block._y);
 		trinum += 2;
 	}
@@ -479,7 +482,7 @@ void TeWarp::startAnimationPart(const Common::String &name, int x, int startFram
 		animData._endFrameNo = endFrame;
 		for (auto &frameData : animData._frameDatas) {
 			// TODO: Is this setting the right thing?
-			frameData._pickMesh.setFlag(flag);
+			frameData._pickMesh.setEnabled(flag);
 		}
 		
 		animData._timer.start();
@@ -497,8 +500,8 @@ void TeWarp::setColor(const TeColor &col) {
 }
 
 void TeWarp::setMouseLeftUpForMakers() {
-	for (auto &marker : _warpMarkers) {
-		marker->marker()->button().setEnable(true);
+	for (auto &warpMarker : _warpMarkers) {
+		warpMarker->marker()->button().setEnable(true);
 	}
 }
 
@@ -540,28 +543,19 @@ void TeWarp::render() {
 	renderer->pushMatrix();
 
 	if (_renderWarpBlocs) {
-		for (uint i = 0; i < _xCount * _yCount * 6; i++) {
-			_warpBlocs[i].render();
+		for (auto &bloc : _warpBlocs) {
+			bloc.render();
 		}
 	}
 
-	TeVector3f32 vertexes[6];
-	for (uint i = 0; i < _putAnimData.size(); i++) {
-		AnimData *animData = _putAnimData[i];
+	for (AnimData *animData : _putAnimData) {
 		if (!animData->_enabled)
 			continue;
-		for (uint j = 0; j < animData->_frameDatas.size(); j++) {
-			FrameData &frameData = animData->_frameDatas[j];
-			for (uint k = 0; k < frameData._warpBlocs.size(); k++) {
-				TeWarpBloc &bloc = frameData._warpBlocs[k];
-				vertexes[0] = bloc.vertex(0);
-				vertexes[1] = bloc.vertex(1);
-				vertexes[2] = bloc.vertex(3);
-				vertexes[3] = bloc.vertex(1);
-				vertexes[4] = bloc.vertex(2);
-				vertexes[5] = bloc.vertex(3);
-				if (_frustum.triangleIsIn(vertexes) && _frustum.triangleIsIn(vertexes + 3)) {
-					bloc.render();
+		for (FrameData &frameData : animData->_frameDatas) {
+			for (TeWarpBloc &b : frameData._warpBlocs) {
+				if (_frustum.isTriangleInside(b.vertex(0), b.vertex(1), b.vertex(3))
+						|| _frustum.isTriangleInside(b.vertex(1), b.vertex(2), b.vertex(3))) {
+					b.render();
 				}
 			}
 		}
@@ -607,7 +601,7 @@ void TeWarp::takeObject(const Common::String &name) {
 			}
 		}
 		for (auto &frame : animData._frameDatas) {
-			frame._pickMesh.setFlag(false);
+			frame._pickMesh.setEnabled(false);
 		}
 		found = true;
 	}
@@ -639,13 +633,10 @@ void TeWarp::unload() {
 }
 
 void TeWarp::unloadTextures() {
-	for (uint i = 0; i < _xCount * _yCount * 6; i++) {
-		_warpBlocs[i].unloadTexture();
+	for (auto &bloc : _warpBlocs) {
+		bloc.unloadTexture();
 	}
 
-	if (_numAnims)
-		error("TODO: Finish TeWarp::unloadTextures");
-
 	for (auto &animData : _loadedAnimData) {
 		for (auto &frameData : animData._frameDatas) {
 			for (auto &warpBloc : frameData._warpBlocs) {
@@ -664,20 +655,10 @@ void TeWarp::updateCamera(const TeVector3f32 &screen) {
 }
 
 void TeWarp::FrameData::loadTextures(const TeFrustum &frustum, Common::File &file, const Common::String &fileType) {
-	TeVector3f32 triangle1[3];
-	TeVector3f32 triangle2[3];
-	for (int b = 0; b < _numWarpBlocs; b++) {
-		TeWarpBloc &bloc = _warpBlocs[b];
-		if (bloc.isLoaded())
-			continue;
-		triangle1[0] = bloc.vertex(0);
-		triangle1[1] = bloc.vertex(1);
-		triangle1[2] = bloc.vertex(3);
-		triangle2[0] = bloc.vertex(1);
-		triangle2[1] = bloc.vertex(2);
-		triangle2[2] = bloc.vertex(3);
-		if (frustum.triangleIsIn(triangle1) || frustum.triangleIsIn(triangle2)) {
-			bloc.loadTexture(file, fileType);
+	for (auto &b : _warpBlocs) {
+		if (!b.isLoaded() && (frustum.isTriangleInside(b.vertex(0), b.vertex(1), b.vertex(3))
+				|| frustum.isTriangleInside(b.vertex(1), b.vertex(2), b.vertex(3)))) {
+			b.loadTexture(file, fileType);
 		}
 	}
 }
diff --git a/engines/tetraedge/te/te_warp.h b/engines/tetraedge/te/te_warp.h
index fb92c9a3727..83bac58d5ce 100644
--- a/engines/tetraedge/te/te_warp.h
+++ b/engines/tetraedge/te/te_warp.h
@@ -94,7 +94,7 @@ public:
 	AnimData *findAnimation(const Common::String &name);
 	Exit *findExit(const Common::String &name, bool flag);
 	//int getAnimationFrame(const Common::String &name); // unused
-	bool hasObjectOrAnim(const Common::String &name);
+	bool hasObjectOrAnim(const Common::String &name) const;
 	void init();
 	void load(const Common::String &path, bool flag);
 	//void loadTextures(); // unused
@@ -135,8 +135,8 @@ private:
 	bool _preloaded;
 	bool _renderWarpBlocs;
 
-	TePickMesh *_clickedPickMesh;
-	AnimData *_clickedAnimData;
+	const TePickMesh *_clickedPickMesh;
+	const AnimData *_clickedAnimData;
 
 	TeFrustum _frustum;
 
@@ -150,7 +150,6 @@ private:
 	uint _someMeshY;
 	uint _xCount;
 	uint _yCount;
-	uint _numAnims;
 	Common::Array<TeWarpBloc> _warpBlocs;
 	Common::Array<TePickMesh *> _pickMeshes2;
 	Common::Array<AnimData> _loadedAnimData;
diff --git a/engines/tetraedge/te/te_warp_bloc.cpp b/engines/tetraedge/te/te_warp_bloc.cpp
index 02b6665d325..5956e97917d 100644
--- a/engines/tetraedge/te/te_warp_bloc.cpp
+++ b/engines/tetraedge/te/te_warp_bloc.cpp
@@ -136,7 +136,6 @@ void TeWarpBloc::loadTexture(Common::File &file, const Common::String &type) {
 	TeIntrusivePtr<Te3DTexture> tex = Te3DTexture::makeInstance();
 	tex->load(img);
 	_mesh->defaultMaterial(tex);
-	_mesh->materials()[0]._enableLights = false;
 }
 
 void TeWarpBloc::render() {




More information about the Scummvm-git-logs mailing list