[Scummvm-git-logs] scummvm master -> 82c6ca435f339643e8de14d6c29ecd849a1c397a

neuromancer noreply at scummvm.org
Mon Aug 14 07:59:06 UTC 2023


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:
dd1c206a57 FREESCAPE: refactored animation support to use a structure
ba4cb6a2f6 FREESCAPE: avoid rendering invisible objects in groups
82c6ca435f FREESCAPE: better implementation for animation ticks


Commit: dd1c206a579ef266c1aedf71af24033c0c547c9e
    https://github.com/scummvm/scummvm/commit/dd1c206a579ef266c1aedf71af24033c0c547c9e
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2023-08-14T09:57:41+02:00

Commit Message:
FREESCAPE: refactored animation support to use a structure

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


diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp
index 1e30bee8030..dd582881e9a 100644
--- a/engines/freescape/freescape.cpp
+++ b/engines/freescape/freescape.cpp
@@ -34,6 +34,8 @@
 
 namespace Freescape {
 
+FreescapeEngine *g_freescape;
+
 FreescapeEngine::FreescapeEngine(OSystem *syst, const ADGameDescription *gd)
 	: Engine(syst), _gameDescription(gd), _gfx(nullptr) {
 	if (!ConfMan.hasKey("render_mode") || ConfMan.get("render_mode").empty())
@@ -157,6 +159,8 @@ FreescapeEngine::FreescapeEngine(OSystem *syst, const ADGameDescription *gd)
 
 	_maxShield = 63;
 	_maxEnergy = 63;
+
+	g_freescape = this;
 }
 
 FreescapeEngine::~FreescapeEngine() {
diff --git a/engines/freescape/loaders/8bitBinaryLoader.cpp b/engines/freescape/loaders/8bitBinaryLoader.cpp
index d0c4b93fc4a..5e2f52db0f1 100644
--- a/engines/freescape/loaders/8bitBinaryLoader.cpp
+++ b/engines/freescape/loaders/8bitBinaryLoader.cpp
@@ -84,6 +84,7 @@ Common::Array<uint16> FreescapeEngine::readArray(Common::SeekableReadStream *fil
 
 Group *FreescapeEngine::load8bitGroup(Common::SeekableReadStream *file, byte rawFlagsAndType) {
 	debugC(1, kFreescapeDebugParser, "Object of type 'group'");
+	Common::Array<AnimationOpcode *> animation;
 	Common::Array<uint16> groupObjects = readArray(file, 6);
 
 	// object ID
@@ -116,19 +117,19 @@ Group *FreescapeEngine::load8bitGroup(Common::SeekableReadStream *file, byte raw
 	Common::Array<uint16> groupOperations;
 	Common::Array<Math::Vector3d> groupPositions;
 	while (byteSizeOfObject > 0) {
-		uint16 operation = 0;
+		uint16 opcode = 0;
 		if (isAmiga() || isAtariST())
-			operation = readField(file, 16);
+			opcode = readField(file, 16);
 		else
-			operation = readField(file, 8);
+			opcode = readField(file, 8);
+
+		AnimationOpcode* operation = new AnimationOpcode(opcode);
 
 		byteSizeOfObject--;
-		Math::Vector3d position;
-		if (operation == 0x80) {
+		if (opcode == 0x80) {
 			debugC(1, kFreescapeDebugParser, "Group operation rewind");
-		} else if (operation == 0x01) {
+		} else if (opcode == 0x01) {
 			debugC(1, kFreescapeDebugParser, "Group operation script execution");
-			FCLInstructionVector instructions;
 			// get the length
 			uint32 lengthOfCondition = readField(file, 8);
 			assert(lengthOfCondition > 0);
@@ -136,31 +137,29 @@ Group *FreescapeEngine::load8bitGroup(Common::SeekableReadStream *file, byte raw
 			debugC(1, kFreescapeDebugParser, "Length of condition: %d at %lx", lengthOfCondition, long(file->pos()));
 			// get the condition
 			Common::Array<uint16> conditionArray = readArray(file, lengthOfCondition);
-			Common::String conditionSource = detokenise8bitCondition(conditionArray, instructions, isAmiga() || isAtariST());
-			debugC(1, kFreescapeDebugParser, "%s", conditionSource.c_str());
+			operation->conditionSource = detokenise8bitCondition(conditionArray, operation->condition, isAmiga() || isAtariST());
+			debugC(1, kFreescapeDebugParser, "%s", operation->conditionSource.c_str());
 			byteSizeOfObject = byteSizeOfObject - lengthOfCondition;
 		} else {
 			if (byteSizeOfObject >= 3) {
-				position.x() = readField(file, 8);
-				position.y() = readField(file, 8);
-				position.z() = readField(file, 8);
-				debugC(1, kFreescapeDebugParser, "Group operation %d move to: %f %f %f", operation, position.x(), position.y(), position.z());
+				operation->position.x() = readField(file, 8);
+				operation->position.y() = readField(file, 8);
+				operation->position.z() = readField(file, 8);
+				debugC(1, kFreescapeDebugParser, "Group operation %d move to: %f %f %f", opcode, operation->position.x(), operation->position.y(), operation->position.z());
 				byteSizeOfObject = byteSizeOfObject - 3;
 			} else {
 				byteSizeOfObject = 0;
 				continue;
 			}
 		}
-		groupOperations.push_back(operation);
-		groupPositions.push_back(position);
+		animation.push_back(operation);
 	}
 
 	return new Group(
 		objectID,
 		rawFlagsAndType,
 		groupObjects,
-		groupOperations,
-		groupPositions);
+		animation);
 }
 
 Object *FreescapeEngine::load8bitObject(Common::SeekableReadStream *file) {
diff --git a/engines/freescape/objects/group.cpp b/engines/freescape/objects/group.cpp
index d2cbd77efaa..c8cec768a69 100644
--- a/engines/freescape/objects/group.cpp
+++ b/engines/freescape/objects/group.cpp
@@ -27,8 +27,7 @@ namespace Freescape {
 
 Group::Group(uint16 objectID_, uint16 flags_,
 const Common::Array<uint16> objectIds_,
-const Common::Array<uint16> objectOperations_,
-const Common::Array<Math::Vector3d> objectPositions_) {
+const Common::Array<AnimationOpcode *> operations_) {
 	_objectID = objectID_;
 	_flags = flags_;
 	_scale = 0;
@@ -37,8 +36,7 @@ const Common::Array<Math::Vector3d> objectPositions_) {
 	_step = 0;
 
 	_objectIds = objectIds_;
-	_objectOperations = objectOperations_;
-	_objectPositions = objectPositions_;
+	_operations = operations_;
 
 	if (isDestroyed()) // If the object is destroyed, restore it
 		restore();
@@ -47,6 +45,11 @@ const Common::Array<Math::Vector3d> objectPositions_) {
 	makeVisible();
 }
 
+Group::~Group() {
+	for (int i = 0; i < int(_operations.size()); i++)
+		delete _operations[i];
+}
+
 void Group::linkObject(Object *obj) {
 	int objectIndex = -1;
 	for (int i = 0; i < int(_objectIds.size()) ; i++) {
@@ -68,7 +71,7 @@ void Group::linkObject(Object *obj) {
 
 void Group::assemble(int index) {
 	GeometricObject *gobj = (GeometricObject *)_objects[index];
-	Math::Vector3d position = _objectPositions[_step];
+	Math::Vector3d position = _operations[_step]->position;
 
 	if (!GeometricObject::isPolygon(gobj->getType()))
 		position = 32 * position / _scale;
@@ -89,14 +92,14 @@ void Group::run() {
 }
 
 void Group::run(int index) {
-	if (_objectOperations[_step] == 0x80) {
+	if (_operations[_step]->opcode == 0x80) {
 		_step = -1;
 		_active = false;
 		_finished = false;
-	} else if (_objectOperations[_step] == 0x01) {
-		// TODO
+	} else if (_operations[_step]->opcode == 0x01) {
+		g_freescape->executeCode(_operations[_step]->condition, false, true, false, false);
 	} else {
-		if (_objectOperations[_step] == 0x10)
+		if (_operations[_step]->opcode == 0x10)
 			if (!_active) {
 				_step = -1;
 				return;
@@ -116,7 +119,7 @@ void Group::step() {
 	if (_finished)
 		return;
 
-	if (_step < int(_objectOperations.size() - 1))
+	if (_step < int(_operations.size() - 1))
 		_step++;
 	else {
 		_finished = true;
diff --git a/engines/freescape/objects/group.h b/engines/freescape/objects/group.h
index b691d6b2899..9ab7244b146 100644
--- a/engines/freescape/objects/group.h
+++ b/engines/freescape/objects/group.h
@@ -27,12 +27,22 @@
 
 namespace Freescape {
 
+struct AnimationOpcode {
+	AnimationOpcode(uint16 opcode_) {
+		opcode = opcode_;
+	}
+	uint16 opcode;
+	Math::Vector3d position;
+	Common::String conditionSource;
+	FCLInstructionVector condition;
+};
+
 class Group : public Object {
 public:
 	Group(uint16 objectID_, uint16 flags_,
 		const Common::Array<uint16> objectIds_,
-		const Common::Array<uint16> objectOperations_,
-		const Common::Array<Math::Vector3d> objectPositions_);
+		const Common::Array<AnimationOpcode *> operations);
+	~Group();
 	void linkObject(Object *obj);
 	void assemble(int index);
 	void step();
@@ -41,8 +51,7 @@ public:
 
 	Common::Array<Object *> _objects;
 	Common::Array<Math::Vector3d> _origins;
-	Common::Array<Math::Vector3d> _objectPositions;
-	Common::Array<uint16> _objectOperations;
+	Common::Array<AnimationOpcode *> _operations;
 	Common::Array<uint16> _objectIds;
 	int _scale;
 	int _step;


Commit: ba4cb6a2f6e9a4e8ada874c4c52fa7bee3542dc8
    https://github.com/scummvm/scummvm/commit/ba4cb6a2f6e9a4e8ada874c4c52fa7bee3542dc8
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2023-08-14T09:57:41+02:00

Commit Message:
FREESCAPE: avoid rendering invisible objects in groups

Changed paths:
    engines/freescape/objects/group.cpp


diff --git a/engines/freescape/objects/group.cpp b/engines/freescape/objects/group.cpp
index c8cec768a69..e2f183503ea 100644
--- a/engines/freescape/objects/group.cpp
+++ b/engines/freescape/objects/group.cpp
@@ -63,8 +63,6 @@ void Group::linkObject(Object *obj) {
 		return;
 
 	_origins.push_back(obj->getOrigin());
-	obj->makeInitiallyVisible();
-	obj->makeVisible();
 	obj->_partOfGroup = this;
 	_objects.push_back(obj);
 }
@@ -111,7 +109,8 @@ void Group::run(int index) {
 void Group::draw(Renderer *gfx) {
 	uint32 groupSize = _objects.size();
 	for (uint32 i = 0; i < groupSize ; i++) {
-		_objects[i]->draw(gfx);
+		if (!_objects[i]->isDestroyed() && !_objects[i]->isInvisible())
+			_objects[i]->draw(gfx);
 	}
 }
 


Commit: 82c6ca435f339643e8de14d6c29ecd849a1c397a
    https://github.com/scummvm/scummvm/commit/82c6ca435f339643e8de14d6c29ecd849a1c397a
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2023-08-14T09:57:41+02:00

Commit Message:
FREESCAPE: better implementation for animation ticks

Changed paths:
    engines/freescape/area.cpp
    engines/freescape/area.h
    engines/freescape/freescape.cpp


diff --git a/engines/freescape/area.cpp b/engines/freescape/area.cpp
index ee525cecb56..d3b113cf6e0 100644
--- a/engines/freescape/area.cpp
+++ b/engines/freescape/area.cpp
@@ -93,6 +93,7 @@ Area::Area(uint16 areaID_, uint16 areaFlags_, ObjectMap *objectsByID_, ObjectMap
 	} compareObjects;
 
 	Common::sort(_drawableObjects.begin(), _drawableObjects.end(), compareObjects);
+	_lastTick = 0;
 }
 
 Area::~Area() {
@@ -222,25 +223,28 @@ void Area::resetArea() {
 }
 
 
-void Area::draw(Freescape::Renderer *gfx, uint32 ticks) {
+void Area::draw(Freescape::Renderer *gfx, uint32 animationTicks) {
+	bool runAnimation = animationTicks != _lastTick;
 	assert(_drawableObjects.size() > 0);
 	for (auto &obj : _drawableObjects) {
 		if (!obj->isDestroyed() && !obj->isInvisible()) {
 			if (obj->getType() != ObjectType::kGroupType)
 				obj->draw(gfx);
-			else
-				drawGroup(gfx, (Group *)obj, ticks);
+			else {
+				drawGroup(gfx, (Group *)obj, runAnimation);
+			}
 		}
 	}
+	_lastTick = animationTicks;
 }
 
-void Area::drawGroup(Freescape::Renderer *gfx, Group* group, uint32 ticks) {
-	if ((ticks % 10) != 0)
-		return;
-
-	group->run();
-	group->draw(gfx);
-	group->step();
+void Area::drawGroup(Freescape::Renderer *gfx, Group* group, bool runAnimation) {
+	if (runAnimation) {
+		group->run();
+		group->draw(gfx);
+		group->step();
+	} else
+		group->draw(gfx);
 }
 
 Object *Area::shootRay(const Math::Ray &ray) {
diff --git a/engines/freescape/area.h b/engines/freescape/area.h
index d887065f651..519d2152093 100644
--- a/engines/freescape/area.h
+++ b/engines/freescape/area.h
@@ -51,8 +51,8 @@ public:
 	uint8 getScale();
 	void remapColor(int index, int color);
 	void unremapColor(int index);
-	void draw(Renderer *gfx, uint32 ticks);
-	void drawGroup(Renderer *gfx, Group *group, uint32 ticks);
+	void draw(Renderer *gfx, uint32 animationTicks);
+	void drawGroup(Renderer *gfx, Group *group, bool runAnimation);
 	void show();
 
 	Object *shootRay(const Math::Ray &ray);
@@ -87,6 +87,8 @@ public:
 	uint8 _extraColor[4];
 	ColorReMap _colorRemaps;
 
+	uint32 _lastTick;
+
 private:
 	uint16 _areaID;
 	uint16 _areaFlags;
diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp
index dd582881e9a..9637adf926e 100644
--- a/engines/freescape/freescape.cpp
+++ b/engines/freescape/freescape.cpp
@@ -305,7 +305,7 @@ void FreescapeEngine::drawFrame() {
 
 	drawBackground();
 	if (!_playerWasCrushed) // Avoid rendering inside objects
-		_currentArea->draw(_gfx, _ticks);
+		_currentArea->draw(_gfx, _ticks / 10);
 
 	if (_underFireFrames > 0) {
 		for (auto &it : _sensors) {




More information about the Scummvm-git-logs mailing list