[Scummvm-git-logs] scummvm master -> 5c790d0d11a32bf099eb322c1bb3278598a48c7c

neuromancer noreply at scummvm.org
Sat Nov 26 21:53:01 UTC 2022


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

Summary:
52cc36a7fd FREESCAPE: refined sensor firing range detection
5c790d0d11 FREESCAPE: refactored checkSensors and implemented renderSensorShoot


Commit: 52cc36a7fd30d9e1007eb6f57cb6110bfb306927
    https://github.com/scummvm/scummvm/commit/52cc36a7fd30d9e1007eb6f57cb6110bfb306927
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2022-11-26T22:53:53+01:00

Commit Message:
FREESCAPE: refined sensor firing range detection

Changed paths:
    engines/freescape/freescape.cpp
    engines/freescape/loaders/8bitBinaryLoader.cpp
    engines/freescape/objects/sensor.h


diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp
index f05fca4d716..949c417d09d 100644
--- a/engines/freescape/freescape.cpp
+++ b/engines/freescape/freescape.cpp
@@ -231,8 +231,26 @@ void FreescapeEngine::checkSensors() {
 		Sensor *sensor = (Sensor *)it;
 		if (sensor->isDestroyed() || sensor->isInvisible())
 			continue;
-		if ((sensor->getOrigin() - _position).length() <= sensor->_firingRange) {
-			if (_ticks % sensor->_firingInterval == 0) {
+
+		Math::Vector3d diff = sensor->getOrigin() - _position;
+		bool playerDetected = false;
+
+		if (sensor->_axis == 0x01 && diff.x() >= 0)
+			playerDetected = true;
+		else if (sensor->_axis == 0x02 && diff.x() <= 0)
+			playerDetected = true;
+		else if (sensor->_axis == 0x04 && diff.y() >= 0)
+			playerDetected = true;
+		else if (sensor->_axis == 0x08 && diff.y() <= 0)
+			playerDetected = true;
+		else if (sensor->_axis == 0x10 && diff.z() >= 0)
+			playerDetected = true;
+		else if (sensor->_axis == 0x20 && diff.z() <= 0)
+			playerDetected = true;
+
+		if (playerDetected) {
+			if ((ABS(diff.x() + ABS(diff.y())) + ABS(diff.z()) <= sensor->_firingRange) &&
+			    (_ticks % sensor->_firingInterval == 0)) {
 				drawSensorShoot(sensor);
 				takeDamageFromSensor();
 			}
diff --git a/engines/freescape/loaders/8bitBinaryLoader.cpp b/engines/freescape/loaders/8bitBinaryLoader.cpp
index 3a9d35c0661..65266aaa45e 100644
--- a/engines/freescape/loaders/8bitBinaryLoader.cpp
+++ b/engines/freescape/loaders/8bitBinaryLoader.cpp
@@ -226,6 +226,7 @@ Object *FreescapeEngine::load8bitObject(Common::SeekableReadStream *file) {
 				0,
 				0,
 				0,
+				0,
 				instructions,
 				conditionSource);
 		}
@@ -235,7 +236,7 @@ Object *FreescapeEngine::load8bitObject(Common::SeekableReadStream *file) {
 		assert(color > 0);
 		byte firingInterval = readField(file, 8);
 		uint16 firingRange = readField(file, 16);
-		byte sensorFlags = readField(file, 8);
+		byte sensorAxis = readField(file, 8);
 		byteSizeOfObject = byteSizeOfObject - 5;
 		// grab the object condition, if there is one
 		if (byteSizeOfObject) {
@@ -252,7 +253,8 @@ Object *FreescapeEngine::load8bitObject(Common::SeekableReadStream *file) {
 			color,
 			firingInterval,
 			firingRange,
-			sensorFlags,
+			sensorAxis,
+			rawFlagsAndType,
 			instructions,
 			conditionSource);
 	} break;
diff --git a/engines/freescape/objects/sensor.h b/engines/freescape/objects/sensor.h
index e2e2e0c82cb..740dbe051ee 100644
--- a/engines/freescape/objects/sensor.h
+++ b/engines/freescape/objects/sensor.h
@@ -39,7 +39,8 @@ public:
 		byte color_,
 		byte firingInterval_,
 		uint16 firingRange_,
-		uint16 flags_,
+		uint16 axis_,
+		uint8 flags_,
 		FCLInstructionVector condition_,
 		Common::String conditionSource_) {
 		_objectID = objectID_;
@@ -51,12 +52,14 @@ public:
 			_colours->push_back(color_);
 		_firingInterval = firingInterval_;
 		_firingRange = firingRange_;
+		_axis = axis_;
 		_flags = flags_;
 		_conditionSource = conditionSource_;
 		_condition = condition_;
 	}
 	byte _firingInterval;
 	uint16 _firingRange;
+	uint16 _axis;
 
 	Common::String _conditionSource;
 	FCLInstructionVector _condition;
@@ -67,7 +70,7 @@ public:
 	bool isDrawable() override { return true; }
 	bool isPlanar() override { return true; }
 	void scale(int factor) override { _origin = _origin / factor; };
-	Object *duplicate() override { return (new Sensor(_objectID, _origin, _rotation, (*_colours)[0], _firingInterval, _firingRange, _flags, _condition, _conditionSource)); };
+	Object *duplicate() override { return (new Sensor(_objectID, _origin, _rotation, (*_colours)[0], _firingInterval, _firingRange, _axis, _flags, _condition, _conditionSource)); };
 
 	ObjectType getType() override { return kSensorType; };
 	Math::Vector3d getRotation() { return _rotation; }


Commit: 5c790d0d11a32bf099eb322c1bb3278598a48c7c
    https://github.com/scummvm/scummvm/commit/5c790d0d11a32bf099eb322c1bb3278598a48c7c
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2022-11-26T22:53:53+01:00

Commit Message:
FREESCAPE: refactored checkSensors and implemented renderSensorShoot

Changed paths:
    engines/freescape/freescape.cpp
    engines/freescape/freescape.h
    engines/freescape/gfx.h
    engines/freescape/gfx_opengl.cpp
    engines/freescape/gfx_opengl.h
    engines/freescape/gfx_tinygl.cpp
    engines/freescape/gfx_tinygl.h


diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp
index 949c417d09d..580335d3b04 100644
--- a/engines/freescape/freescape.cpp
+++ b/engines/freescape/freescape.cpp
@@ -226,7 +226,8 @@ void FreescapeEngine::centerCrossair() {
 	_currentDemoMousePosition = _crossairPosition;
 }
 
-void FreescapeEngine::checkSensors() {
+bool FreescapeEngine::checkSensors() {
+	bool frameRedrawed = false;
 	for (auto &it : _sensors) {
 		Sensor *sensor = (Sensor *)it;
 		if (sensor->isDestroyed() || sensor->isInvisible())
@@ -251,16 +252,21 @@ void FreescapeEngine::checkSensors() {
 		if (playerDetected) {
 			if ((ABS(diff.x() + ABS(diff.y())) + ABS(diff.z()) <= sensor->_firingRange) &&
 			    (_ticks % sensor->_firingInterval == 0)) {
-				drawSensorShoot(sensor);
+				frameRedrawed = true;
 				takeDamageFromSensor();
+				drawSensorShoot(sensor);
+				_gfx->flipBuffer();
+				g_system->updateScreen();
+				g_system->delayMillis(10);
 			}
 		}
 	}
+	return frameRedrawed;
 }
 
 void FreescapeEngine::drawSensorShoot(Sensor *sensor) {
 	assert(sensor);
-	_gfx->renderSensorShoot(1, sensor->getOrigin(), _viewArea);
+	_gfx->renderSensorShoot(1, sensor->getOrigin(), _position, _viewArea);
 }
 
 void FreescapeEngine::flashScreen(int backgroundColor) {
@@ -269,8 +275,6 @@ void FreescapeEngine::flashScreen(int backgroundColor) {
 	_currentArea->remapColor(_currentArea->_usualBackgroundColor, backgroundColor);
 	_currentArea->remapColor(_currentArea->_skyColor, backgroundColor);
 	drawFrame();
-	_gfx->flipBuffer();
-	g_system->updateScreen();
 	_currentArea->unremapColor(_currentArea->_usualBackgroundColor);
 	_currentArea->unremapColor(_currentArea->_skyColor);
 }
@@ -578,8 +582,11 @@ Common::Error FreescapeEngine::run() {
 	g_system->updateScreen();
 
 	while (!shouldQuit() && !endGame) {
-		checkSensors();
-		drawFrame();
+		bool frameRedrawed = checkSensors();
+
+		if (!frameRedrawed)
+			drawFrame();
+
 		if (_demoMode)
 			generateInput();
 
diff --git a/engines/freescape/freescape.h b/engines/freescape/freescape.h
index 5786b62cc82..02e1f306a26 100644
--- a/engines/freescape/freescape.h
+++ b/engines/freescape/freescape.h
@@ -301,7 +301,7 @@ public:
 	StateBits _gameStateBits;
 	virtual bool checkIfGameEnded();
 	ObjectArray _sensors;
-	void checkSensors();
+	bool checkSensors();
 	void drawSensorShoot(Sensor *sensor);
 	void takeDamageFromSensor();
 
diff --git a/engines/freescape/gfx.h b/engines/freescape/gfx.h
index 44260689783..1b5cd7b2dde 100644
--- a/engines/freescape/gfx.h
+++ b/engines/freescape/gfx.h
@@ -81,7 +81,7 @@ public:
 	virtual void freeTexture(Texture *texture) = 0;
 	virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) = 0;
 
-	virtual void renderSensorShoot(byte color, const Math::Vector3d position, const Common::Rect viewPort) = 0;
+	virtual void renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect viewPort) = 0;
 	virtual void renderPlayerShoot(byte color, const Common::Point position, const Common::Rect viewPort) = 0;
 	virtual void renderCube(const Math::Vector3d &position, const Math::Vector3d &size, Common::Array<uint8> *colours);
 	virtual void renderRectangle(const Math::Vector3d &position, const Math::Vector3d &size, Common::Array<uint8> *colours);
diff --git a/engines/freescape/gfx_opengl.cpp b/engines/freescape/gfx_opengl.cpp
index 4954609a6b9..bbb90caada2 100644
--- a/engines/freescape/gfx_opengl.cpp
+++ b/engines/freescape/gfx_opengl.cpp
@@ -168,7 +168,18 @@ void OpenGLRenderer::positionCamera(const Math::Vector3d &pos, const Math::Vecto
 	glTranslatef(-pos.x(), -pos.y(), -pos.z());
 }
 
-void OpenGLRenderer::renderSensorShoot(byte color, const Math::Vector3d position, const Common::Rect viewArea) {
+void OpenGLRenderer::renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect viewArea) {
+	glColor3ub(255, 255, 255);
+	glLineWidth(20);
+	polygonOffset(true);
+	glEnableClientState(GL_VERTEX_ARRAY);
+	copyToVertexArray(0, sensor);
+	copyToVertexArray(1, player);
+	glVertexPointer(3, GL_FLOAT, 0, _verts);
+	glDrawArrays(GL_LINES, 0, 2);
+	glDisableClientState(GL_VERTEX_ARRAY);
+	polygonOffset(false);
+	glLineWidth(1);
 }
 
 void OpenGLRenderer::renderPlayerShoot(byte color, const Common::Point position, const Common::Rect viewArea) {
diff --git a/engines/freescape/gfx_opengl.h b/engines/freescape/gfx_opengl.h
index 4c793990d75..4cefff98832 100644
--- a/engines/freescape/gfx_opengl.h
+++ b/engines/freescape/gfx_opengl.h
@@ -73,7 +73,7 @@ public:
 	void freeTexture(Texture *texture) override;
 	virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) override;
 
-	virtual void renderSensorShoot(byte color, const Math::Vector3d position, const Common::Rect viewPort) override;
+	virtual void renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect viewPort) override;
 	virtual void renderPlayerShoot(byte color, const Common::Point position, const Common::Rect viewPort) override;
 	virtual void renderFace(const Common::Array<Math::Vector3d> &vertices) override;
 
diff --git a/engines/freescape/gfx_tinygl.cpp b/engines/freescape/gfx_tinygl.cpp
index ee4709f48a2..421a8391b10 100644
--- a/engines/freescape/gfx_tinygl.cpp
+++ b/engines/freescape/gfx_tinygl.cpp
@@ -117,8 +117,16 @@ void TinyGLRenderer::positionCamera(const Math::Vector3d &pos, const Math::Vecto
 	tglTranslatef(-pos.x(), -pos.y(), -pos.z());
 }
 
-void TinyGLRenderer::renderSensorShoot(byte color, const Math::Vector3d position, const Common::Rect viewArea) {
-
+void TinyGLRenderer::renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect viewArea) {
+	tglColor3ub(255, 255, 255);
+	polygonOffset(true);
+	tglEnableClientState(TGL_VERTEX_ARRAY);
+	copyToVertexArray(0, player);
+	copyToVertexArray(1, sensor);
+	tglVertexPointer(3, TGL_FLOAT, 0, _verts);
+	tglDrawArrays(TGL_LINES, 0, 2);
+	tglDisableClientState(TGL_VERTEX_ARRAY);
+	polygonOffset(false);
 }
 
 void TinyGLRenderer::renderPlayerShoot(byte color, const Common::Point position, const Common::Rect viewArea) {
diff --git a/engines/freescape/gfx_tinygl.h b/engines/freescape/gfx_tinygl.h
index 2752f18e4c3..f358ae29cd2 100644
--- a/engines/freescape/gfx_tinygl.h
+++ b/engines/freescape/gfx_tinygl.h
@@ -59,7 +59,7 @@ public:
 	void freeTexture(Texture *texture) override;
 	virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) override;
 
-	virtual void renderSensorShoot(byte color, const Math::Vector3d position, const Common::Rect viewPort) override;
+	virtual void renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect viewPort) override;
 	virtual void renderPlayerShoot(byte color, const Common::Point position, const Common::Rect viewPort) override;
 	virtual void renderFace(const Common::Array<Math::Vector3d> &vertices) override;
 




More information about the Scummvm-git-logs mailing list