[Scummvm-git-logs] scummvm master -> 3abff67b07b36425d8abba07255227cbe7880cf7
neuromancer
noreply at scummvm.org
Sat Dec 17 22:28:58 UTC 2022
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
9eacc4f955 FREESCAPE: refactored sensor code
69735a15fb FREESCAPE: refactored frame rendering code to avoid displaying things too quickly
3abff67b07 FREESCAPE: improved shoot rendering in driller to match the original implementation
Commit: 9eacc4f9558e188218012d9bfa1cba74661681ae
https://github.com/scummvm/scummvm/commit/9eacc4f9558e188218012d9bfa1cba74661681ae
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2022-12-17T19:28:37-03:00
Commit Message:
FREESCAPE: refactored sensor code
Changed paths:
A engines/freescape/objects/sensor.cpp
engines/freescape/freescape.cpp
engines/freescape/module.mk
engines/freescape/objects/sensor.h
diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp
index 00dd9748c6d..03b1c1dd0f6 100644
--- a/engines/freescape/freescape.cpp
+++ b/engines/freescape/freescape.cpp
@@ -238,33 +238,9 @@ bool FreescapeEngine::checkSensors() {
return frameRedrawed;
for (auto &it : _sensors) {
Sensor *sensor = (Sensor *)it;
- if (sensor->isDestroyed() || sensor->isInvisible())
- continue;
-
- 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) {
- Math::Ray sight(sensor->getOrigin(), -diff);
- playerDetected = _currentArea->checkInSight(sight, diff.length());
- }
-
+ bool playerDetected = sensor->playerDetected(_position, _currentArea);
if (playerDetected) {
- if ((ABS(diff.x() + ABS(diff.y())) + ABS(diff.z()) <= sensor->_firingRange) &&
- (_ticks % sensor->_firingInterval == 0)) {
+ if (_ticks % sensor->_firingInterval == 0) {
frameRedrawed = true;
takeDamageFromSensor();
drawSensorShoot(sensor);
diff --git a/engines/freescape/module.mk b/engines/freescape/module.mk
index 7329c11c833..9b3b656ce6c 100644
--- a/engines/freescape/module.mk
+++ b/engines/freescape/module.mk
@@ -17,6 +17,7 @@ MODULE_OBJS := \
movement.o \
neo.o \
objects/geometricobject.o \
+ objects/sensor.o \
sound.o
ifdef USE_TINYGL
diff --git a/engines/freescape/objects/sensor.cpp b/engines/freescape/objects/sensor.cpp
new file mode 100644
index 00000000000..4033dbebba7
--- /dev/null
+++ b/engines/freescape/objects/sensor.cpp
@@ -0,0 +1,94 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "freescape/objects/sensor.h"
+
+namespace Freescape {
+
+Sensor::Sensor(
+ uint16 objectID_,
+ const Math::Vector3d &origin_,
+ const Math::Vector3d &rotation_,
+ byte color_,
+ byte firingInterval_,
+ uint16 firingRange_,
+ uint16 axis_,
+ uint8 flags_,
+ FCLInstructionVector condition_,
+ Common::String conditionSource_) {
+ _objectID = objectID_;
+ _origin = origin_;
+ _rotation = rotation_;
+ _size = Math::Vector3d(3, 3, 3);
+ _colours = new Common::Array<uint8>;
+ for (int i = 0; i < 6; i++)
+ _colours->push_back(color_);
+ _firingInterval = firingInterval_;
+ _firingRange = firingRange_;
+ _axis = axis_;
+ _flags = flags_;
+ _conditionSource = conditionSource_;
+ _condition = condition_;
+}
+
+Object *Sensor::duplicate() {
+ Sensor *sensor = new Sensor(_objectID, _origin, _rotation, (*_colours)[0], _firingInterval, _firingRange, _axis, _flags, _condition, _conditionSource);
+ return sensor;
+}
+
+void Sensor::draw(Freescape::Renderer *gfx) {
+ Math::Vector3d origin(_origin.x() - 1, _origin.y() - 1, _origin.z() - 1);
+ gfx->renderCube(_origin, _size, _colours);
+}
+
+bool Sensor::playerDetected(const Math::Vector3d &position, Area *area) {
+ if (isDestroyed() || isInvisible())
+ return false;
+
+ Math::Vector3d diff = _origin - position;
+ bool detected = false;
+
+ if (_axis == 0x01 && diff.x() >= 0)
+ detected = true;
+ else if (_axis == 0x02 && diff.x() <= 0)
+ detected = true;
+ else if (_axis == 0x04 && diff.y() >= 0)
+ detected = true;
+ else if (_axis == 0x08 && diff.y() <= 0)
+ detected = true;
+ else if (_axis == 0x10 && diff.z() >= 0)
+ detected = true;
+ else if (_axis == 0x20 && diff.z() <= 0)
+ detected = true;
+
+ if (detected) {
+ Math::Ray sight(_origin, -diff);
+ detected = area->checkInSight(sight, diff.length());
+ }
+
+ if (detected) {
+ detected = ABS(diff.x() + ABS(diff.y())) + ABS(diff.z()) <= _firingRange;
+ }
+
+ return detected;
+}
+
+} // End of namespace Freescape
diff --git a/engines/freescape/objects/sensor.h b/engines/freescape/objects/sensor.h
index 740dbe051ee..89c13311419 100644
--- a/engines/freescape/objects/sensor.h
+++ b/engines/freescape/objects/sensor.h
@@ -25,6 +25,7 @@
#ifndef FREESCAPE_SENSOR_H
#define FREESCAPE_SENSOR_H
+#include "freescape/area.h"
#include "freescape/objects/object.h"
#include "freescape/language/instruction.h"
@@ -42,21 +43,8 @@ public:
uint16 axis_,
uint8 flags_,
FCLInstructionVector condition_,
- Common::String conditionSource_) {
- _objectID = objectID_;
- _origin = origin_;
- _rotation = rotation_;
- _size = Math::Vector3d(3, 3, 3);
- _colours = new Common::Array<uint8>;
- for (int i = 0; i < 6; i++)
- _colours->push_back(color_);
- _firingInterval = firingInterval_;
- _firingRange = firingRange_;
- _axis = axis_;
- _flags = flags_;
- _conditionSource = conditionSource_;
- _condition = condition_;
- }
+ Common::String conditionSource_);
+
byte _firingInterval;
uint16 _firingRange;
uint16 _axis;
@@ -64,21 +52,18 @@ public:
Common::String _conditionSource;
FCLInstructionVector _condition;
- virtual ~Sensor() {
- delete _colours;
- }
+ virtual ~Sensor() { delete _colours; }
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, _axis, _flags, _condition, _conditionSource)); };
+ Object *duplicate() override;
ObjectType getType() override { return kSensorType; };
Math::Vector3d getRotation() { return _rotation; }
- void draw(Freescape::Renderer *gfx) override {
- Math::Vector3d origin(_origin.x() - 1, _origin.y() - 1, _origin.z() - 1);
- gfx->renderCube(_origin, _size, _colours);
- };
+ void draw(Freescape::Renderer *gfx) override;
+
+ bool playerDetected(const Math::Vector3d &position, Area *area);
private:
Common::Array<uint8> *_colours;
Commit: 69735a15fb8d8e644f3b8eec26e81c02fe207ca7
https://github.com/scummvm/scummvm/commit/69735a15fb8d8e644f3b8eec26e81c02fe207ca7
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2022-12-17T19:28:37-03:00
Commit Message:
FREESCAPE: refactored frame rendering code to avoid displaying things too quickly
Changed paths:
engines/freescape/freescape.cpp
engines/freescape/freescape.h
engines/freescape/games/driller.cpp
engines/freescape/movement.cpp
engines/freescape/objects/sensor.cpp
engines/freescape/objects/sensor.h
diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp
index 03b1c1dd0f6..454262b949b 100644
--- a/engines/freescape/freescape.cpp
+++ b/engines/freescape/freescape.cpp
@@ -129,7 +129,11 @@ FreescapeEngine::FreescapeEngine(OSystem *syst, const ADGameDescription *gd)
_initialCountdown = 0;
_countdown = 0;
_ticks = 0;
+ _lastTick = -1;
_frameLimiter = nullptr;
+
+ _underFireFrames = 0;
+ _shootingFrames = 0;
}
FreescapeEngine::~FreescapeEngine() {
@@ -232,25 +236,26 @@ void FreescapeEngine::centerCrossair() {
_currentDemoMousePosition = _crossairPosition;
}
-bool FreescapeEngine::checkSensors() {
- bool frameRedrawed = false;
+void FreescapeEngine::checkSensors() {
if (_disableSensors)
- return frameRedrawed;
+ return;
+
+ if (_lastTick == _ticks)
+ return;
+
+ _lastTick = _ticks;
for (auto &it : _sensors) {
Sensor *sensor = (Sensor *)it;
bool playerDetected = sensor->playerDetected(_position, _currentArea);
if (playerDetected) {
if (_ticks % sensor->_firingInterval == 0) {
- frameRedrawed = true;
+ if (_underFireFrames <= 0)
+ _underFireFrames = _gfx->_isAccelerated ? 60 : 4;
takeDamageFromSensor();
- drawSensorShoot(sensor);
- _gfx->flipBuffer();
- g_system->updateScreen();
- g_system->delayMillis(10);
}
}
+ sensor->shouldShoot(playerDetected);
}
- return frameRedrawed;
}
void FreescapeEngine::drawSensorShoot(Sensor *sensor) {
@@ -270,9 +275,6 @@ void FreescapeEngine::flashScreen(int backgroundColor) {
void FreescapeEngine::takeDamageFromSensor() {
_gameStateVars[k8bitVariableShield]--;
- int underFireColor = isDriller() && (_renderMode == Common::kRenderEGA) ? 1
- : _currentArea->_underFireBackgroundColor;
- flashScreen(underFireColor);
}
void FreescapeEngine::drawBackground() {
@@ -286,10 +288,40 @@ void FreescapeEngine::drawBackground() {
void FreescapeEngine::drawFrame() {
_gfx->updateProjectionMatrix(70.0, _nearClipPlane, _farClipPlane);
_gfx->positionCamera(_position, _position + _cameraFront);
+
+ if (_underFireFrames > 0) {
+ int underFireColor = isDriller() && (_renderMode == Common::kRenderEGA) ? 1
+ : _currentArea->_underFireBackgroundColor;
+ if (underFireColor < 16) {
+ _currentArea->remapColor(_currentArea->_usualBackgroundColor, underFireColor);
+ _currentArea->remapColor(_currentArea->_skyColor, underFireColor);
+ }
+ }
+
drawBackground();
_currentArea->draw(_gfx);
+
+ if (_underFireFrames > 0) {
+ for (auto &it : _sensors) {
+ Sensor *sensor = (Sensor *)it;
+ if (sensor->isShooting())
+ drawSensorShoot(sensor);
+ }
+ _underFireFrames--;
+ }
+
drawBorder();
drawUI();
+
+ if (_shootingFrames > 0) {
+ _gfx->setViewport(_fullscreenViewArea);
+ _gfx->renderPlayerShoot(0, _crossairPosition, _viewArea);
+ _gfx->setViewport(_viewArea);
+ _shootingFrames--;
+ }
+
+ _currentArea->unremapColor(_currentArea->_usualBackgroundColor);
+ _currentArea->unremapColor(_currentArea->_skyColor);
}
void FreescapeEngine::pressedKey(const int keycode) {}
@@ -506,10 +538,8 @@ Common::Error FreescapeEngine::run() {
endGame = false;
}
- bool frameRedrawed = checkSensors();
-
- if (!frameRedrawed)
- drawFrame();
+ checkSensors();
+ drawFrame();
if (_demoMode)
generateDemoInput();
diff --git a/engines/freescape/freescape.h b/engines/freescape/freescape.h
index 59d19661801..8ac5aba14d3 100644
--- a/engines/freescape/freescape.h
+++ b/engines/freescape/freescape.h
@@ -272,6 +272,8 @@ public:
Graphics::FrameLimiter *_frameLimiter;
Common::RenderMode _renderMode;
ColorMap _colorMap;
+ int _underFireFrames;
+ int _shootingFrames;
void drawFrame();
void flashScreen(int backgroundColor);
uint8 _colorNumber;
@@ -303,7 +305,7 @@ public:
StateBits _gameStateBits;
virtual bool checkIfGameEnded();
ObjectArray _sensors;
- bool checkSensors();
+ void checkSensors();
void drawSensorShoot(Sensor *sensor);
void takeDamageFromSensor();
@@ -324,6 +326,7 @@ public:
int _initialCountdown;
int _countdown;
int _ticks;
+ int _lastTick;
// Cheats
bool _useExtendedTimer;
diff --git a/engines/freescape/games/driller.cpp b/engines/freescape/games/driller.cpp
index 365aa913ec0..c181613a4cb 100644
--- a/engines/freescape/games/driller.cpp
+++ b/engines/freescape/games/driller.cpp
@@ -854,6 +854,8 @@ void DrillerEngine::removeDrill(Area *area) {
void DrillerEngine::initGameState() {
_flyMode = false;
_noClipMode = false;
+ _shootingFrames = 0;
+ _underFireFrames = 0;
_lastMousePos = Common::Point(0, 0);
_yaw = 0;
_pitch = 0;
diff --git a/engines/freescape/movement.cpp b/engines/freescape/movement.cpp
index 553243f6b36..e1576b774c7 100644
--- a/engines/freescape/movement.cpp
+++ b/engines/freescape/movement.cpp
@@ -63,9 +63,7 @@ void FreescapeEngine::traverseEntrance(uint16 entranceID) {
void FreescapeEngine::shoot() {
//_mixer->stopHandle(_soundFxHandle);
playSound(1, true);
- _gfx->setViewport(_fullscreenViewArea);
- _gfx->renderPlayerShoot(0, _crossairPosition, _viewArea);
- _gfx->setViewport(_viewArea);
+ _shootingFrames = _gfx->_isAccelerated ? 60 : 4;
Common::Point center(_viewArea.left + _viewArea.width() / 2, _viewArea.top + _viewArea.height() / 2);
float xoffset = _crossairPosition.x - center.x;
diff --git a/engines/freescape/objects/sensor.cpp b/engines/freescape/objects/sensor.cpp
index 4033dbebba7..b391d633324 100644
--- a/engines/freescape/objects/sensor.cpp
+++ b/engines/freescape/objects/sensor.cpp
@@ -47,6 +47,7 @@ Sensor::Sensor(
_flags = flags_;
_conditionSource = conditionSource_;
_condition = condition_;
+ _isShooting = false;
}
Object *Sensor::duplicate() {
diff --git a/engines/freescape/objects/sensor.h b/engines/freescape/objects/sensor.h
index 89c13311419..8ba7c491390 100644
--- a/engines/freescape/objects/sensor.h
+++ b/engines/freescape/objects/sensor.h
@@ -48,6 +48,7 @@ public:
byte _firingInterval;
uint16 _firingRange;
uint16 _axis;
+ bool _isShooting;
Common::String _conditionSource;
FCLInstructionVector _condition;
@@ -55,11 +56,13 @@ public:
virtual ~Sensor() { delete _colours; }
bool isDrawable() override { return true; }
bool isPlanar() override { return true; }
+ bool isShooting() { return _isShooting; }
void scale(int factor) override { _origin = _origin / factor; };
Object *duplicate() override;
ObjectType getType() override { return kSensorType; };
Math::Vector3d getRotation() { return _rotation; }
+ void shouldShoot(bool shooting) { _isShooting = shooting; }
void draw(Freescape::Renderer *gfx) override;
Commit: 3abff67b07b36425d8abba07255227cbe7880cf7
https://github.com/scummvm/scummvm/commit/3abff67b07b36425d8abba07255227cbe7880cf7
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2022-12-17T19:28:37-03:00
Commit Message:
FREESCAPE: improved shoot rendering in driller to match the original implementation
Changed paths:
engines/freescape/freescape.cpp
engines/freescape/gfx_opengl.cpp
engines/freescape/gfx_tinygl.cpp
diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp
index 454262b949b..e03044dfda6 100644
--- a/engines/freescape/freescape.cpp
+++ b/engines/freescape/freescape.cpp
@@ -310,9 +310,6 @@ void FreescapeEngine::drawFrame() {
_underFireFrames--;
}
- drawBorder();
- drawUI();
-
if (_shootingFrames > 0) {
_gfx->setViewport(_fullscreenViewArea);
_gfx->renderPlayerShoot(0, _crossairPosition, _viewArea);
@@ -320,6 +317,9 @@ void FreescapeEngine::drawFrame() {
_shootingFrames--;
}
+ drawBorder();
+ drawUI();
+
_currentArea->unremapColor(_currentArea->_usualBackgroundColor);
_currentArea->unremapColor(_currentArea->_skyColor);
}
diff --git a/engines/freescape/gfx_opengl.cpp b/engines/freescape/gfx_opengl.cpp
index 43dd0f16b46..dfae983809e 100644
--- a/engines/freescape/gfx_opengl.cpp
+++ b/engines/freescape/gfx_opengl.cpp
@@ -198,20 +198,17 @@ void OpenGLRenderer::renderPlayerShoot(byte color, const Common::Point position,
glColor3ub(r, g, b);
- int viewPort[4];
- glGetIntegerv(GL_VIEWPORT, viewPort);
-
- glLineWidth(10); // It will not work in every OpenGL implementation since the
+ glLineWidth(5); // It will not work in every OpenGL implementation since the
// spec doesn't require support for line widths other than 1
glEnableClientState(GL_VERTEX_ARRAY);
- copyToVertexArray(0, Math::Vector3d(viewArea.left, viewArea.height() + viewArea.top - 1, 0));
+ copyToVertexArray(0, Math::Vector3d(viewArea.left, viewArea.height() + viewArea.top, 0));
copyToVertexArray(1, Math::Vector3d(position.x, position.y, 0));
- copyToVertexArray(2, Math::Vector3d(viewArea.left, viewArea.height() + viewArea.top - 1, 0));
+ copyToVertexArray(2, Math::Vector3d(viewArea.left, viewArea.height() + viewArea.top + 3, 0));
copyToVertexArray(3, Math::Vector3d(position.x, position.y, 0));
- copyToVertexArray(4, Math::Vector3d(viewArea.right, viewArea.width() - viewArea.bottom, 0));
+ copyToVertexArray(4, Math::Vector3d(viewArea.right, viewArea.height() + viewArea.top, 0));
copyToVertexArray(5, Math::Vector3d(position.x, position.y, 0));
- copyToVertexArray(6, Math::Vector3d(viewArea.right, viewArea.width() - viewArea.bottom, 0));
+ copyToVertexArray(6, Math::Vector3d(viewArea.right, viewArea.height() + viewArea.top + 3, 0));
copyToVertexArray(7, Math::Vector3d(position.x, position.y, 0));
glVertexPointer(3, GL_FLOAT, 0, _verts);
diff --git a/engines/freescape/gfx_tinygl.cpp b/engines/freescape/gfx_tinygl.cpp
index 0af00934fa3..fd599676509 100644
--- a/engines/freescape/gfx_tinygl.cpp
+++ b/engines/freescape/gfx_tinygl.cpp
@@ -148,14 +148,14 @@ void TinyGLRenderer::renderPlayerShoot(byte color, const Common::Point position,
tglGetIntegerv(TGL_VIEWPORT, viewPort);
tglEnableClientState(TGL_VERTEX_ARRAY);
- copyToVertexArray(0, Math::Vector3d(viewArea.left, viewArea.height() + viewArea.top - 1, 0));
+ copyToVertexArray(0, Math::Vector3d(viewArea.left, viewArea.height() + viewArea.top, 0));
copyToVertexArray(1, Math::Vector3d(position.x, position.y, 0));
- copyToVertexArray(2, Math::Vector3d(viewArea.left, viewArea.height() + viewArea.top - 1, 0));
+ copyToVertexArray(2, Math::Vector3d(viewArea.left, viewArea.height() + viewArea.top + 3, 0));
copyToVertexArray(3, Math::Vector3d(position.x, position.y, 0));
- copyToVertexArray(4, Math::Vector3d(viewArea.right, viewArea.width() - viewArea.bottom, 0));
+ copyToVertexArray(4, Math::Vector3d(viewArea.right, viewArea.height() + viewArea.top, 0));
copyToVertexArray(5, Math::Vector3d(position.x, position.y, 0));
- copyToVertexArray(6, Math::Vector3d(viewArea.right, viewArea.width() - viewArea.bottom, 0));
+ copyToVertexArray(6, Math::Vector3d(viewArea.right, viewArea.height() + viewArea.top + 3, 0));
copyToVertexArray(7, Math::Vector3d(position.x, position.y, 0));
tglVertexPointer(3, TGL_FLOAT, 0, _verts);
More information about the Scummvm-git-logs
mailing list