Initial commit
This commit is contained in:
6
engines/freescape/POTFILES
Normal file
6
engines/freescape/POTFILES
Normal file
@@ -0,0 +1,6 @@
|
||||
engines/freescape/metaengine.cpp
|
||||
engines/freescape/movement.cpp
|
||||
engines/freescape/games/castle/castle.cpp
|
||||
engines/freescape/games/dark/dark.cpp
|
||||
engines/freescape/games/driller/driller.cpp
|
||||
engines/freescape/games/eclipse/eclipse.cpp
|
||||
685
engines/freescape/area.cpp
Normal file
685
engines/freescape/area.cpp
Normal file
@@ -0,0 +1,685 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#include "common/algorithm.h"
|
||||
#include "common/hash-ptr.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/area.h"
|
||||
#include "freescape/objects/global.h"
|
||||
#include "freescape/sweepAABB.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
Object *Area::objectWithIDFromMap(ObjectMap *map, uint16 objectID) {
|
||||
if (!map)
|
||||
return nullptr;
|
||||
if (!map->contains(objectID))
|
||||
return nullptr;
|
||||
return (*map)[objectID];
|
||||
}
|
||||
|
||||
Object *Area::objectWithID(uint16 objectID) {
|
||||
return objectWithIDFromMap(_objectsByID, objectID);
|
||||
}
|
||||
|
||||
Object *Area::entranceWithID(uint16 objectID) {
|
||||
return objectWithIDFromMap(_entrancesByID, objectID);
|
||||
}
|
||||
|
||||
uint16 Area::getAreaID() {
|
||||
return _areaID;
|
||||
}
|
||||
|
||||
uint16 Area::getAreaFlags() {
|
||||
return _areaFlags;
|
||||
}
|
||||
|
||||
uint8 Area::getScale() {
|
||||
return _scale;
|
||||
}
|
||||
|
||||
Area::Area(uint16 areaID_, uint16 areaFlags_, ObjectMap *objectsByID_, ObjectMap *entrancesByID_, bool isCastle_) {
|
||||
_areaID = areaID_;
|
||||
_areaFlags = areaFlags_;
|
||||
_objectsByID = objectsByID_;
|
||||
_entrancesByID = entrancesByID_;
|
||||
_isCastle = isCastle_;
|
||||
|
||||
_scale = 0;
|
||||
_skyColor = 255;
|
||||
_groundColor = 255;
|
||||
_usualBackgroundColor = 255;
|
||||
_underFireBackgroundColor = 255;
|
||||
_inkColor = 255;
|
||||
_paperColor = 255;
|
||||
|
||||
_gasPocketRadius = 0;
|
||||
|
||||
// create a list of drawable objects only
|
||||
for (auto &it : *_objectsByID) {
|
||||
if (it._value->isDrawable()) {
|
||||
_drawableObjects.push_back(it._value);
|
||||
}
|
||||
}
|
||||
|
||||
// sort so that those that are planar are drawn last
|
||||
struct {
|
||||
bool operator()(Object *object1, Object *object2) {
|
||||
if (!object1->isPlanar() && object2->isPlanar())
|
||||
return true;
|
||||
if (object1->isPlanar() && !object2->isPlanar())
|
||||
return false;
|
||||
return object1->getObjectID() > object2->getObjectID();
|
||||
};
|
||||
} compareObjects;
|
||||
|
||||
Common::sort(_drawableObjects.begin(), _drawableObjects.end(), compareObjects);
|
||||
_lastTick = 0;
|
||||
}
|
||||
|
||||
Area::~Area() {
|
||||
if (_entrancesByID) {
|
||||
for (auto &it : *_entrancesByID) {
|
||||
if (!_addedObjects.contains(it._value->getObjectID()))
|
||||
delete it._value;
|
||||
}
|
||||
}
|
||||
|
||||
if (_objectsByID) {
|
||||
for (auto &it : *_objectsByID) {
|
||||
if (!_addedObjects.contains(it._value->getObjectID()))
|
||||
delete it._value;
|
||||
}
|
||||
}
|
||||
|
||||
delete _entrancesByID;
|
||||
delete _objectsByID;
|
||||
}
|
||||
|
||||
ObjectArray Area::getSensors() {
|
||||
ObjectArray sensors;
|
||||
debugC(1, kFreescapeDebugMove, "Area name: %s", _name.c_str());
|
||||
for (auto &it : *_objectsByID) {
|
||||
if (it._value->getType() == kSensorType)
|
||||
sensors.push_back(it._value);
|
||||
}
|
||||
return sensors;
|
||||
}
|
||||
|
||||
void Area::show() {
|
||||
debugC(1, kFreescapeDebugMove, "Area name: %s", _name.c_str());
|
||||
for (auto &it : *_objectsByID)
|
||||
debugC(1, kFreescapeDebugMove, "objID: %d, type: %d", it._value->getObjectID(), it._value->getType());
|
||||
|
||||
for (auto &it : *_entrancesByID)
|
||||
debugC(1, kFreescapeDebugMove, "objID: %d, type: %d (entrance)", it._value->getObjectID(), it._value->getType());
|
||||
}
|
||||
|
||||
void Area::loadObjects(Common::SeekableReadStream *stream, Area *global) {
|
||||
int objectsByIDSize = stream->readUint32LE();
|
||||
|
||||
for (int i = 0; i < objectsByIDSize; i++) {
|
||||
uint16 key = stream->readUint32LE();
|
||||
uint32 flags = stream->readUint32LE();
|
||||
float x = stream->readFloatLE();
|
||||
float y = stream->readFloatLE();
|
||||
float z = stream->readFloatLE();
|
||||
Object *obj = nullptr;
|
||||
if (!_objectsByID->contains(key))
|
||||
addObjectFromArea(key, global);
|
||||
|
||||
obj = (*_objectsByID)[key];
|
||||
assert(obj);
|
||||
obj->setObjectFlags(flags);
|
||||
obj->setOrigin(Math::Vector3d(x, y, z));
|
||||
}
|
||||
|
||||
_colorRemaps.clear();
|
||||
int colorRemapsSize = stream->readUint32LE();
|
||||
|
||||
for (int i = 0; i < colorRemapsSize; i++) {
|
||||
int src = stream->readUint32LE();
|
||||
int dst = stream->readUint32LE();
|
||||
remapColor(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
void Area::saveObjects(Common::WriteStream *stream) {
|
||||
stream->writeUint32LE(_objectsByID->size());
|
||||
|
||||
for (auto &it : *_objectsByID) {
|
||||
Object *obj = it._value;
|
||||
stream->writeUint32LE(it._key);
|
||||
stream->writeUint32LE(obj->getObjectFlags());
|
||||
stream->writeFloatLE(obj->getOrigin().x());
|
||||
stream->writeFloatLE(obj->getOrigin().y());
|
||||
stream->writeFloatLE(obj->getOrigin().z());
|
||||
}
|
||||
|
||||
stream->writeUint32LE(_colorRemaps.size());
|
||||
for (auto &it : _colorRemaps) {
|
||||
stream->writeUint32LE(it._key);
|
||||
stream->writeUint32LE(it._value);
|
||||
}
|
||||
}
|
||||
|
||||
void Area::remapColor(int index, int color) {
|
||||
_colorRemaps[index] = color;
|
||||
}
|
||||
|
||||
void Area::unremapColor(int index) {
|
||||
_colorRemaps.clear(index);
|
||||
}
|
||||
|
||||
void Area::resetAreaGroups() {
|
||||
debugC(1, kFreescapeDebugMove, "Resetting groups from area: %s", _name.c_str());
|
||||
if (_objectsByID) {
|
||||
for (auto &it : *_objectsByID) {
|
||||
Object *obj = it._value;
|
||||
|
||||
if (obj->getType() == ObjectType::kGroupType)
|
||||
((Group *)obj)->reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Area::resetArea() {
|
||||
debugC(1, kFreescapeDebugMove, "Resetting objects from area: %s", _name.c_str());
|
||||
_colorRemaps.clear();
|
||||
if (_objectsByID) {
|
||||
for (auto &it : *_objectsByID) {
|
||||
Object *obj = it._value;
|
||||
if (obj->isDestroyed())
|
||||
obj->restore();
|
||||
|
||||
if (obj->isInitiallyInvisible())
|
||||
obj->makeInvisible();
|
||||
else
|
||||
obj->makeVisible();
|
||||
}
|
||||
}
|
||||
if (_entrancesByID) {
|
||||
for (auto &it : *_entrancesByID) {
|
||||
Object *obj = it._value;
|
||||
if (obj->isDestroyed())
|
||||
obj->restore();
|
||||
|
||||
if (obj->isInitiallyInvisible())
|
||||
obj->makeInvisible();
|
||||
else
|
||||
obj->makeVisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Area::draw(Freescape::Renderer *gfx, uint32 animationTicks, Math::Vector3d camera, Math::Vector3d direction, bool insideWait) {
|
||||
bool runAnimation = animationTicks != _lastTick;
|
||||
assert(_drawableObjects.size() > 0);
|
||||
ObjectArray planarObjects;
|
||||
ObjectArray nonPlanarObjects;
|
||||
Object *floor = nullptr;
|
||||
Common::HashMap<Object *, float> sizes;
|
||||
float offset = MAX(0.15, 1.0 / _scale);
|
||||
|
||||
for (auto &obj : _drawableObjects) {
|
||||
if (!obj->isDestroyed() && !obj->isInvisible()) {
|
||||
if (obj->getObjectID() == 0 && _groundColor < 255 && _skyColor < 255) {
|
||||
floor = obj;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (obj->getType() == ObjectType::kGroupType) {
|
||||
drawGroup(gfx, (Group *)obj, runAnimation && !insideWait);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (obj->isPlanar())
|
||||
planarObjects.push_back(obj);
|
||||
else
|
||||
nonPlanarObjects.push_back(obj);
|
||||
}
|
||||
}
|
||||
|
||||
if (floor) {
|
||||
gfx->depthTesting(false);
|
||||
floor->draw(gfx);
|
||||
gfx->depthTesting(true);
|
||||
}
|
||||
|
||||
Common::HashMap<Object *, float> offsetMap;
|
||||
for (auto &planar : planarObjects)
|
||||
offsetMap[planar] = 0;
|
||||
|
||||
for (auto &planar : planarObjects) {
|
||||
Math::Vector3d centerPlanar = planar->_boundingBox.getMin() + planar->_boundingBox.getMax();
|
||||
centerPlanar /= 2;
|
||||
Math::Vector3d distance;
|
||||
for (auto &object : nonPlanarObjects) {
|
||||
if (object->_partOfGroup)
|
||||
continue;
|
||||
|
||||
distance = object->_boundingBox.distance(centerPlanar);
|
||||
if (distance.length() > 0.0001)
|
||||
continue;
|
||||
|
||||
float sizeNonPlanar = object->_boundingBox.getSize().length();
|
||||
if (sizes[planar] >= sizeNonPlanar)
|
||||
continue;
|
||||
|
||||
sizes[planar] = sizeNonPlanar;
|
||||
|
||||
if (planar->getSize().x() == 0) {
|
||||
if (object->getOrigin().x() >= centerPlanar.x())
|
||||
offsetMap[planar] = -offset;
|
||||
else
|
||||
offsetMap[planar] = offset;
|
||||
} else if (planar->getSize().y() == 0) {
|
||||
if (object->getOrigin().y() >= centerPlanar.y())
|
||||
offsetMap[planar] = -offset;
|
||||
else
|
||||
offsetMap[planar] = offset;
|
||||
} else if (planar->getSize().z() == 0) {
|
||||
if (object->getOrigin().z() >= centerPlanar.z())
|
||||
offsetMap[planar] = -offset;
|
||||
else
|
||||
offsetMap[planar] = offset;
|
||||
} else
|
||||
; //It was not really planar?!
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &planar : planarObjects) {
|
||||
Math::Vector3d centerPlanar = planar->_boundingBox.getMin() + planar->_boundingBox.getMax();
|
||||
centerPlanar /= 2;
|
||||
Math::Vector3d distance;
|
||||
for (auto &object : planarObjects) {
|
||||
if (object == planar)
|
||||
continue;
|
||||
|
||||
distance = object->_boundingBox.distance(centerPlanar);
|
||||
if (distance.length() > 0)
|
||||
continue;
|
||||
|
||||
if (planar->getSize().x() == 0) {
|
||||
if (object->getSize().x() > 0)
|
||||
continue;
|
||||
} else if (planar->getSize().y() == 0) {
|
||||
if (object->getSize().y() > 0)
|
||||
continue;
|
||||
} else if (planar->getSize().z() == 0) {
|
||||
if (object->getSize().z() > 0)
|
||||
continue;
|
||||
} else
|
||||
continue;
|
||||
|
||||
//debug("planar object %d collides with planar object %d", planar->getObjectID(), object->getObjectID());
|
||||
if (offsetMap[planar] == offsetMap[object] && offsetMap[object] != 0) {
|
||||
// Nothing to do?
|
||||
} else if (offsetMap[planar] == offsetMap[object] && offsetMap[object] == 0) {
|
||||
if (planar->getSize().x() == 0) {
|
||||
if (object->getOrigin().x() < centerPlanar.x())
|
||||
offsetMap[planar] = -offset;
|
||||
else
|
||||
offsetMap[planar] = offset;
|
||||
} else if (planar->getSize().y() == 0) {
|
||||
if (object->getOrigin().y() < centerPlanar.y())
|
||||
offsetMap[planar] = -offset;
|
||||
else
|
||||
offsetMap[planar] = offset;
|
||||
} else if (planar->getSize().z() == 0) {
|
||||
if (object->getOrigin().z() < centerPlanar.z())
|
||||
offsetMap[planar] = -offset;
|
||||
else
|
||||
offsetMap[planar] = offset;
|
||||
} else
|
||||
; //It was not really planar?!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &obj : nonPlanarObjects) {
|
||||
obj->draw(gfx);
|
||||
}
|
||||
|
||||
for (auto &pair : offsetMap) {
|
||||
pair._key->draw(gfx, pair._value);
|
||||
}
|
||||
|
||||
_lastTick = animationTicks;
|
||||
}
|
||||
|
||||
void Area::drawGroup(Freescape::Renderer *gfx, Group* group, bool runAnimation) {
|
||||
if (runAnimation) {
|
||||
group->run();
|
||||
group->draw(gfx);
|
||||
group->step();
|
||||
} else
|
||||
group->draw(gfx);
|
||||
}
|
||||
|
||||
bool Area::hasActiveGroups() {
|
||||
for (auto &obj : _drawableObjects) {
|
||||
if (obj->getType() == kGroupType) {
|
||||
Group *group = (Group *)obj;
|
||||
if (group->isActive())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Object *Area::checkCollisionRay(const Math::Ray &ray, int raySize) {
|
||||
float distance = 1.0;
|
||||
float size = 16.0 * 8192.0; // TODO: check if this is the max size
|
||||
Math::AABB boundingBox(ray.getOrigin(), ray.getOrigin());
|
||||
Object *collided = nullptr;
|
||||
for (auto &obj : _drawableObjects) {
|
||||
if (obj->getType() == kLineType)
|
||||
// If the line is not along an axis, the AABB is wildly inaccurate so we skip it
|
||||
if (((GeometricObject *)obj)->isLineButNotStraight())
|
||||
continue;
|
||||
|
||||
if (!obj->isDestroyed() && !obj->isInvisible() && obj->isGeometric()) {
|
||||
GeometricObject *gobj = (GeometricObject *)obj;
|
||||
Math::Vector3d collidedNormal;
|
||||
float collidedDistance = sweepAABB(boundingBox, gobj->_boundingBox, raySize * ray.getDirection(), collidedNormal);
|
||||
debugC(1, kFreescapeDebugMove, "reached obj id: %d with distance %f", obj->getObjectID(), collidedDistance);
|
||||
if (collidedDistance >= 1.0)
|
||||
continue;
|
||||
|
||||
if (collidedDistance == 0.0 && signbit(collidedDistance))
|
||||
continue;
|
||||
|
||||
if (collidedDistance < distance || (ABS(collidedDistance - distance) <= 0.05 && gobj->getSize().length() < size)) {
|
||||
collided = obj;
|
||||
size = gobj->getSize().length();
|
||||
distance = collidedDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return collided;
|
||||
}
|
||||
|
||||
ObjectArray Area::checkCollisions(const Math::AABB &boundingBox) {
|
||||
ObjectArray collided;
|
||||
for (auto &obj : _drawableObjects) {
|
||||
if (!obj->isDestroyed() && !obj->isInvisible() && obj->isGeometric()) {
|
||||
GeometricObject *gobj = (GeometricObject *)obj;
|
||||
if (gobj->collides(boundingBox)) {
|
||||
collided.push_back(gobj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return collided;
|
||||
}
|
||||
|
||||
bool Area::checkIfPlayerWasCrushed(const Math::AABB &boundingBox) {
|
||||
for (auto &obj : _drawableObjects) {
|
||||
if (!obj->isDestroyed() && !obj->isInvisible() && obj->getType() == kGroupType) {
|
||||
Group *group = (Group *)obj;
|
||||
if (group->collides(boundingBox)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Math::Vector3d Area::separateFromWall(const Math::Vector3d &_position) {
|
||||
Math::Vector3d position = _position;
|
||||
float sep = 8 / _scale;
|
||||
for (auto &obj : _drawableObjects) {
|
||||
if (!obj->isDestroyed() && !obj->isInvisible() && obj->isGeometric()) {
|
||||
GeometricObject *gobj = (GeometricObject *)obj;
|
||||
Math::Vector3d distance = gobj->_boundingBox.distance(position);
|
||||
if (distance.length() > 0.0001)
|
||||
continue;
|
||||
|
||||
position.z() = position.z() + sep;
|
||||
distance = gobj->_boundingBox.distance(position);
|
||||
if (distance.length() > 0.0001)
|
||||
return position;
|
||||
|
||||
position = _position;
|
||||
position.z() = position.z() - sep;
|
||||
distance = gobj->_boundingBox.distance(position);
|
||||
if (distance.length() > 0.0001)
|
||||
return position;
|
||||
|
||||
position = _position;
|
||||
position.x() = position.x() + sep;
|
||||
distance = gobj->_boundingBox.distance(position);
|
||||
if (distance.length() > 0.0001)
|
||||
return position;
|
||||
|
||||
position = _position;
|
||||
position.x() = position.x() - sep;
|
||||
distance = gobj->_boundingBox.distance(position);
|
||||
if (distance.length() > 0.0001)
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
Math::Vector3d Area::resolveCollisions(const Math::Vector3d &lastPosition_, const Math::Vector3d &newPosition_, int playerHeight) {
|
||||
Math::Vector3d position = newPosition_;
|
||||
Math::Vector3d lastPosition = lastPosition_;
|
||||
|
||||
float reductionHeight = 0.0;
|
||||
// Ugly hack to fix the collisions in tight spaces in the stores and junk room
|
||||
// for Castle Master
|
||||
if (_isCastle && _areaID == 62) {
|
||||
reductionHeight = 0.3f;
|
||||
} else if (_isCastle && _areaID == 61) {
|
||||
reductionHeight = 0.3f;
|
||||
}
|
||||
|
||||
Math::AABB boundingBox = createPlayerAABB(lastPosition, playerHeight, reductionHeight);
|
||||
|
||||
float epsilon = 1.5;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
float distance = 1.0;
|
||||
Math::Vector3d normal;
|
||||
Math::Vector3d direction = position - lastPosition;
|
||||
|
||||
for (auto &obj : _drawableObjects) {
|
||||
if (!obj->isDestroyed() && !obj->isInvisible() && obj->isGeometric()) {
|
||||
GeometricObject *gobj = (GeometricObject *)obj;
|
||||
Math::Vector3d collidedNormal;
|
||||
float collidedDistance = sweepAABB(boundingBox, gobj->_boundingBox, direction, collidedNormal);
|
||||
if (collidedDistance < distance) {
|
||||
distance = collidedDistance;
|
||||
normal = collidedNormal;
|
||||
}
|
||||
}
|
||||
}
|
||||
position = lastPosition + distance * direction + epsilon * normal;
|
||||
if (i > 1 || distance >= 1.0)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
bool Area::checkInSight(const Math::Ray &ray, float maxDistance) {
|
||||
Math::Vector3d direction = ray.getDirection();
|
||||
direction.normalize();
|
||||
GeometricObject point(kCubeType,
|
||||
0,
|
||||
0,
|
||||
Math::Vector3d(0, 0, 0),
|
||||
Math::Vector3d(maxDistance / 30, maxDistance / 30, maxDistance / 30), // size
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
FCLInstructionVector(),
|
||||
"");
|
||||
|
||||
for (int distanceMultiplier = 2; distanceMultiplier <= 10; distanceMultiplier++) {
|
||||
Math::Vector3d origin = ray.getOrigin() + distanceMultiplier * (maxDistance / 10) * direction;
|
||||
point.setOrigin(origin);
|
||||
|
||||
for (auto &obj : _drawableObjects) {
|
||||
if (obj->getType() != kSensorType && !obj->isDestroyed() && !obj->isInvisible() && obj->_boundingBox.isValid() && point.collides(obj->_boundingBox)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Area::addObject(Object *obj) {
|
||||
assert(obj);
|
||||
int id = obj->getObjectID();
|
||||
debugC(1, kFreescapeDebugParser, "Adding object %d to room %d", id, _areaID);
|
||||
assert(!_objectsByID->contains(id));
|
||||
(*_objectsByID)[id] = obj;
|
||||
if (obj->isDrawable())
|
||||
_drawableObjects.insert_at(0, obj);
|
||||
|
||||
_addedObjects[id] = obj;
|
||||
}
|
||||
|
||||
void Area::removeObject(int16 id) {
|
||||
assert(_objectsByID->contains(id));
|
||||
for (uint i = 0; i < _drawableObjects.size(); i++) {
|
||||
if (_drawableObjects[i]->getObjectID() == id) {
|
||||
_drawableObjects.remove_at(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
_objectsByID->erase(id);
|
||||
_addedObjects.erase(id);
|
||||
}
|
||||
|
||||
Common::List<int> Area::getEntranceIds() {
|
||||
Common::List<int> ids;
|
||||
for (auto &it : *_entrancesByID) {
|
||||
ids.push_back(it._key);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
void Area::addObjectFromArea(int16 id, Area *global) {
|
||||
debugC(1, kFreescapeDebugParser, "Adding object %d to room structure in area %d", id, _areaID);
|
||||
Object *obj = global->objectWithID(id);
|
||||
if (!obj) {
|
||||
assert(global->entranceWithID(id));
|
||||
obj = global->entranceWithID(id);
|
||||
obj = obj->duplicate();
|
||||
obj->scale(_scale);
|
||||
_addedObjects[id] = obj;
|
||||
(*_entrancesByID)[id] = obj;
|
||||
} else {
|
||||
obj = obj->duplicate();
|
||||
obj->scale(_scale);
|
||||
(*_objectsByID)[id] = obj;
|
||||
_addedObjects[id] = obj;
|
||||
if (obj->isDrawable()) {
|
||||
_drawableObjects.insert_at(0, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Area::addGroupFromArea(int16 id, Area *global) {
|
||||
debugC(1, kFreescapeDebugParser, "Adding group %d to room structure in area %d", id, _areaID);
|
||||
Object *obj = global->objectWithID(id);
|
||||
assert(obj);
|
||||
assert(obj->getType() == ObjectType::kGroupType);
|
||||
|
||||
addObjectFromArea(id, global);
|
||||
Group *group = (Group *)objectWithID(id);
|
||||
for (auto &it : ((Group *)obj)->_objectIds) {
|
||||
if (it == 0 || it == 0xffff)
|
||||
break;
|
||||
if (!global->objectWithID(it))
|
||||
continue;
|
||||
|
||||
if (!objectWithID(it))
|
||||
addObjectFromArea(it, global);
|
||||
group->linkObject(objectWithID(it));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Area::addFloor() {
|
||||
int id = 0;
|
||||
assert(!_objectsByID->contains(id));
|
||||
Common::Array<uint8> *gColors = new Common::Array<uint8>;
|
||||
for (int i = 0; i < 6; i++)
|
||||
gColors->push_back(_groundColor);
|
||||
|
||||
int maxSize = 10000000 / 4;
|
||||
Object *obj = (Object *)new GeometricObject(
|
||||
ObjectType::kCubeType,
|
||||
id,
|
||||
0, // flags
|
||||
Math::Vector3d(-maxSize, -3, -maxSize), // Position
|
||||
Math::Vector3d(maxSize * 4, 3, maxSize * 4), // size
|
||||
gColors,
|
||||
nullptr,
|
||||
nullptr,
|
||||
FCLInstructionVector());
|
||||
(*_objectsByID)[id] = obj;
|
||||
_drawableObjects.insert_at(0, obj);
|
||||
}
|
||||
|
||||
void Area::addStructure(Area *global) {
|
||||
if (!global || !_entrancesByID->contains(255)) {
|
||||
return;
|
||||
}
|
||||
GlobalStructure *rs = (GlobalStructure *)(*_entrancesByID)[255];
|
||||
|
||||
for (uint i = 0; i < rs->_structure.size(); i++) {
|
||||
int16 id = rs->_structure[i];
|
||||
if (id == 0)
|
||||
continue;
|
||||
|
||||
addObjectFromArea(id, global);
|
||||
}
|
||||
}
|
||||
|
||||
void Area::changeObjectID(uint16 objectID, uint16 newObjectID) {
|
||||
assert(!objectWithID(newObjectID));
|
||||
Object *obj = objectWithID(objectID);
|
||||
assert(obj);
|
||||
obj->_objectID = newObjectID;
|
||||
_addedObjects.erase(objectID);
|
||||
_addedObjects[newObjectID] = obj;
|
||||
|
||||
(*_objectsByID).erase(objectID);
|
||||
(*_objectsByID)[newObjectID] = obj;
|
||||
}
|
||||
|
||||
|
||||
bool Area::isOutside() {
|
||||
return _skyColor < 255 && _groundColor < 255;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
116
engines/freescape/area.h
Normal file
116
engines/freescape/area.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#ifndef FREESCAPE_AREA_H
|
||||
#define FREESCAPE_AREA_H
|
||||
|
||||
#include "math/ray.h"
|
||||
#include "math/vector3d.h"
|
||||
|
||||
#include "freescape/language/instruction.h"
|
||||
#include "freescape/objects/object.h"
|
||||
#include "freescape/objects/group.h"
|
||||
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
typedef Common::HashMap<uint16, Object *> ObjectMap;
|
||||
typedef Common::Array<Object *> ObjectArray;
|
||||
class Area {
|
||||
public:
|
||||
Area(uint16 areaID, uint16 areaFlags, ObjectMap *objectsByID, ObjectMap *entrancesByID, bool isCastle);
|
||||
virtual ~Area();
|
||||
|
||||
Common::String _name;
|
||||
Object *objectWithID(uint16 objectID);
|
||||
Object *entranceWithID(uint16 objectID);
|
||||
Common::List<int> getEntranceIds();
|
||||
|
||||
void changeObjectID(uint16 objectID, uint16 newObjectID);
|
||||
ObjectArray getSensors();
|
||||
uint16 getAreaID();
|
||||
uint16 getAreaFlags();
|
||||
uint8 getScale();
|
||||
void remapColor(int index, int color);
|
||||
void unremapColor(int index);
|
||||
void draw(Renderer *gfx, uint32 animationTicks, Math::Vector3d camera, Math::Vector3d direction, bool insideWait);
|
||||
void drawGroup(Renderer *gfx, Group *group, bool runAnimation);
|
||||
void show();
|
||||
|
||||
Object *checkCollisionRay(const Math::Ray &ray, int raySize);
|
||||
bool checkInSight(const Math::Ray &ray, float maxDistance);
|
||||
Math::Vector3d separateFromWall(const Math::Vector3d &position);
|
||||
ObjectArray checkCollisions(const Math::AABB &boundingBox);
|
||||
bool checkIfPlayerWasCrushed(const Math::AABB &boundingBox);
|
||||
Math::Vector3d resolveCollisions(Math::Vector3d const &lastPosition, Math::Vector3d const &newPosition, int playerHeight);
|
||||
void addObjectFromArea(int16 id, Area *global);
|
||||
void addGroupFromArea(int16 id, Area *global);
|
||||
void addObject(Object *obj);
|
||||
void addFloor();
|
||||
void addStructure(Area *global);
|
||||
void removeObject(int16 id);
|
||||
void resetArea();
|
||||
void resetAreaGroups();
|
||||
bool isOutside();
|
||||
bool hasActiveGroups();
|
||||
|
||||
Common::Array<Common::String> _conditionSources;
|
||||
Common::Array<FCLInstructionVector> _conditions;
|
||||
|
||||
// Serialization
|
||||
void saveObjects(Common::WriteStream *stream);
|
||||
void loadObjects(Common::SeekableReadStream *stream, Area *global);
|
||||
|
||||
// Driller specific
|
||||
Common::Point _gasPocketPosition;
|
||||
uint32 _gasPocketRadius;
|
||||
|
||||
// Castle Master specific
|
||||
bool _isCastle;
|
||||
|
||||
uint8 _scale;
|
||||
uint8 _skyColor;
|
||||
uint8 _groundColor;
|
||||
uint8 _usualBackgroundColor;
|
||||
uint8 _underFireBackgroundColor;
|
||||
uint8 _inkColor;
|
||||
uint8 _paperColor;
|
||||
uint8 _extraColor[4];
|
||||
ColorReMap _colorRemaps;
|
||||
|
||||
uint32 _lastTick;
|
||||
|
||||
private:
|
||||
uint16 _areaID;
|
||||
uint16 _areaFlags;
|
||||
ObjectMap *_objectsByID;
|
||||
ObjectMap *_entrancesByID;
|
||||
ObjectArray _drawableObjects;
|
||||
ObjectMap _addedObjects;
|
||||
Object *objectWithIDFromMap(ObjectMap *map, uint16 objectID);
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_AREA_H
|
||||
151
engines/freescape/assets.cpp
Normal file
151
engines/freescape/assets.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#include "common/file.h"
|
||||
#include "common/compression/unzip.h"
|
||||
#include "image/bmp.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void FreescapeEngine::loadAssets() {
|
||||
if (isDemo())
|
||||
loadAssetsDemo();
|
||||
else
|
||||
loadAssetsFullGame();
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsFullGame() {
|
||||
Common::File file;
|
||||
if (isAmiga()) {
|
||||
loadAssetsAmigaFullGame();
|
||||
} else if (isAtariST()) {
|
||||
loadAssetsAtariFullGame();
|
||||
} else if (isSpectrum()) {
|
||||
loadAssetsZXFullGame();
|
||||
} else if (isCPC()) {
|
||||
loadAssetsCPCFullGame();
|
||||
} else if (isC64()) {
|
||||
loadAssetsC64FullGame();
|
||||
} else if (isDOS()) {
|
||||
loadAssetsDOSFullGame();
|
||||
} else
|
||||
error("Invalid or unsupported render mode %s", Common::getRenderModeDescription(_renderMode));
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsDemo() {
|
||||
Common::File file;
|
||||
if (isAmiga()) {
|
||||
loadAssetsAmigaDemo();
|
||||
} else if (isAtariST()) {
|
||||
loadAssetsAtariDemo();
|
||||
} else if (isDOS()) {
|
||||
loadAssetsDOSDemo();
|
||||
} else if (isSpectrum()) {
|
||||
loadAssetsZXDemo();
|
||||
} else if (isCPC()) {
|
||||
loadAssetsCPCDemo();
|
||||
} else
|
||||
error("Unsupported demo");
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsAtariDemo() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsAmigaDemo() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsDOSDemo() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsZXDemo() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsCPCDemo() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsC64Demo() {
|
||||
}
|
||||
|
||||
|
||||
void FreescapeEngine::loadAssetsAtariFullGame() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsAmigaFullGame() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsDOSFullGame() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsZXFullGame() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsCPCFullGame() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadAssetsC64FullGame() {
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadDataBundle() {
|
||||
_dataBundle = Common::makeZipArchive(FREESCAPE_DATA_BUNDLE);
|
||||
if (!_dataBundle) {
|
||||
error("ENGINE: Couldn't load data bundle '%s'.", FREESCAPE_DATA_BUNDLE);
|
||||
}
|
||||
Common::Path versionFilename("version");
|
||||
if (!_dataBundle->hasFile(versionFilename))
|
||||
error("No version number in %s", FREESCAPE_DATA_BUNDLE);
|
||||
|
||||
Common::SeekableReadStream *versionFile = _dataBundle->createReadStreamForMember(versionFilename);
|
||||
char *versionData = (char *)malloc((versionFile->size() + 1) * sizeof(char));
|
||||
versionFile->read(versionData, versionFile->size());
|
||||
versionData[versionFile->size()] = '\0';
|
||||
Common::String expectedVersion = "3";
|
||||
if (versionData != expectedVersion)
|
||||
error("Unexpected version number for freescape.dat: expecting '%s' but found '%s'", expectedVersion.c_str(), versionData);
|
||||
free(versionData);
|
||||
}
|
||||
|
||||
Graphics::Surface *FreescapeEngine::loadBundledImage(const Common::String &name, bool appendRenderMode) {
|
||||
Image::BitmapDecoder decoder;
|
||||
Common::Path bmpFilename(name + ".bmp");
|
||||
|
||||
if (appendRenderMode)
|
||||
bmpFilename = Common::Path(name + "_" + Common::getRenderModeDescription(_renderMode) + ".bmp");
|
||||
|
||||
debugC(1, kFreescapeDebugParser, "Loading %s from bundled archive", bmpFilename.toString().c_str());
|
||||
if (!_dataBundle->hasFile(bmpFilename))
|
||||
error("Failed to open file %s from bundle", bmpFilename.toString().c_str());
|
||||
|
||||
Common::SeekableReadStream *bmpFile = _dataBundle->createReadStreamForMember(bmpFilename);
|
||||
if (!decoder.loadStream(*bmpFile))
|
||||
error("Failed to decode bmp file %s from bundle", bmpFilename.toString().c_str());
|
||||
|
||||
Graphics::Surface *surface = new Graphics::Surface();
|
||||
surface->copyFrom(*decoder.getSurface());
|
||||
decoder.destroy();
|
||||
return surface;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
3
engines/freescape/configure.engine
Normal file
3
engines/freescape/configure.engine
Normal file
@@ -0,0 +1,3 @@
|
||||
# This file is included from the main "configure" script
|
||||
# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] [components]
|
||||
add_engine freescape "Freescape" yes "" "" "highres 16bit 3d" "tinygl sid_audio"
|
||||
4
engines/freescape/credits.pl
Normal file
4
engines/freescape/credits.pl
Normal file
@@ -0,0 +1,4 @@
|
||||
begin_section("Freescape");
|
||||
add_person("Chris Allen", "", "Sound engine programming");
|
||||
add_person("Gustavo Grieco", "neuromancer", "");
|
||||
end_section();
|
||||
210
engines/freescape/demo.cpp
Normal file
210
engines/freescape/demo.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
/* 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/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void FreescapeEngine::generateDemoInput() {
|
||||
if (_shootingFrames > 0)
|
||||
return;
|
||||
|
||||
Common::Event event;
|
||||
if (isDOS()) {
|
||||
|
||||
if (_currentDemoInputRepetition == 0) {
|
||||
_currentDemoInputRepetition = 1;
|
||||
_currentDemoInputCode = _demoData[_demoIndex++];
|
||||
if (_currentDemoInputCode & 0x80) {
|
||||
_currentDemoInputRepetition = (_currentDemoInputCode & 0x7F) /*+ 1*/;
|
||||
//if (_currentDemoInputRepetition == 1)
|
||||
// _currentDemoInputRepetition = 255;
|
||||
_currentDemoInputCode = _demoData[_demoIndex++];
|
||||
}
|
||||
}
|
||||
|
||||
if (_currentDemoInputCode >= 0x16 && _currentDemoInputCode <= 0x1a) {
|
||||
event = decodeDOSMouseEvent(_currentDemoInputCode, _currentDemoInputRepetition);
|
||||
|
||||
Common::Point resolution = _gfx->nativeResolution();
|
||||
event.mouse.x = resolution.x * event.mouse.x / _screenW;
|
||||
event.mouse.y = resolution.y * event.mouse.y / _screenH ;
|
||||
|
||||
_demoEvents.push_back(event);
|
||||
g_system->delayMillis(10);
|
||||
_currentDemoInputRepetition = 0;
|
||||
} else if (_currentDemoInputCode == 0x7f) {
|
||||
// NOP
|
||||
_currentDemoInputRepetition--;
|
||||
} else if (_currentDemoInputCode == 0x0) {
|
||||
_forceEndGame = true;
|
||||
} else {
|
||||
event = Common::Event();
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = (Common::KeyCode)decodeDOSKey(_currentDemoInputCode);
|
||||
event.customType = 0xde00;
|
||||
_demoEvents.push_back(event);
|
||||
debugC(1, kFreescapeDebugMove, "Pushing key: %x with repetition %d", event.kbd.keycode, _currentDemoInputRepetition);
|
||||
g_system->delayMillis(100);
|
||||
_currentDemoInputRepetition--;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int mouseX = _demoData[_demoIndex++] << 1;
|
||||
int mouseY = _demoData[_demoIndex++];
|
||||
debugC(1, kFreescapeDebugMove, "Mouse moved to: %d, %d", mouseX, mouseY);
|
||||
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
event.mouse = Common::Point(mouseX, mouseY);
|
||||
//event.mouse.x = float(event.mouse.x) * g_system->getWidth() / _screenW ;
|
||||
//event.mouse.y = float(event.mouse.y) * g_system->getHeight() / _screenH ;
|
||||
|
||||
byte nextKeyCode = _demoData[_demoIndex++];
|
||||
|
||||
if (nextKeyCode == 0x30) {
|
||||
Common::Event spaceEvent;
|
||||
spaceEvent.type = Common::EVENT_CUSTOM_ENGINE_ACTION_START;
|
||||
spaceEvent.customType = kActionChangeMode;
|
||||
|
||||
_demoEvents.push_back(spaceEvent);
|
||||
_demoEvents.push_back(event); // Mouse pointer is moved
|
||||
|
||||
event.type = Common::EVENT_LBUTTONDOWN; // Keep same event fields
|
||||
event.customType = 0;
|
||||
_demoEvents.push_back(event); // Mouse is clicked
|
||||
_demoEvents.push_back(spaceEvent);
|
||||
nextKeyCode = _demoData[_demoIndex++];
|
||||
}
|
||||
|
||||
while (nextKeyCode != 0) {
|
||||
event = Common::Event();
|
||||
event.type = Common::EVENT_CUSTOM_ENGINE_ACTION_START;
|
||||
event.customType = decodeAmigaAtariKey(nextKeyCode);
|
||||
debugC(1, kFreescapeDebugMove, "Pushing key: %x", event.kbd.keycode);
|
||||
|
||||
_demoEvents.push_back(event);
|
||||
nextKeyCode = _demoData[_demoIndex++];
|
||||
}
|
||||
assert(!nextKeyCode);
|
||||
g_system->delayMillis(100);
|
||||
}
|
||||
|
||||
Common::Event FreescapeEngine::decodeDOSMouseEvent(int index, int repetition) {
|
||||
Common::Event event;
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
event.customType = 0xde00;
|
||||
switch (index) {
|
||||
case 0x16:
|
||||
assert(repetition == 1);
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
break;
|
||||
case 0x17:
|
||||
_currentDemoMousePosition.x += repetition;
|
||||
break;
|
||||
case 0x18:
|
||||
_currentDemoMousePosition.x -= repetition;
|
||||
break;
|
||||
case 0x19:
|
||||
_currentDemoMousePosition.y += repetition;
|
||||
break;
|
||||
case 0x1a:
|
||||
_currentDemoMousePosition.y -= repetition;
|
||||
break;
|
||||
default:
|
||||
error("Unreachable");
|
||||
}
|
||||
event.mouse = _currentDemoMousePosition;
|
||||
return event;
|
||||
}
|
||||
|
||||
int FreescapeEngine::decodeAmigaAtariKey(int index) {
|
||||
switch (index) {
|
||||
case 0x41:
|
||||
return kActionIncreaseAngle;
|
||||
case 0x44:
|
||||
return kActionDeployDrillingRig;
|
||||
case 0x46:
|
||||
return kActionLowerOrFlyDown;
|
||||
case 0x4c:
|
||||
return kActionRotateDown;
|
||||
case 0x4e:
|
||||
return kActionRollLeft;
|
||||
case 0x50:
|
||||
return kActionRotateUp;
|
||||
case 0x52:
|
||||
return kActionRiseOrFlyUp;
|
||||
case 0x53:
|
||||
return kActionIncreaseStepSize;
|
||||
case 0x55:
|
||||
return kActionTurnBack;
|
||||
case 0x58:
|
||||
return kActionRotateRight;
|
||||
case 0x5a:
|
||||
return kActionDecreaseAngle;
|
||||
case 0x5f:
|
||||
return kActionUnknownKey;
|
||||
case 0x96:
|
||||
return kActionMoveUp;
|
||||
case 0x97:
|
||||
return kActionMoveDown;
|
||||
case 0x98:
|
||||
return kActionRotateRight; // Right
|
||||
case 0x99:
|
||||
return kActionRotateLeft; // Left
|
||||
default:
|
||||
error("Invalid key index: %x", index);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FreescapeEngine::decodeDOSKey(int index) {
|
||||
switch (index) {
|
||||
case 1:
|
||||
return Common::KEYCODE_r;
|
||||
case 2:
|
||||
return Common::KEYCODE_f;
|
||||
case 3:
|
||||
return Common::KEYCODE_UP;
|
||||
case 4:
|
||||
return Common::KEYCODE_DOWN;
|
||||
case 5:
|
||||
return Common::KEYCODE_q;
|
||||
case 6:
|
||||
return Common::KEYCODE_w;
|
||||
case 7:
|
||||
return Common::KEYCODE_p;
|
||||
case 8:
|
||||
return Common::KEYCODE_l;
|
||||
case 11:
|
||||
return Common::KEYCODE_a;
|
||||
case 30:
|
||||
return Common::KEYCODE_SPACE;
|
||||
case 40:
|
||||
return Common::KEYCODE_d;
|
||||
default:
|
||||
error("Invalid key index: %x", index);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
1214
engines/freescape/detection.cpp
Normal file
1214
engines/freescape/detection.cpp
Normal file
File diff suppressed because it is too large
Load Diff
43
engines/freescape/detection.h
Normal file
43
engines/freescape/detection.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_DETECTION_H
|
||||
#define FREESCAPE_DETECTION_H
|
||||
|
||||
// Engine options
|
||||
#define GAMEOPTION_PRERECORDED_SOUNDS GUIO_GAMEOPTIONS1
|
||||
#define GAMEOPTION_EXTENDED_TIMER GUIO_GAMEOPTIONS2
|
||||
#define GAMEOPTION_DISABLE_DEMO_MODE GUIO_GAMEOPTIONS3
|
||||
#define GAMEOPTION_DISABLE_SENSORS GUIO_GAMEOPTIONS4
|
||||
#define GAMEOPTION_DISABLE_FALLING GUIO_GAMEOPTIONS5
|
||||
#define GAMEOPTION_INVERT_Y GUIO_GAMEOPTIONS6
|
||||
#define GAMEOPTION_AUTHENTIC_GRAPHICS GUIO_GAMEOPTIONS7
|
||||
#define GAMEOPTION_MODERN_MOVEMENT GUIO_GAMEOPTIONS10
|
||||
|
||||
// Driller options
|
||||
#define GAMEOPTION_AUTOMATIC_DRILLING GUIO_GAMEOPTIONS8
|
||||
|
||||
// Castle Master options
|
||||
|
||||
#define GAMEOPTION_TRAVEL_ROCK GUIO_GAMEOPTIONS9
|
||||
|
||||
|
||||
#endif
|
||||
129
engines/freescape/doodle.cpp
Normal file
129
engines/freescape/doodle.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "common/file.h"
|
||||
#include "common/stream.h"
|
||||
#include "graphics/pixelformat.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "engines/freescape/doodle.h"
|
||||
|
||||
namespace Image {
|
||||
|
||||
DoodleDecoder::DoodleDecoder(const byte *palette) : _surface(nullptr), _palette(palette, 16) {
|
||||
}
|
||||
|
||||
DoodleDecoder::~DoodleDecoder() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void DoodleDecoder::destroy() {
|
||||
if (_surface) {
|
||||
_surface->free();
|
||||
delete _surface;
|
||||
_surface = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool DoodleDecoder::loadStream(Common::SeekableReadStream &stream) {
|
||||
// This method should not be used
|
||||
error("DoodleDecoder::loadStream - Use loadStreams instead");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DoodleDecoder::loadStreams(Common::SeekableReadStream &highresStream,
|
||||
Common::SeekableReadStream &colorStream1,
|
||||
Common::SeekableReadStream &colorStream2) {
|
||||
destroy();
|
||||
|
||||
// Check stream sizes
|
||||
if (highresStream.size() < 8002) {
|
||||
error("DoodleDecoder: Invalid high-resolution data size");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (colorStream1.size() < 1002 || colorStream2.size() < 1002) {
|
||||
error("DoodleDecoder: Invalid color data size");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip headers
|
||||
highresStream.skip(2);
|
||||
colorStream1.skip(2);
|
||||
colorStream2.skip(2);
|
||||
|
||||
// Read high-resolution data
|
||||
byte *highresData = new byte[8000];
|
||||
highresStream.read(highresData, 8000);
|
||||
|
||||
// Skip remaining header bytes in highres file
|
||||
highresStream.skip(190);
|
||||
|
||||
// Read color data
|
||||
byte *colorData1 = new byte[kColorDataSize];
|
||||
byte *colorData2 = new byte[kColorDataSize];
|
||||
|
||||
colorStream1.read(colorData1, kColorDataSize);
|
||||
colorStream2.read(colorData2, kColorDataSize);
|
||||
|
||||
int width = 320;
|
||||
int height = 200;
|
||||
|
||||
// Create surface
|
||||
_surface = new Graphics::Surface();
|
||||
_surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
|
||||
|
||||
// Process each cell
|
||||
for (int cellIdx = 0; cellIdx < 1000; ++cellIdx) {
|
||||
processDoodleCell(cellIdx, highresData, colorData1, colorData2);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
delete[] highresData;
|
||||
delete[] colorData1;
|
||||
delete[] colorData2;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DoodleDecoder::processDoodleCell(int cellIdx, const byte *highresData,
|
||||
const byte *colorData1, const byte *colorData2) {
|
||||
// Calculate cell coordinates
|
||||
int cellX = (cellIdx % 40) * 8;
|
||||
int cellY = (cellIdx / 40) * 8;
|
||||
|
||||
// Get colors for this cell
|
||||
byte color1 = colorData2[cellIdx] & 0xf;
|
||||
byte color2 = colorData1[cellIdx] >> 4;
|
||||
byte color3 = colorData1[cellIdx] & 0xf;
|
||||
|
||||
// Process each row in the cell
|
||||
for (int row = 0; row < 8; ++row) {
|
||||
byte pixelByte = highresData[cellIdx * 8 + row];
|
||||
|
||||
// Process 4 pixel pairs (8 pixels total) in multicolor mode
|
||||
for (int bit = 0; bit < 4; ++bit) {
|
||||
byte pixelPair = (pixelByte >> (6 - bit * 2)) & 0x03;
|
||||
|
||||
// Determine final color
|
||||
byte color = 0;
|
||||
switch (pixelPair) {
|
||||
case 0:
|
||||
color = 0;
|
||||
break;
|
||||
case 1:
|
||||
color = color2;
|
||||
break;
|
||||
case 2:
|
||||
color = color3;
|
||||
break;
|
||||
case 3:
|
||||
color = color1;
|
||||
break;
|
||||
}
|
||||
|
||||
// Set pixel colors (2 pixels for each pair due to multicolor mode)
|
||||
_surface->setPixel(cellX + bit * 2, cellY + row, color);
|
||||
_surface->setPixel(cellX + bit * 2 + 1, cellY + row, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Image
|
||||
59
engines/freescape/doodle.h
Normal file
59
engines/freescape/doodle.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef IMAGE_DOODLE_DECODER_H
|
||||
#define IMAGE_DOODLE_DECODER_H
|
||||
|
||||
#include "image/image_decoder.h"
|
||||
#include "common/stream.h"
|
||||
#include "graphics/palette.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
namespace Image {
|
||||
|
||||
class DoodleDecoder : public ImageDecoder {
|
||||
public:
|
||||
/**
|
||||
* Constructor for the DoodleDecoder
|
||||
* @param palette Pointer to RGB palette data (16 colors * 3 components)
|
||||
*/
|
||||
DoodleDecoder(const byte *palette);
|
||||
~DoodleDecoder() override;
|
||||
|
||||
// ImageDecoder interface
|
||||
bool loadStream(Common::SeekableReadStream &stream) override;
|
||||
void destroy() override;
|
||||
const Graphics::Surface *getSurface() const override { return _surface; }
|
||||
const Graphics::Palette &getPalette() const override { return _palette; }
|
||||
|
||||
/**
|
||||
* Load a C64 doodle image from its component streams
|
||||
* @param highresStream Stream containing high-resolution pixel data
|
||||
* @param colorStream1 Stream containing first color data file
|
||||
* @param colorStream2 Stream containing second color data file
|
||||
* @return Whether loading succeeded
|
||||
*/
|
||||
bool loadStreams(Common::SeekableReadStream &highresStream,
|
||||
Common::SeekableReadStream &colorStream1,
|
||||
Common::SeekableReadStream &colorStream2);
|
||||
|
||||
private:
|
||||
static const int kWidth = 320;
|
||||
static const int kHeight = 200;
|
||||
static const int kHeaderSize = 192;
|
||||
static const int kColorDataSize = 1000; // 40x25 color cells
|
||||
|
||||
Graphics::Surface *_surface;
|
||||
Graphics::Palette _palette;
|
||||
|
||||
/**
|
||||
* Process an 8x8 cell of the image
|
||||
* @param cellIdx Cell index (0-999)
|
||||
* @param highresData Pointer to high-resolution pixel data
|
||||
* @param colorData1 First color data array
|
||||
* @param colorData2 Second color data array
|
||||
*/
|
||||
void processDoodleCell(int cellIdx, const byte *highresData,
|
||||
const byte *colorData1, const byte *colorData2);
|
||||
};
|
||||
|
||||
} // End of namespace Image
|
||||
|
||||
#endif
|
||||
130
engines/freescape/events.cpp
Normal file
130
engines/freescape/events.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/* 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/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
EventManagerWrapper::EventManagerWrapper(Common::EventManager *delegate) :
|
||||
_delegate(delegate),
|
||||
_keyRepeatTime(0),
|
||||
_currentActionDown(kActionNone) {
|
||||
assert(delegate);
|
||||
}
|
||||
|
||||
bool EventManagerWrapper::pollEvent(Common::Event &event) {
|
||||
uint32 time = g_system->getMillis(true);
|
||||
bool gotEvent = _delegate->pollEvent(event);
|
||||
|
||||
if (gotEvent) {
|
||||
switch (event.type) {
|
||||
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
|
||||
if (event.customType == kActionEscape)
|
||||
break;
|
||||
_currentActionDown = event.customType;
|
||||
_keyRepeatTime = time + kKeyRepeatInitialDelay;
|
||||
break;
|
||||
case Common::EVENT_CUSTOM_ENGINE_ACTION_END:
|
||||
if (event.customType == kActionEscape)
|
||||
break;
|
||||
if (event.customType == _currentActionDown) {
|
||||
// Only stop firing events if it's the current key
|
||||
_currentActionDown = kActionNone;
|
||||
}
|
||||
break;
|
||||
case Common::EVENT_KEYDOWN:
|
||||
if (event.kbd == Common::KEYCODE_ESCAPE || event.kbd == Common::KEYCODE_F5)
|
||||
break;
|
||||
|
||||
// init continuous event stream
|
||||
_currentKeyDown = event.kbd;
|
||||
_keyRepeatTime = time + kKeyRepeatInitialDelay;
|
||||
break;
|
||||
|
||||
case Common::EVENT_KEYUP:
|
||||
if (event.kbd == Common::KEYCODE_ESCAPE || event.kbd == Common::KEYCODE_F5)
|
||||
break;
|
||||
|
||||
if (event.kbd.keycode == _currentKeyDown.keycode) {
|
||||
// Only stop firing events if it's the current key
|
||||
_currentKeyDown.keycode = Common::KEYCODE_INVALID;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// Check if event should be sent again (keydown)
|
||||
if (_currentKeyDown.keycode != Common::KEYCODE_INVALID && _keyRepeatTime <= time) {
|
||||
// fire event
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbdRepeat = true;
|
||||
event.kbd = _currentKeyDown;
|
||||
_keyRepeatTime = time + kKeyRepeatSustainDelay;
|
||||
return true;
|
||||
}
|
||||
if (_currentActionDown != kActionNone && _keyRepeatTime <= time) {
|
||||
event.type = Common::EVENT_CUSTOM_ENGINE_ACTION_START;
|
||||
event.kbdRepeat = true;
|
||||
event.customType = _currentActionDown;
|
||||
_keyRepeatTime = time + kKeyRepeatSustainDelay;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void EventManagerWrapper::purgeKeyboardEvents() {
|
||||
_delegate->purgeKeyboardEvents();
|
||||
_currentKeyDown.reset();
|
||||
_currentActionDown = kActionNone;
|
||||
_keyRepeatTime = 0;
|
||||
}
|
||||
|
||||
void EventManagerWrapper::purgeMouseEvents() {
|
||||
_delegate->purgeMouseEvents();
|
||||
}
|
||||
|
||||
void EventManagerWrapper::pushEvent(Common::Event &event) {
|
||||
_delegate->pushEvent(event);
|
||||
}
|
||||
|
||||
void EventManagerWrapper::clearExitEvents() {
|
||||
_delegate->resetQuit();
|
||||
//_delegate->resetReturnToLauncher();
|
||||
|
||||
}
|
||||
|
||||
bool EventManagerWrapper::isActionActive(const Common::CustomEventType &action) {
|
||||
return _currentActionDown == action;
|
||||
}
|
||||
|
||||
bool EventManagerWrapper::isKeyPressed() {
|
||||
return _currentKeyDown.keycode != Common::KEYCODE_INVALID;
|
||||
}
|
||||
|
||||
} // namespace Freescape
|
||||
238
engines/freescape/font.cpp
Normal file
238
engines/freescape/font.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
/* 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 "engines/freescape/freescape.h"
|
||||
#include "engines/freescape/font.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
Common::String shiftStr(const Common::String &str, int shift) {
|
||||
Common::String result;
|
||||
for (int i = 0; i < int(str.size()); i++) {
|
||||
int c = shift + str[i];
|
||||
assert(c < 256);
|
||||
result += char(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Common::String centerAndPadString(const Common::String &str, int size) {
|
||||
Common::String result;
|
||||
|
||||
if (int(str.size()) >= size)
|
||||
return str;
|
||||
|
||||
int padding = (size - str.size()) / 2;
|
||||
for (int i = 0; i < padding; i++)
|
||||
result += " ";
|
||||
|
||||
result += str;
|
||||
|
||||
if (int(result.size()) >= size)
|
||||
return result;
|
||||
|
||||
padding = size - result.size();
|
||||
|
||||
for (int i = 0; i < padding; i++)
|
||||
result += " ";
|
||||
return result;
|
||||
}
|
||||
|
||||
Font::Font() {
|
||||
_backgroundColor = 0;
|
||||
_secondaryColor = 0;
|
||||
_kerningOffset = 0;
|
||||
_charWidth = 0;
|
||||
_chars.clear();
|
||||
}
|
||||
|
||||
Font::Font(Common::Array<Graphics::ManagedSurface *> &chars) {
|
||||
_chars = chars;
|
||||
_backgroundColor = 0;
|
||||
_secondaryColor = 0;
|
||||
_kerningOffset = 0;
|
||||
_charWidth = 8;
|
||||
}
|
||||
|
||||
Font::~Font() {
|
||||
/*for (Graphics::ManagedSurface *surface : _chars) {
|
||||
surface->free();
|
||||
delete surface;
|
||||
}*/
|
||||
}
|
||||
|
||||
int Font::getCharWidth(uint32 chr) const {
|
||||
return _charWidth;
|
||||
}
|
||||
|
||||
int Font::getMaxCharWidth() const {
|
||||
return getCharWidth(0);
|
||||
}
|
||||
|
||||
int Font::getFontHeight() const {
|
||||
return _chars[0]->h + 1;
|
||||
}
|
||||
|
||||
void Font::setSecondaryColor(uint32 color) {
|
||||
_secondaryColor = color;
|
||||
}
|
||||
|
||||
void Font::setBackground(uint32 color) {
|
||||
_backgroundColor = color;
|
||||
}
|
||||
|
||||
void Font::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const {
|
||||
assert(chr >= 32);
|
||||
chr -= 32;
|
||||
|
||||
// Check if the character drawing is completely contained in the surface
|
||||
// Make sure you use the correct width for the character
|
||||
int height = getCharWidth(chr);
|
||||
int width = getCharWidth(chr);
|
||||
if (x < 0 || y < 0 || x + width > dst->w || y + height > dst->h) {
|
||||
//warning("drawChar: Character %d (%c) is out of bounds at (%d, %d)", chr + 32, char(chr + 32), x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface surface = Graphics::ManagedSurface();
|
||||
surface.copyFrom(*_chars[chr]);
|
||||
|
||||
uint8 rb, gb, bb;
|
||||
uint8 rp, gp, bp;
|
||||
uint8 rs, gs, bs;
|
||||
|
||||
dst->format.colorToRGB(color, rp, gp, bp);
|
||||
dst->format.colorToRGB(_secondaryColor, rs, gs, bs);
|
||||
dst->format.colorToRGB(_backgroundColor, rb, gb, bb);
|
||||
|
||||
byte palette[3][3] = {
|
||||
{ rb, gb, bb },
|
||||
{ rp, gp, bp },
|
||||
{ rs, gs, bs },
|
||||
};
|
||||
|
||||
if (surface.format != dst->format)
|
||||
surface.convertToInPlace(dst->format, (byte *)palette, 3);
|
||||
|
||||
if (_backgroundColor == dst->format.ARGBToColor(0x00, 0x00, 0x00, 0x00))
|
||||
dst->copyRectToSurfaceWithKey(surface, x, y, Common::Rect(0, 0, MIN(int(surface.w), _charWidth), surface.h), dst->format.ARGBToColor(0xFF, 0x00, 0x00, 0x00));
|
||||
else
|
||||
dst->copyRectToSurface(surface, x, y, Common::Rect(0, 0, MIN(int(surface.w), _charWidth), surface.h));
|
||||
|
||||
surface.free();
|
||||
}
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> FreescapeEngine::getChars(Common::SeekableReadStream *file, int offset, int charsNumber) {
|
||||
byte *fontBuffer = (byte *)malloc(6 * charsNumber);
|
||||
file->seek(offset);
|
||||
file->read(fontBuffer, 6 * charsNumber);
|
||||
|
||||
Common::BitArray font;
|
||||
font.set_size(48 * charsNumber); // Enough to hold characters for all platforms
|
||||
font.set_bits(fontBuffer);
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
|
||||
int sizeX = 8;
|
||||
int sizeY = 6;
|
||||
int additional = isEclipse() ? 0 : 1;
|
||||
|
||||
for (int c = 0; c < charsNumber - 1; c++) {
|
||||
int position = sizeX * sizeY * c;
|
||||
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
|
||||
int charWidth = sizeX;
|
||||
if (_renderMode == Common::kRenderHercG || isC64())
|
||||
charWidth *= 2;
|
||||
|
||||
surface->create(charWidth, sizeY, Graphics::PixelFormat::createFormatCLUT8());
|
||||
for (int j = 0; j < sizeY; j++) {
|
||||
for (int i = 0; i < sizeX; i++) {
|
||||
if (font.get(position + additional + j * 8 + i)) {
|
||||
if (_renderMode == Common::kRenderHercG || isC64()) {
|
||||
surface->setPixel(2 * (7 - i), j, 1);
|
||||
surface->setPixel(2 * (7 - i) + 1, j, 1);
|
||||
} else {
|
||||
surface->setPixel(7 - i, j, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
chars.push_back(surface);
|
||||
}
|
||||
return chars;
|
||||
}
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> FreescapeEngine::getCharsAmigaAtariInternal(int sizeX, int sizeY, int additional, int m1, int m2, Common::SeekableReadStream *file, int offset, int charsNumber) {
|
||||
|
||||
file->seek(offset);
|
||||
int fontSize = 4654;
|
||||
byte *fontBuffer = (byte *)malloc(fontSize);
|
||||
file->read(fontBuffer, fontSize);
|
||||
|
||||
Common::BitArray font;
|
||||
font.set_size(8 * fontSize);
|
||||
font.set_bits(fontBuffer);
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
|
||||
for (int c = 0; c < charsNumber - 1; c++) {
|
||||
int position = 8 * (m1 * c + 1);
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(sizeX, sizeY, Graphics::PixelFormat::createFormatCLUT8());
|
||||
for (int j = 0; j < sizeY; j++) {
|
||||
for (int i = 0; i < sizeX; i++) {
|
||||
if (font.get(position + additional + j * m2 + i + 7))
|
||||
surface->setPixel(7 - i, j, 2);
|
||||
else if (font.get(position + j * m2 + i)) {
|
||||
surface->setPixel(7 - i, j, 1);
|
||||
} else
|
||||
surface->setPixel(7 - i, j, 0);
|
||||
}
|
||||
}
|
||||
chars.push_back(surface);
|
||||
}
|
||||
free(fontBuffer);
|
||||
return chars;
|
||||
}
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> FreescapeEngine::getCharsAmigaAtari(Common::SeekableReadStream *file, int offset, int charsNumber) {
|
||||
return getCharsAmigaAtariInternal(8, 8, isEclipse() ? 0 : 1, isDriller() ? 33 : 16, isDriller() ? 32 : 16, file, offset, charsNumber);
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset) {
|
||||
Common::String ustr = str;
|
||||
if (!isEclipse())
|
||||
ustr.toUppercase();
|
||||
_font.setBackground(backColor);
|
||||
_font.drawString(surface, ustr, x, y, _screenW, fontColor);
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface, int offset) {
|
||||
Common::String ustr = str;
|
||||
ustr.toUppercase();
|
||||
_font.setBackground(backColor);
|
||||
_font.setSecondaryColor(secondaryColor);
|
||||
_font.drawString(surface, ustr, x, y, _screenW, primaryColor);
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace Freescape
|
||||
60
engines/freescape/font.h
Normal file
60
engines/freescape/font.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_FONT_H
|
||||
#define FREESCAPE_FONT_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/stream.h"
|
||||
|
||||
#include "graphics/font.h"
|
||||
#include "graphics/managed_surface.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class Font : public Graphics::Font {
|
||||
public:
|
||||
Font();
|
||||
Font(Common::Array<Graphics::ManagedSurface *> &chars);
|
||||
~Font() override;
|
||||
|
||||
void setBackground(uint32 color);
|
||||
void setSecondaryColor(uint32 color);
|
||||
int getFontHeight() const override;
|
||||
int getMaxCharWidth() const override;
|
||||
int getCharWidth(uint32 chr) const override;
|
||||
int getKerningOffset(uint32 left, uint32 right) const override { return _kerningOffset; }
|
||||
void setKernelingOffset(int offset) { _kerningOffset = offset; }
|
||||
void setCharWidth(int width) { _charWidth = width; }
|
||||
|
||||
void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
|
||||
|
||||
//const Graphics::ManagedSurface &getImageSurface() const { return _image; }
|
||||
private:
|
||||
Common::Array<Graphics::ManagedSurface *> _chars;
|
||||
uint32 _backgroundColor;
|
||||
uint32 _secondaryColor;
|
||||
int _kerningOffset;
|
||||
int _charWidth;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_FONT_H
|
||||
1308
engines/freescape/freescape.cpp
Normal file
1308
engines/freescape/freescape.cpp
Normal file
File diff suppressed because it is too large
Load Diff
652
engines/freescape/freescape.h
Normal file
652
engines/freescape/freescape.h
Normal file
@@ -0,0 +1,652 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_H
|
||||
#define FREESCAPE_H
|
||||
|
||||
#include "common/bitarray.h"
|
||||
#include "common/events.h"
|
||||
#include "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
#include "engines/advancedDetector.h"
|
||||
#include "graphics/managed_surface.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
|
||||
#include "audio/decoders/wave.h"
|
||||
#include "audio/mixer.h"
|
||||
#include "audio/softsynth/pcspk.h"
|
||||
#include "graphics/framelimiter.h"
|
||||
|
||||
#include "freescape/area.h"
|
||||
#include "freescape/font.h"
|
||||
#include "freescape/gfx.h"
|
||||
#include "freescape/objects/entrance.h"
|
||||
#include "freescape/objects/geometricobject.h"
|
||||
#include "freescape/objects/sensor.h"
|
||||
#include "freescape/sound.h"
|
||||
|
||||
namespace Common {
|
||||
class RandomSource;
|
||||
}
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class Renderer;
|
||||
|
||||
#define FREESCAPE_DATA_BUNDLE "freescape.dat"
|
||||
|
||||
enum CameraMovement {
|
||||
kForwardMovement,
|
||||
kBackwardMovement,
|
||||
kLeftMovement,
|
||||
kRightMovement
|
||||
};
|
||||
|
||||
enum FreescapeAction {
|
||||
kActionNone,
|
||||
kActionEscape,
|
||||
kActionSave,
|
||||
kActionLoad,
|
||||
kActionToggleSound,
|
||||
kActionMoveUp,
|
||||
kActionMoveDown,
|
||||
kActionMoveLeft,
|
||||
kActionMoveRight,
|
||||
kActionShoot,
|
||||
kActionActivate,
|
||||
kActionIncreaseAngle,
|
||||
kActionDecreaseAngle,
|
||||
kActionChangeStepSize,
|
||||
kActionToggleRiseLower,
|
||||
kActionRiseOrFlyUp,
|
||||
kActionLowerOrFlyDown,
|
||||
kActionChangeMode,
|
||||
kActionSkip,
|
||||
kActionFaceForward,
|
||||
kActionRotateUp,
|
||||
kActionRotateDown,
|
||||
kActionRotateLeft,
|
||||
kActionRotateRight,
|
||||
kActionTurnBack,
|
||||
kActionInfoMenu,
|
||||
kActionIncreaseStepSize,
|
||||
kActionDecreaseStepSize,
|
||||
kActionToggleFlyMode,
|
||||
kActionToggleClipMode,
|
||||
// Driller
|
||||
kActionDeployDrillingRig,
|
||||
kActionCollectDrillingRig,
|
||||
kActionRollLeft,
|
||||
kActionRollRight,
|
||||
// Total Eclipse
|
||||
kActionRest,
|
||||
// Castle
|
||||
kActionRunMode,
|
||||
kActionWalkMode,
|
||||
kActionCrawlMode,
|
||||
kActionSelectPrince,
|
||||
kActionSelectPrincess,
|
||||
kActionQuit,
|
||||
// Demo actions
|
||||
kActionUnknownKey,
|
||||
kActionWait
|
||||
};
|
||||
|
||||
typedef Common::HashMap<uint16, Area *> AreaMap;
|
||||
typedef Common::Array<byte *> ColorMap;
|
||||
typedef Common::HashMap<uint16, int32> StateVars;
|
||||
|
||||
enum {
|
||||
kFreescapeDebugMove = 1,
|
||||
kFreescapeDebugParser,
|
||||
kFreescapeDebugCode,
|
||||
kFreescapeDebugMedia,
|
||||
kFreescapeDebugGroup,
|
||||
};
|
||||
|
||||
enum {
|
||||
kFreescapeDefaultVolume = 192,
|
||||
};
|
||||
|
||||
enum GameStateControl {
|
||||
kFreescapeGameStateStart,
|
||||
kFreescapeGameStatePlaying,
|
||||
kFreescapeGameStateDemo,
|
||||
kFreescapeGameStateEnd,
|
||||
kFreescapeGameStateRestart,
|
||||
};
|
||||
|
||||
struct CGAPaletteEntry {
|
||||
int areaId;
|
||||
byte *palette;
|
||||
};
|
||||
|
||||
extern Common::String shiftStr(const Common::String &str, int shift);
|
||||
extern Common::String centerAndPadString(const Common::String &str, int size);
|
||||
|
||||
class EventManagerWrapper {
|
||||
public:
|
||||
EventManagerWrapper(Common::EventManager *delegate);
|
||||
// EventManager API
|
||||
bool pollEvent(Common::Event &event);
|
||||
void purgeKeyboardEvents();
|
||||
void purgeMouseEvents();
|
||||
void pushEvent(Common::Event &event);
|
||||
void clearExitEvents();
|
||||
bool isActionActive(const Common::CustomEventType &action);
|
||||
bool isKeyPressed();
|
||||
|
||||
private:
|
||||
// for continuous events (keyDown)
|
||||
enum {
|
||||
kKeyRepeatInitialDelay = 400,
|
||||
kKeyRepeatSustainDelay = 100
|
||||
};
|
||||
|
||||
Common::EventManager *_delegate;
|
||||
|
||||
Common::KeyState _currentKeyDown;
|
||||
Common::CustomEventType _currentActionDown;
|
||||
uint32 _keyRepeatTime;
|
||||
};
|
||||
|
||||
class FreescapeEngine : public Engine {
|
||||
|
||||
public:
|
||||
FreescapeEngine(OSystem *syst, const ADGameDescription *gd);
|
||||
~FreescapeEngine();
|
||||
|
||||
const ADGameDescription *_gameDescription;
|
||||
GameStateControl _gameStateControl;
|
||||
bool isDemo() const;
|
||||
|
||||
// Game selection
|
||||
uint32 _variant;
|
||||
Common::Language _language;
|
||||
bool isSpaceStationOblivion() { return _targetName.hasPrefix("spacestationoblivion"); }
|
||||
bool isDriller() { return _targetName.hasPrefix("driller") || _targetName.hasPrefix("spacestationoblivion"); }
|
||||
bool isDark() { return _targetName.hasPrefix("darkside"); }
|
||||
bool isEclipse() { return _targetName.hasPrefix("totaleclipse"); } // This will match Total Eclipse 1 and 2.
|
||||
bool isEclipse2() { return _targetName.hasPrefix("totaleclipse2"); }
|
||||
bool isCastle() { return _targetName.hasPrefix("castle"); }
|
||||
bool isAmiga() { return _gameDescription->platform == Common::kPlatformAmiga; }
|
||||
bool isAtariST() { return _gameDescription->platform == Common::kPlatformAtariST; }
|
||||
bool isDOS() { return _gameDescription->platform == Common::kPlatformDOS; }
|
||||
bool isSpectrum() { return _gameDescription->platform == Common::kPlatformZX; }
|
||||
bool isCPC() { return _gameDescription->platform == Common::kPlatformAmstradCPC; }
|
||||
bool isC64() { return _gameDescription->platform == Common::kPlatformC64; }
|
||||
|
||||
virtual void beforeStarting();
|
||||
Common::Error run() override;
|
||||
|
||||
// UI
|
||||
Common::Rect _viewArea;
|
||||
Common::Rect _fullscreenViewArea;
|
||||
void centerCrossair();
|
||||
|
||||
virtual void borderScreen();
|
||||
virtual void titleScreen();
|
||||
|
||||
void drawFullscreenSurface(Graphics::Surface *surface);
|
||||
virtual void loadBorder();
|
||||
virtual void processBorder();
|
||||
void waitInLoop(int maxWait);
|
||||
void drawBorder();
|
||||
void drawTitle();
|
||||
virtual void drawBackground();
|
||||
void clearBackground();
|
||||
virtual void drawUI();
|
||||
virtual void drawInfoMenu();
|
||||
void drawBorderScreenAndWait(Graphics::Surface *surface, int maxWait = INT_MAX);
|
||||
|
||||
virtual void drawCrossair(Graphics::Surface *surface);
|
||||
Graphics::ManagedSurface *_border;
|
||||
Graphics::ManagedSurface *_title;
|
||||
Graphics::ManagedSurface *_background;
|
||||
|
||||
Texture *_borderTexture;
|
||||
Texture *_titleTexture;
|
||||
Texture *_uiTexture;
|
||||
Texture *_skyTexture;
|
||||
|
||||
Common::Array<Graphics::Surface *>_indicators;
|
||||
Common::HashMap<uint16, Texture *> _borderCGAByArea;
|
||||
Common::HashMap<uint16, byte *> _paletteCGAByArea;
|
||||
|
||||
// Parsing assets
|
||||
uint8 _binaryBits;
|
||||
virtual void loadAssets();
|
||||
virtual void loadAssetsDemo();
|
||||
virtual void loadAssetsFullGame();
|
||||
|
||||
virtual void loadAssetsAtariFullGame();
|
||||
virtual void loadAssetsAtariDemo();
|
||||
|
||||
virtual void loadAssetsAmigaFullGame();
|
||||
virtual void loadAssetsAmigaDemo();
|
||||
|
||||
virtual void loadAssetsDOSFullGame();
|
||||
virtual void loadAssetsDOSDemo();
|
||||
|
||||
virtual void loadAssetsZXFullGame();
|
||||
virtual void loadAssetsZXDemo();
|
||||
|
||||
virtual void loadAssetsCPCFullGame();
|
||||
virtual void loadAssetsCPCDemo();
|
||||
|
||||
virtual void loadAssetsC64FullGame();
|
||||
virtual void loadAssetsC64Demo();
|
||||
|
||||
virtual void drawDOSUI(Graphics::Surface *surface);
|
||||
virtual void drawZXUI(Graphics::Surface *surface);
|
||||
virtual void drawCPCUI(Graphics::Surface *surface);
|
||||
virtual void drawC64UI(Graphics::Surface *surface);
|
||||
virtual void drawAmigaAtariSTUI(Graphics::Surface *surface);
|
||||
|
||||
Common::Archive *_dataBundle;
|
||||
void loadDataBundle();
|
||||
Graphics::Surface *loadBundledImage(const Common::String &name, bool appendRenderMode = true);
|
||||
byte *getPaletteFromNeoImage(Common::SeekableReadStream *stream, int offset);
|
||||
Graphics::ManagedSurface *loadAndConvertNeoImage(Common::SeekableReadStream *stream, int offset, byte *palette = nullptr);
|
||||
Graphics::ManagedSurface *loadAndConvertScrImage(Common::SeekableReadStream *stream);
|
||||
Graphics::ManagedSurface *loadAndConvertDoodleImage(Common::SeekableReadStream *bitmap, Common::SeekableReadStream *color1, Common::SeekableReadStream *color2, byte *palette);
|
||||
|
||||
void loadPalettes(Common::SeekableReadStream *file, int offset);
|
||||
byte *loadPalette(Common::SeekableReadStream *file);
|
||||
void swapPalette(uint16 areaID);
|
||||
virtual byte *findCGAPalette(uint16 levelID);
|
||||
Common::HashMap<uint16, byte *> _paletteByArea;
|
||||
void loadColorPalette();
|
||||
|
||||
// Demo
|
||||
Common::Array<byte> _demoData;
|
||||
int _demoIndex;
|
||||
int _currentDemoInputCode;
|
||||
int _currentDemoInputRepetition;
|
||||
Common::Array<Common::Event> _demoEvents;
|
||||
Common::Point _currentDemoMousePosition;
|
||||
void loadDemoData(Common::SeekableReadStream *file, int offset, int size);
|
||||
int decodeAmigaAtariKey(int code);
|
||||
int decodeDOSKey(int code);
|
||||
Common::Event decodeDOSMouseEvent(int code, int repetition);
|
||||
|
||||
uint16 readField(Common::SeekableReadStream *file, int nbits);
|
||||
uint16 readPtr(Common::SeekableReadStream *file);
|
||||
Common::Array<uint16> readArray(Common::SeekableReadStream *file, int size);
|
||||
|
||||
// 8-bit
|
||||
void load8bitBinary(Common::SeekableReadStream *file, int offset, int ncolors);
|
||||
Area *load8bitArea(Common::SeekableReadStream *file, uint16 ncolors);
|
||||
Object *load8bitObject(Common::SeekableReadStream *file);
|
||||
Group *load8bitGroup(Common::SeekableReadStream *file, byte rawFlagsAndType);
|
||||
Group *load8bitGroupV1(Common::SeekableReadStream *file, byte rawFlagsAndType);
|
||||
Group *load8bitGroupV2(Common::SeekableReadStream *file, byte rawFlagsAndType);
|
||||
|
||||
void loadGlobalObjects(Common::SeekableReadStream *file, int offset, int size);
|
||||
void renderPixels8bitBinImage(Graphics::ManagedSurface *surface, int row, int column, int bit, int count);
|
||||
|
||||
void renderPixels8bitBinCGAImage(Graphics::ManagedSurface *surface, int &i, int &j, uint8 pixels, int color);
|
||||
void renderPixels8bitBinEGAImage(Graphics::ManagedSurface *surface, int &i, int &j, uint8 pixels, int color);
|
||||
|
||||
Graphics::ManagedSurface *load8bitBinImage(Common::SeekableReadStream *file, int offset);
|
||||
void load8bitBinImageRow(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row);
|
||||
void load8bitBinImageRowIteration(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int bit);
|
||||
int execute8bitBinImageCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int pixels, int bit);
|
||||
int execute8bitBinImageSingleCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int pixels, int bit, int count);
|
||||
int execute8bitBinImageMultiCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int pixels, int bit, int count);
|
||||
|
||||
void parseAmigaAtariHeader(Common::SeekableReadStream *file);
|
||||
Common::SeekableReadStream *decryptFileAmigaAtari(const Common::Path &packed, const Common::Path &unpacker, uint32 unpackArrayOffset);
|
||||
|
||||
// Areas
|
||||
uint16 _startArea;
|
||||
uint16 _endArea;
|
||||
AreaMap _areaMap;
|
||||
Area *_currentArea;
|
||||
bool _gotoExecuted;
|
||||
Math::Vector3d _scale;
|
||||
|
||||
virtual void gotoArea(uint16 areaID, int entranceID);
|
||||
// Entrance
|
||||
uint16 _startEntrance;
|
||||
uint16 _endEntrance;
|
||||
Common::HashMap<int, const struct entrancesTableEntry *> _entranceTable;
|
||||
|
||||
// Input
|
||||
bool _demoMode;
|
||||
bool _disableDemoMode;
|
||||
bool _flyMode;
|
||||
bool _shootMode;
|
||||
bool _noClipMode;
|
||||
bool _invertY;
|
||||
|
||||
bool _smoothMovement;
|
||||
// Player movement state
|
||||
bool _moveForward;
|
||||
bool _moveBackward;
|
||||
bool _strafeLeft;
|
||||
bool _strafeRight;
|
||||
bool _moveUp;
|
||||
bool _moveDown;
|
||||
|
||||
virtual void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target);
|
||||
EventManagerWrapper *_eventManager;
|
||||
void processInput();
|
||||
void resetInput();
|
||||
void stopMovement();
|
||||
void generateDemoInput();
|
||||
virtual void pressedKey(const int keycode);
|
||||
virtual void releasedKey(const int keycode);
|
||||
Common::Point getNormalizedPosition(Common::Point position);
|
||||
virtual bool onScreenControls(Common::Point mouse);
|
||||
void updatePlayerMovement(float deltaTime);
|
||||
void updatePlayerMovementSmooth(float deltaTime);
|
||||
void updatePlayerMovementClassic(float deltaTime);
|
||||
void resolveCollisions(Math::Vector3d newPosition);
|
||||
virtual void checkIfStillInArea();
|
||||
void changePlayerHeight(int index);
|
||||
void increaseStepSize();
|
||||
void decreaseStepSize();
|
||||
void changeStepSize();
|
||||
|
||||
void changeAngle(int offset, bool wrapAround);
|
||||
bool rise();
|
||||
void lower();
|
||||
bool checkFloor(Math::Vector3d currentPosition);
|
||||
bool tryStepUp(Math::Vector3d currentPosition);
|
||||
bool tryStepDown(Math::Vector3d currentPosition);
|
||||
bool _hasFallen;
|
||||
bool _isCollidingWithWall;
|
||||
bool _isSteppingUp;
|
||||
bool _isSteppingDown;
|
||||
bool _isFalling;
|
||||
int _maxFallingDistance;
|
||||
int _maxShield;
|
||||
int _maxEnergy;
|
||||
|
||||
void rotate(float xoffset, float yoffset, float zoffset);
|
||||
// Input state
|
||||
float _lastFrame;
|
||||
|
||||
// Interaction
|
||||
void activate();
|
||||
void shoot();
|
||||
void traverseEntrance(uint16 entranceID);
|
||||
|
||||
// Euler Angles
|
||||
float _yaw;
|
||||
float _pitch;
|
||||
int _roll;
|
||||
int _angleRotationIndex;
|
||||
Common::Array<float> _angleRotations;
|
||||
|
||||
Math::Vector3d directionToVector(float pitch, float heading, bool useTable);
|
||||
void updateCamera();
|
||||
|
||||
// Camera options
|
||||
Common::Point _crossairPosition;
|
||||
float _mouseSensitivity;
|
||||
Math::Vector3d _upVector; // const
|
||||
Math::Vector3d _cameraFront, _cameraRight;
|
||||
// Spacial attributes
|
||||
Math::Vector3d _position, _rotation, _velocity;
|
||||
Math::Vector3d _lastPosition;
|
||||
int _playerHeightNumber;
|
||||
int _playerHeightMaxNumber;
|
||||
uint16 _playerHeight;
|
||||
uint16 _playerWidth;
|
||||
uint16 _playerDepth;
|
||||
uint16 _stepUpDistance;
|
||||
|
||||
int _playerStepIndex;
|
||||
Common::Array<int> _playerSteps;
|
||||
|
||||
Common::Point crossairPosToMousePos(const Common::Point &crossairPos);
|
||||
Common::Point mousePosToCrossairPos(const Common::Point &mousePos);
|
||||
void warpMouseToCrossair(void);
|
||||
|
||||
// Effects
|
||||
Common::Array<Common::String> _conditionSources;
|
||||
Common::Array<FCLInstructionVector> _conditions;
|
||||
|
||||
bool runCollisionConditions(Math::Vector3d const lastPosition, Math::Vector3d const newPosition);
|
||||
Math::Vector3d _objExecutingCodeSize;
|
||||
bool _executingGlobalCode;
|
||||
virtual void executeMovementConditions();
|
||||
bool executeObjectConditions(GeometricObject *obj, bool shot, bool collided, bool activated);
|
||||
void executeEntranceConditions(Entrance *entrance);
|
||||
void executeLocalGlobalConditions(bool shot, bool collided, bool timer);
|
||||
bool executeCode(FCLInstructionVector &code, bool shot, bool collided, bool timer, bool activated);
|
||||
|
||||
// Instructions
|
||||
bool checkConditional(FCLInstruction &instruction, bool shot, bool collided, bool timer, bool activated);
|
||||
bool checkIfGreaterOrEqual(FCLInstruction &instruction);
|
||||
bool checkIfLessOrEqual(FCLInstruction &instruction);
|
||||
void executeExecute(FCLInstruction &instruction);
|
||||
void executeIncrementVariable(FCLInstruction &instruction);
|
||||
void executeDecrementVariable(FCLInstruction &instruction);
|
||||
void executeSetVariable(FCLInstruction &instruction);
|
||||
void executeGoto(FCLInstruction &instruction);
|
||||
void executeIfThenElse(FCLInstruction &instruction);
|
||||
virtual void executeMakeInvisible(FCLInstruction &instruction);
|
||||
void executeMakeVisible(FCLInstruction &instruction);
|
||||
void executeToggleVisibility(FCLInstruction &instruction);
|
||||
virtual void executeDestroy(FCLInstruction &instruction);
|
||||
virtual void executeRedraw(FCLInstruction &instruction);
|
||||
void executeSound(FCLInstruction &instruction);
|
||||
void executeDelay(FCLInstruction &instruction);
|
||||
bool executeEndIfNotEqual(FCLInstruction &instruction);
|
||||
void executeSetBit(FCLInstruction &instruction);
|
||||
void executeClearBit(FCLInstruction &instruction);
|
||||
void executeToggleBit(FCLInstruction &instruction);
|
||||
bool executeEndIfBitNotEqual(FCLInstruction &instruction);
|
||||
bool executeEndIfVisibilityIsEqual(FCLInstruction &instruction);
|
||||
void executeSwapJet(FCLInstruction &instruction);
|
||||
virtual void executePrint(FCLInstruction &instruction);
|
||||
void executeSPFX(FCLInstruction &instruction);
|
||||
void executeStartAnim(FCLInstruction &instruction);
|
||||
|
||||
// Sound
|
||||
Audio::SoundHandle _soundFxHandle;
|
||||
Audio::SoundHandle _musicHandle;
|
||||
Audio::SoundHandle _movementSoundHandle;
|
||||
Freescape::SizedPCSpeaker *_speaker;
|
||||
|
||||
bool _syncSound;
|
||||
bool _firstSound;
|
||||
bool _usePrerecordedSounds;
|
||||
void waitForSounds();
|
||||
void stopAllSounds(Audio::SoundHandle &handle);
|
||||
bool isPlayingSound();
|
||||
void playSound(int index, bool sync, Audio::SoundHandle &handle);
|
||||
void playWav(const Common::Path &filename);
|
||||
void playMusic(const Common::Path &filename);
|
||||
void queueSoundConst(double hzFreq, int duration);
|
||||
void playSilence(int duration, bool sync);
|
||||
void playSoundConst(double hzFreq, int duration, bool sync);
|
||||
void playSoundSweepIncWL(double hzFreq1, double hzFreq2, double wlStepPerMS, int resolution, bool sync);
|
||||
uint16 playSoundDOSSpeaker(uint16 startFrequency, soundSpeakerFx *speakerFxInfo);
|
||||
void playSoundDOS(soundSpeakerFx *speakerFxInfo, bool sync, Audio::SoundHandle &handle);
|
||||
|
||||
virtual void playSoundFx(int index, bool sync);
|
||||
virtual void loadSoundsFx(Common::SeekableReadStream *file, int offset, int number);
|
||||
Common::HashMap<uint16, soundFx *> _soundsFx;
|
||||
void loadSpeakerFxDOS(Common::SeekableReadStream *file, int offsetFreq, int offsetDuration, int numberSounds);
|
||||
void loadSpeakerFxZX(Common::SeekableReadStream *file, int sfxTable, int sfxData);
|
||||
Common::HashMap<uint16, soundSpeakerFx *> _soundsSpeakerFx;
|
||||
|
||||
void playSoundZX(Common::Array<soundUnitZX> *data, Audio::SoundHandle &handle);
|
||||
Common::HashMap<uint16, Common::Array<soundUnitZX>*> _soundsSpeakerFxZX;
|
||||
int _soundIndexShoot;
|
||||
int _soundIndexCollide;
|
||||
int _soundIndexStepDown;
|
||||
int _soundIndexStepUp;
|
||||
int _soundIndexFall;
|
||||
int _soundIndexMenu;
|
||||
int _soundIndexStart;
|
||||
int _soundIndexAreaChange;
|
||||
int _soundIndexHit;
|
||||
|
||||
int _soundIndexNoShield;
|
||||
int _soundIndexNoEnergy;
|
||||
int _soundIndexFallen;
|
||||
int _soundIndexTimeout;
|
||||
int _soundIndexForceEndGame;
|
||||
int _soundIndexCrushed;
|
||||
int _soundIndexMissionComplete;
|
||||
|
||||
// Rendering
|
||||
int _screenW, _screenH;
|
||||
Renderer *_gfx;
|
||||
Graphics::FrameLimiter *_frameLimiter;
|
||||
bool _vsyncEnabled;
|
||||
Common::RenderMode _renderMode;
|
||||
ColorMap _colorMap;
|
||||
int _underFireFrames;
|
||||
int _avoidRenderingFrames;
|
||||
int _shootingFrames;
|
||||
GeometricObject *_delayedShootObject;
|
||||
void drawFrame();
|
||||
void flashScreen(int backgroundColor);
|
||||
uint8 _colorNumber;
|
||||
Math::Vector3d _scaleVector;
|
||||
float _nearClipPlane;
|
||||
float _farClipPlane;
|
||||
|
||||
// Text messages and Fonts
|
||||
void insertTemporaryMessage(const Common::String &message, int deadline);
|
||||
void getLatestMessages(Common::String &message, int &deadline);
|
||||
void clearTemporalMessages();
|
||||
Common::StringArray _temporaryMessages;
|
||||
Common::Array<int> _temporaryMessageDeadlines;
|
||||
Common::StringArray _messagesList;
|
||||
Common::String _noShieldMessage;
|
||||
Common::String _noEnergyMessage;
|
||||
Common::String _fallenMessage;
|
||||
Common::String _timeoutMessage;
|
||||
Common::String _forceEndGameMessage;
|
||||
Common::String _crushedMessage;
|
||||
Common::String _outOfReachMessage;
|
||||
Common::String _noEffectMessage;
|
||||
|
||||
void loadMessagesFixedSize(Common::SeekableReadStream *file, int offset, int size, int number);
|
||||
virtual void loadMessagesVariableSize(Common::SeekableReadStream *file, int offset, int number);
|
||||
void drawFullscreenMessageAndWait(Common::String message);
|
||||
void drawFullscreenMessage(Common::String message, uint32 front, Graphics::Surface *surface);
|
||||
|
||||
// Font loading and rendering
|
||||
void loadFonts(Common::SeekableReadStream *file, int offset);
|
||||
void loadFonts(byte *font, int charNumber);
|
||||
Common::Array<Graphics::ManagedSurface *> getChars(Common::SeekableReadStream *file, int offset, int charsNumber);
|
||||
Common::Array<Graphics::ManagedSurface *> getCharsAmigaAtariInternal(int sizeX, int sizeY, int additional, int m1, int m2, Common::SeekableReadStream *file, int offset, int charsNumber);
|
||||
Common::Array<Graphics::ManagedSurface *> getCharsAmigaAtari(Common::SeekableReadStream *file, int offset, int charsNumber);
|
||||
Common::StringArray _currentAreaMessages;
|
||||
Common::StringArray _currentEphymeralMessages;
|
||||
Font _font;
|
||||
bool _fontLoaded;
|
||||
virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0);
|
||||
virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0);
|
||||
Graphics::Surface *drawStringsInSurface(const Common::Array<Common::String> &lines, Graphics::Surface *surface);
|
||||
|
||||
// Game state
|
||||
virtual void initGameState();
|
||||
void setGameBit(int index);
|
||||
void clearGameBit(int index);
|
||||
void toggleGameBit(int index);
|
||||
uint16 getGameBit(int index);
|
||||
|
||||
StateVars _gameStateVars;
|
||||
uint32 _gameStateBits;
|
||||
void checkIfPlayerWasCrushed();
|
||||
virtual bool checkIfGameEnded();
|
||||
virtual void endGame();
|
||||
int _endGameDelayTicks;
|
||||
bool _endGameKeyPressed;
|
||||
bool _endGamePlayerEndArea;
|
||||
bool _forceEndGame;
|
||||
bool _playerWasCrushed;
|
||||
Common::HashMap<uint16, bool> _exploredAreas;
|
||||
ObjectArray _sensors;
|
||||
virtual void checkSensors();
|
||||
virtual void drawSensorShoot(Sensor *sensor);
|
||||
void takeDamageFromSensor();
|
||||
|
||||
bool hasFeature(EngineFeature f) const override;
|
||||
bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
|
||||
bool canSaveAutosaveCurrently() override { return false; }
|
||||
bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _gameStateControl == kFreescapeGameStatePlaying && _currentArea; }
|
||||
Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
|
||||
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
|
||||
virtual Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false);
|
||||
virtual Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream);
|
||||
Graphics::Surface *_savedScreen;
|
||||
|
||||
void pauseEngineIntern(bool pause) override;
|
||||
|
||||
// Timers
|
||||
bool startCountdown(uint32 delay);
|
||||
void removeTimers();
|
||||
bool _timerStarted;
|
||||
int _initialCountdown;
|
||||
int _countdown;
|
||||
int _ticks;
|
||||
int _ticksFromEnd;
|
||||
int _lastTick;
|
||||
int _lastMinute;
|
||||
|
||||
void getTimeFromCountdown(int &seconds, int &minutes, int &hours);
|
||||
virtual void updateTimeVariables();
|
||||
|
||||
// Cheats
|
||||
bool _useExtendedTimer;
|
||||
bool _disableSensors;
|
||||
bool _disableFalling;
|
||||
|
||||
// Random
|
||||
Common::RandomSource *_rnd;
|
||||
|
||||
// C64 specifics
|
||||
byte *decompressC64RLE(byte *buffer, int *size, byte marker);
|
||||
byte *_extraBuffer;
|
||||
};
|
||||
|
||||
enum GameReleaseFlags {
|
||||
GF_AMIGA_RETAIL = (1 << 0),
|
||||
GF_AMIGA_BUDGET = (1 << 1),
|
||||
GF_ZX_RETAIL = (1 << 2),
|
||||
GF_ZX_BUDGET = (1 << 3),
|
||||
GF_ZX_DISC = (1 << 4),
|
||||
GF_CPC_RETAIL = (1 << 5),
|
||||
GF_CPC_RETAIL_ALT = (1 << 6),
|
||||
GF_CPC_BUDGET = (1 << 7),
|
||||
GF_CPC_VIRTUALWORLDS = (1 << 8),
|
||||
GF_ATARI_RETAIL = (1 << 9),
|
||||
GF_ATARI_BUDGET = (1 << 10),
|
||||
GF_C64_TAPE = (1 << 11),
|
||||
GF_C64_DISC = (1 << 12),
|
||||
};
|
||||
|
||||
extern FreescapeEngine *g_freescape;
|
||||
|
||||
} // namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_H
|
||||
143
engines/freescape/games/castle/amiga.cpp
Normal file
143
engines/freescape/games/castle/amiga.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/castle/castle.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
byte kAmigaCastlePalette[16][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x44, 0x44, 0x44},
|
||||
{0x66, 0x66, 0x66},
|
||||
{0x88, 0x88, 0x88},
|
||||
{0xaa, 0xaa, 0xaa},
|
||||
{0xcc, 0xcc, 0xcc},
|
||||
{0x00, 0x00, 0x88},
|
||||
{0x66, 0xaa, 0x00},
|
||||
{0x88, 0xcc, 0x00},
|
||||
{0xcc, 0xee, 0x00},
|
||||
{0xee, 0xee, 0x66},
|
||||
{0x44, 0x88, 0x00},
|
||||
{0xee, 0xaa, 0x00},
|
||||
{0xcc, 0x44, 0x00},
|
||||
{0x88, 0x44, 0x00},
|
||||
{0xee, 0xee, 0xee},
|
||||
};
|
||||
|
||||
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesVertical(Common::SeekableReadStream *file, int widthInBytes, int height) {
|
||||
Graphics::ManagedSurface *surface;
|
||||
surface = new Graphics::ManagedSurface();
|
||||
surface->create(widthInBytes * 8 / 4, height, Graphics::PixelFormat::createFormatCLUT8());
|
||||
surface->fillRect(Common::Rect(0, 0, widthInBytes * 8 / 4, height), 0);
|
||||
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 0);
|
||||
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 1);
|
||||
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 2);
|
||||
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 3);
|
||||
return surface;
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesInternalVertical(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, int plane) {
|
||||
byte *colors = (byte *)malloc(sizeof(byte) * height * width);
|
||||
file->read(colors, height * width);
|
||||
|
||||
for (int i = 0; i < height * width; i++) {
|
||||
byte color = colors[i];
|
||||
for (int n = 0; n < 8; n++) {
|
||||
int y = i / width;
|
||||
int x = (i % width) * 8 + (7 - n);
|
||||
|
||||
int bit = ((color >> n) & 0x01) << plane;
|
||||
int sample = surface->getPixel(x, y) | bit;
|
||||
assert(sample < 16);
|
||||
surface->setPixel(x, y, sample);
|
||||
}
|
||||
}
|
||||
free(colors);
|
||||
return surface;
|
||||
}
|
||||
|
||||
void CastleEngine::loadAssetsAmigaDemo() {
|
||||
Common::File file;
|
||||
file.open("x");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'x' file");
|
||||
|
||||
_viewArea = Common::Rect(40, 29, 280, 154);
|
||||
loadMessagesVariableSize(&file, 0x8bb2, 178);
|
||||
loadRiddles(&file, 0x96c8 - 2 - 19 * 2, 19);
|
||||
|
||||
file.seek(0x11eec);
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
for (int i = 0; i < 90; i++) {
|
||||
Graphics::ManagedSurface *img = loadFrameFromPlanes(&file, 8, 8);
|
||||
//Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
|
||||
//imgRiddle->copyFrom(*img);
|
||||
|
||||
chars.push_back(img);
|
||||
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)kAmigaCastlePalette, 16);
|
||||
|
||||
//charsRiddle.push_back(imgRiddle);
|
||||
//charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
|
||||
}
|
||||
// 0x1356c
|
||||
|
||||
_font = Font(chars);
|
||||
_font.setCharWidth(9);
|
||||
|
||||
load8bitBinary(&file, 0x162a6, 16);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
debugC(1, kFreescapeDebugParser, "Continue to parse area index %d at offset %x", _areaMap.size() + i + 1, (int)file.pos());
|
||||
Area *newArea = load8bitArea(&file, 16);
|
||||
if (newArea) {
|
||||
if (!_areaMap.contains(newArea->getAreaID()))
|
||||
_areaMap[newArea->getAreaID()] = newArea;
|
||||
else
|
||||
error("Repeated area ID: %d", newArea->getAreaID());
|
||||
} else {
|
||||
error("Invalid area %d?", i);
|
||||
}
|
||||
}
|
||||
|
||||
loadPalettes(&file, 0x151a6);
|
||||
|
||||
file.seek(0x2be96); // Area 255
|
||||
_areaMap[255] = load8bitArea(&file, 16);
|
||||
|
||||
file.seek(0x2cf28 + 0x28 - 0x2 + 0x28);
|
||||
_border = loadFrameFromPlanesVertical(&file, 160, 200);
|
||||
_border->convertToInPlace(_gfx->_texturePixelFormat, (byte *)kAmigaCastlePalette, 16);
|
||||
file.close();
|
||||
|
||||
_areaMap[2]->_groundColor = 1;
|
||||
for (auto &it : _areaMap)
|
||||
it._value->addStructure(_areaMap[255]);
|
||||
}
|
||||
|
||||
void CastleEngine::drawAmigaAtariSTUI(Graphics::Surface *surface) {
|
||||
drawStringInSurface(_currentArea->_name, 97, 182, 0, 0, surface);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
1712
engines/freescape/games/castle/castle.cpp
Normal file
1712
engines/freescape/games/castle/castle.cpp
Normal file
File diff suppressed because it is too large
Load Diff
164
engines/freescape/games/castle/castle.h
Normal file
164
engines/freescape/games/castle/castle.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
struct RiddleText {
|
||||
int8 _dx;
|
||||
int8 _dy;
|
||||
Common::String _text;
|
||||
|
||||
RiddleText(int8 dx, int8 dy, const Common::String &text) : _dx(dx), _dy(dy), _text(text) {}
|
||||
};
|
||||
|
||||
struct Riddle {
|
||||
Common::Point _origin;
|
||||
Common::Array<RiddleText> _lines;
|
||||
};
|
||||
|
||||
class CastleEngine : public FreescapeEngine {
|
||||
public:
|
||||
CastleEngine(OSystem *syst, const ADGameDescription *gd);
|
||||
~CastleEngine();
|
||||
|
||||
// Only in DOS
|
||||
Graphics::ManagedSurface *_option;
|
||||
Graphics::ManagedSurface *_menuButtons;
|
||||
Graphics::ManagedSurface *_menuCrawlIndicator;
|
||||
Graphics::ManagedSurface *_menuWalkIndicator;
|
||||
Graphics::ManagedSurface *_menuRunIndicator;
|
||||
Graphics::ManagedSurface *_menuFxOnIndicator;
|
||||
Graphics::ManagedSurface *_menuFxOffIndicator;
|
||||
Graphics::ManagedSurface *_menu;
|
||||
|
||||
void beforeStarting() override;
|
||||
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
|
||||
void initGameState() override;
|
||||
void endGame() override;
|
||||
|
||||
void drawInfoMenu() override;
|
||||
void loadAssets() override;
|
||||
void loadAssetsDOSFullGame() override;
|
||||
void loadAssetsDOSDemo() override;
|
||||
void loadAssetsAmigaDemo() override;
|
||||
void loadAssetsZXFullGame() override;
|
||||
void loadAssetsCPCFullGame() override;
|
||||
void borderScreen() override;
|
||||
void selectCharacterScreen();
|
||||
void drawOption();
|
||||
|
||||
void initZX();
|
||||
void initDOS();
|
||||
void initCPC();
|
||||
|
||||
void drawDOSUI(Graphics::Surface *surface) override;
|
||||
void drawZXUI(Graphics::Surface *surface) override;
|
||||
void drawCPCUI(Graphics::Surface *surface) override;
|
||||
void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
|
||||
void drawEnergyMeter(Graphics::Surface *surface, Common::Point origin);
|
||||
void drawLiftingGate(Graphics::Surface *surface);
|
||||
void drawDroppingGate(Graphics::Surface *surface);
|
||||
void pressedKey(const int keycode) override;
|
||||
void checkSensors() override;
|
||||
void updateTimeVariables() override;
|
||||
void drawBackground() override;
|
||||
|
||||
bool checkIfGameEnded() override;
|
||||
void drawSensorShoot(Sensor *sensor) override;
|
||||
|
||||
void executePrint(FCLInstruction &instruction) override;
|
||||
void executeDestroy(FCLInstruction &instruction) override;
|
||||
void executeRedraw(FCLInstruction &instruction) override;
|
||||
void gotoArea(uint16 areaID, int entranceID) override;
|
||||
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
|
||||
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
|
||||
|
||||
Common::Array<Riddle> _riddleList;
|
||||
Common::BitArray _fontPlane1;
|
||||
Common::BitArray _fontPlane2;
|
||||
Common::BitArray _fontPlane3;
|
||||
|
||||
void drawRiddleStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface);
|
||||
Graphics::ManagedSurface *loadFrameWithHeaderDOS(Common::SeekableReadStream *file);
|
||||
Common::Array <Graphics::ManagedSurface *>loadFramesWithHeaderDOS(Common::SeekableReadStream *file, int numFrames);
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back);
|
||||
Graphics::ManagedSurface *loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back);
|
||||
Graphics::ManagedSurface *loadFrame(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, uint32 back);
|
||||
Graphics::ManagedSurface *loadFrameFromPlanes(Common::SeekableReadStream *file, int widthInBytes, int height);
|
||||
Graphics::ManagedSurface *loadFrameFromPlanesInternal(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height);
|
||||
|
||||
Graphics::ManagedSurface *loadFrameFromPlanesVertical(Common::SeekableReadStream *file, int widthInBytes, int height);
|
||||
Graphics::ManagedSurface *loadFrameFromPlanesInternalVertical(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, int plane);
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *>_keysBorderFrames;
|
||||
Common::Array<Graphics::ManagedSurface *>_keysMenuFrames;
|
||||
Graphics::ManagedSurface *_spiritsMeterIndicatorBackgroundFrame;
|
||||
Graphics::ManagedSurface *_spiritsMeterIndicatorFrame;
|
||||
Graphics::ManagedSurface *_spiritsMeterIndicatorSideFrame;
|
||||
Graphics::ManagedSurface *_strenghtBackgroundFrame;
|
||||
Graphics::ManagedSurface *_strenghtBarFrame;
|
||||
Common::Array<Graphics::ManagedSurface *> _strenghtWeightsFrames;
|
||||
Common::Array<Graphics::ManagedSurface *> _flagFrames;
|
||||
Common::Array<Graphics::ManagedSurface *> _thunderFrames;
|
||||
|
||||
Graphics::ManagedSurface *_riddleTopFrame;
|
||||
Graphics::ManagedSurface *_riddleBackgroundFrame;
|
||||
Graphics::ManagedSurface *_riddleBottomFrame;
|
||||
|
||||
Graphics::ManagedSurface *_endGameThroneFrame;
|
||||
Graphics::ManagedSurface *_endGameBackgroundFrame;
|
||||
Graphics::ManagedSurface *_gameOverBackgroundFrame;
|
||||
|
||||
Common::Array<int> _keysCollected;
|
||||
bool _useRockTravel;
|
||||
int _spiritsMeter;
|
||||
int _spiritsMeterPosition;
|
||||
int _spiritsMeterMax;
|
||||
int _spiritsToKill;
|
||||
|
||||
int _lastTenSeconds;
|
||||
int _soundIndexStartFalling;
|
||||
|
||||
private:
|
||||
Common::SeekableReadStream *decryptFile(const Common::Path &filename);
|
||||
void loadRiddles(Common::SeekableReadStream *file, int offset, int number);
|
||||
void loadDOSFonts(Common::SeekableReadStream *file, int pos);
|
||||
void drawFullscreenRiddleAndWait(uint16 riddle);
|
||||
void drawFullscreenEndGameAndWait();
|
||||
void drawFullscreenGameOverAndWait();
|
||||
void drawRiddle(uint16 riddle, uint32 front, uint32 back, Graphics::Surface *surface);
|
||||
void tryToCollectKey();
|
||||
void addGhosts();
|
||||
bool ghostInArea();
|
||||
void updateThunder();
|
||||
|
||||
Audio::SoundHandle _soundFxGhostHandle;
|
||||
Texture *_optionTexture;
|
||||
Font _fontRiddle;
|
||||
int _droppingGateStartTicks;
|
||||
int _thunderTicks;
|
||||
int _thunderFrameDuration;
|
||||
Math::Vector3d _thunderOffset;
|
||||
Common::Array<Texture *>_thunderTextures;
|
||||
};
|
||||
|
||||
}
|
||||
345
engines/freescape/games/castle/cpc.cpp
Normal file
345
engines/freescape/games/castle/cpc.cpp
Normal file
@@ -0,0 +1,345 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/castle/castle.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void CastleEngine::initCPC() {
|
||||
_viewArea = Common::Rect(40, 33 - 2, 280, 152);
|
||||
_soundIndexShoot = 5;
|
||||
_soundIndexCollide = -1;
|
||||
_soundIndexFallen = -1;
|
||||
_soundIndexStepUp = -1;
|
||||
_soundIndexStepDown = -1;
|
||||
_soundIndexMenu = -1;
|
||||
_soundIndexStart = 6;
|
||||
_soundIndexAreaChange = 7;
|
||||
}
|
||||
|
||||
|
||||
byte kCPCPaletteCastleTitleData[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0xff},
|
||||
{0xff, 0xff, 0x00},
|
||||
{0xff, 0x00, 0x00},
|
||||
};
|
||||
|
||||
byte kCPCPaletteCastleBorderData[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x80, 0x80, 0x80},
|
||||
{0x00, 0x80, 0x00},
|
||||
{0xff, 0xff, 0xff},
|
||||
};
|
||||
|
||||
// Data for the mountains background. This is not included in the original game for some reason
|
||||
// but all the other releases have it. This is coming from the ZX Spectrum version.
|
||||
byte mountainsData[288] {
|
||||
0x06, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
|
||||
0x00, 0x00, 0x38, 0x01, 0xa0, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1e, 0x30, 0x00, 0x00, 0x00, 0x00, 0x17,
|
||||
0x80, 0x00, 0x7c, 0x03, 0xd0, 0x00, 0x00, 0x01,
|
||||
0x00, 0x3f, 0x5c, 0x80, 0x0, 0x18, 0x0, 0x23,
|
||||
0xc0, 0x00, 0xfe, 0x0d, 0xfe, 0x6, 0x00, 0x02,
|
||||
0x80, 0x7e, 0xbe, 0xc0, 0x0, 0x3c, 0x0, 0x47,
|
||||
0xe0, 0x1, 0x57, 0x56, 0xff, 0xf, 0x80, 0x5,
|
||||
0x40, 0xf5, 0xfb, 0x40, 0x0, 0x76, 0x0, 0x93,
|
||||
0xd0, 0xa, 0xab, 0xab, 0xff, 0xaf, 0xc3, 0x2a,
|
||||
0xa1, 0xeb, 0xfe, 0xa8, 0x0, 0xde, 0x0, 0x21,
|
||||
0xa8, 0x75, 0x55, 0x41, 0xff, 0xd6, 0xef, 0xd5,
|
||||
0x53, 0x57, 0xfc, 0x14, 0x1, 0xb7, 0x7, 0x42,
|
||||
0xd5, 0xea, 0xaa, 0x92, 0xfb, 0xeb, 0xab, 0xea,
|
||||
0xaa, 0xae, 0xfa, 0x4a, 0x82, 0xea, 0xbe, 0x97,
|
||||
0xab, 0xd5, 0x55, 0x25, 0xdd, 0x75, 0x45, 0xf5,
|
||||
0x55, 0x7d, 0xdd, 0x25, 0x55, 0xd5, 0x54, 0x2f,
|
||||
0xf7, 0xaa, 0xaa, 0x53, 0xea, 0xa8, 0x13, 0xfa,
|
||||
0xaa, 0xea, 0xbe, 0x42, 0xab, 0xaa, 0xa9, 0x5f,
|
||||
0xdd, 0xd5, 0x55, 0x7, 0x55, 0x2, 0x45, 0xfd,
|
||||
0x51, 0x55, 0x57, 0x15, 0x57, 0xd5, 0x52, 0xaf,
|
||||
0xee, 0xfa, 0xaa, 0x2b, 0xaa, 0x80, 0x8b, 0xfe,
|
||||
0xaa, 0xaa, 0xae, 0xaa, 0xbe, 0xaa, 0xa4, 0x5a,
|
||||
0xb5, 0x5d, 0x5c, 0x56, 0xd5, 0x29, 0x1f, 0xff,
|
||||
0x55, 0x55, 0x5b, 0x55, 0x7d, 0x55, 0x9, 0xb5,
|
||||
0x5a, 0xaf, 0xba, 0xad, 0xaa, 0x92, 0x3e, 0xbf,
|
||||
0xea, 0xaa, 0xaf, 0xab, 0xea, 0xaa, 0x2, 0x5a,
|
||||
0xf5, 0x55, 0xfd, 0x57, 0x55, 0x5, 0x5f, 0x57,
|
||||
0xfd, 0x55, 0x55, 0x57, 0x55, 0x50, 0x15, 0xaf,
|
||||
0xba, 0xaa, 0xfe, 0xae, 0xfa, 0xaa, 0xbe, 0xaa,
|
||||
0xbf, 0xaa, 0xaa, 0xaa, 0xaa, 0x82, 0xaa, 0x55,
|
||||
0x55, 0x55, 0x5f, 0xd5, 0xfd, 0x55, 0x55, 0x55,
|
||||
0x5f, 0xfd, 0x55, 0x55, 0x55, 0x55, 0x55, 0xea,
|
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||
0xaa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
};
|
||||
|
||||
extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode0);
|
||||
|
||||
void CastleEngine::loadAssetsCPCFullGame() {
|
||||
Common::File file;
|
||||
uint8 r, g, b;
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
|
||||
file.open("CMLOAD.BIN");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open CMLOAD.BIN");
|
||||
|
||||
_title = readCPCImage(&file, true);
|
||||
_title->setPalette((byte*)&kCPCPaletteCastleTitleData, 0, 4);
|
||||
|
||||
file.close();
|
||||
file.open("CMSCR.BIN");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open CMSCR.BIN");
|
||||
|
||||
_border = readCPCImage(&file, true);
|
||||
_border->setPalette((byte*)&kCPCPaletteCastleBorderData, 0, 4);
|
||||
|
||||
file.close();
|
||||
file.open("CM.BIN");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TECODE.BIN/TE2.BI2");
|
||||
|
||||
loadMessagesVariableSize(&file, 0x16c6, 71);
|
||||
switch (_language) {
|
||||
/*case Common::ES_ESP:
|
||||
loadRiddles(&file, 0x1470 - 4 - 2 - 9 * 2, 9);
|
||||
loadMessagesVariableSize(&file, 0xf3d, 71);
|
||||
load8bitBinary(&file, 0x6aab - 2, 16);
|
||||
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
|
||||
|
||||
file.seek(0x1218 + 16);
|
||||
for (int i = 0; i < 90; i++) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
|
||||
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
|
||||
}
|
||||
_font = Font(chars);
|
||||
_font.setCharWidth(9);
|
||||
_fontLoaded = true;
|
||||
|
||||
break;*/
|
||||
case Common::EN_ANY:
|
||||
loadRiddles(&file, 0x1b75 - 2 - 9 * 2, 9);
|
||||
load8bitBinary(&file, 0x791a, 16);
|
||||
|
||||
file.seek(0x2724);
|
||||
for (int i = 0; i < 90; i++) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
|
||||
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
|
||||
}
|
||||
_font = Font(chars);
|
||||
_font.setCharWidth(9);
|
||||
_fontLoaded = true;
|
||||
|
||||
break;
|
||||
default:
|
||||
error("Language not supported");
|
||||
break;
|
||||
}
|
||||
|
||||
loadColorPalette();
|
||||
|
||||
int backgroundWidth = 16;
|
||||
int backgroundHeight = 18;
|
||||
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
|
||||
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
|
||||
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
|
||||
Common::MemoryReadStream mountainsStream(mountainsData, sizeof(mountainsData));
|
||||
|
||||
_gfx->readFromPalette(11, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_background = loadFrame(&mountainsStream, background, backgroundWidth, backgroundHeight, front);
|
||||
/*_gfx->readFromPalette(2, r, g, b);
|
||||
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(7, r, g, b);
|
||||
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_keysBorderFrames.push_back(loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xe06 : 0xdf7, red, white));
|
||||
|
||||
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
|
||||
_spiritsMeterIndicatorFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xe5e : 0xe4f, green, white);
|
||||
|
||||
_gfx->readFromPalette(4, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int backgroundWidth = 16;
|
||||
int backgroundHeight = 18;
|
||||
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
|
||||
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
|
||||
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
|
||||
|
||||
file.seek(_language == Common::ES_ESP ? 0xfd3 : 0xfc4);
|
||||
_background = loadFrame(&file, background, backgroundWidth, backgroundHeight, front);
|
||||
|
||||
_gfx->readFromPalette(6, r, g, b);
|
||||
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0, 0);
|
||||
_strenghtBackgroundFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xee6 : 0xed7, yellow, black);
|
||||
_strenghtBarFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xf72 : 0xf63, yellow, black);
|
||||
|
||||
Graphics::ManagedSurface *bar = new Graphics::ManagedSurface();
|
||||
bar->create(_strenghtBarFrame->w - 4, _strenghtBarFrame->h, _gfx->_texturePixelFormat);
|
||||
_strenghtBarFrame->copyRectToSurface(*bar, 4, 0, Common::Rect(4, 0, _strenghtBarFrame->w - 4, _strenghtBarFrame->h));
|
||||
_strenghtBarFrame->free();
|
||||
delete _strenghtBarFrame;
|
||||
_strenghtBarFrame = bar;
|
||||
|
||||
_strenghtWeightsFrames = loadFramesWithHeader(&file, _language == Common::ES_ESP ? 0xf92 : 0xf83, 4, yellow, black);
|
||||
|
||||
_flagFrames = loadFramesWithHeader(&file, (_language == Common::ES_ESP ? 0x10e4 + 15 : 0x10e4), 4, green, black);
|
||||
|
||||
int thunderWidth = 4;
|
||||
int thunderHeight = 43;
|
||||
_thunderFrame = new Graphics::ManagedSurface();
|
||||
_thunderFrame->create(thunderWidth * 8, thunderHeight, _gfx->_texturePixelFormat);
|
||||
_thunderFrame->fillRect(Common::Rect(0, 0, thunderWidth * 8, thunderHeight), 0);
|
||||
_thunderFrame = loadFrame(&file, _thunderFrame, thunderWidth, thunderHeight, front);
|
||||
|
||||
Graphics::Surface *tmp;
|
||||
tmp = loadBundledImage("castle_riddle_top_frame");
|
||||
_riddleTopFrame = new Graphics::ManagedSurface;
|
||||
_riddleTopFrame->copyFrom(*tmp);
|
||||
tmp->free();
|
||||
delete tmp;
|
||||
_riddleTopFrame->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
|
||||
tmp = loadBundledImage("castle_riddle_background_frame");
|
||||
_riddleBackgroundFrame = new Graphics::ManagedSurface();
|
||||
_riddleBackgroundFrame->copyFrom(*tmp);
|
||||
tmp->free();
|
||||
delete tmp;
|
||||
_riddleBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
|
||||
tmp = loadBundledImage("castle_riddle_bottom_frame");
|
||||
_riddleBottomFrame = new Graphics::ManagedSurface();
|
||||
_riddleBottomFrame->copyFrom(*tmp);
|
||||
tmp->free();
|
||||
delete tmp;
|
||||
_riddleBottomFrame->convertToInPlace(_gfx->_texturePixelFormat);*/
|
||||
|
||||
for (auto &it : _areaMap) {
|
||||
it._value->addStructure(_areaMap[255]);
|
||||
|
||||
it._value->addObjectFromArea(164, _areaMap[255]);
|
||||
it._value->addObjectFromArea(174, _areaMap[255]);
|
||||
it._value->addObjectFromArea(175, _areaMap[255]);
|
||||
for (int16 id = 136; id < 140; id++) {
|
||||
it._value->addObjectFromArea(id, _areaMap[255]);
|
||||
}
|
||||
|
||||
it._value->addObjectFromArea(195, _areaMap[255]);
|
||||
for (int16 id = 214; id < 228; id++) {
|
||||
it._value->addObjectFromArea(id, _areaMap[255]);
|
||||
}
|
||||
}
|
||||
// Discard some global conditions
|
||||
// It is unclear why they hide/unhide objects that formed the spirits
|
||||
for (int i = 0; i < 3; i++) {
|
||||
debugC(kFreescapeDebugParser, "Discarding condition %s", _conditionSources[0].c_str());
|
||||
_conditions.remove_at(0);
|
||||
_conditionSources.remove_at(0);
|
||||
}
|
||||
}
|
||||
|
||||
void CastleEngine::drawCPCUI(Graphics::Surface *surface) {
|
||||
uint32 color = _gfx->_paperColor;
|
||||
//uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = 1;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
Common::Rect backRect(97, 181, 232, 190);
|
||||
surface->fillRect(backRect, back);
|
||||
|
||||
Common::String message;
|
||||
int deadline = -1;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline > 0 && deadline <= _countdown) {
|
||||
drawStringInSurface(message, 97, 182, front, back, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else {
|
||||
if (_gameStateControl == kFreescapeGameStatePlaying) {
|
||||
drawStringInSurface(_currentArea->_name, 97, 182, front, back, surface);
|
||||
}
|
||||
}
|
||||
|
||||
/*uint32 color = 5;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = 0;
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
Common::Rect backRect(123, 179, 242 + 5, 188);
|
||||
surface->fillRect(backRect, black);
|
||||
|
||||
Common::String message;
|
||||
int deadline = -1;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline > 0 && deadline <= _countdown) {
|
||||
//debug("deadline: %d countdown: %d", deadline, _countdown);
|
||||
drawStringInSurface(message, 120, 179, front, black, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else {
|
||||
if (_gameStateControl == kFreescapeGameStatePlaying) {
|
||||
drawStringInSurface(_currentArea->_name, 120, 179, front, black, surface);
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < int(_keysCollected.size()); k++) {
|
||||
surface->copyRectToSurface((const Graphics::Surface)*_keysBorderFrames[0], 99 - k * 4, 177, Common::Rect(0, 0, 6, 11));
|
||||
}
|
||||
|
||||
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
|
||||
|
||||
surface->fillRect(Common::Rect(152, 156, 216, 164), green);
|
||||
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 140 + _spiritsMeterPosition, 156, Common::Rect(0, 0, 15, 8));
|
||||
drawEnergyMeter(surface, Common::Point(63, 154));
|
||||
|
||||
int ticks = g_system->getMillis() / 20;
|
||||
int flagFrameIndex = (ticks / 10) % 4;
|
||||
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 264, 9, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));*/
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
476
engines/freescape/games/castle/dos.cpp
Normal file
476
engines/freescape/games/castle/dos.cpp
Normal file
@@ -0,0 +1,476 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/castle/castle.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
Common::SeekableReadStream *CastleEngine::decryptFile(const Common::Path &filename) {
|
||||
Common::File file;
|
||||
file.open(filename);
|
||||
if (!file.isOpen())
|
||||
error("Failed to open %s", filename.toString().c_str());
|
||||
|
||||
int size = file.size();
|
||||
byte *encryptedBuffer = (byte *)malloc(size);
|
||||
file.read(encryptedBuffer, size);
|
||||
file.close();
|
||||
|
||||
int seed = 24;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (i > 1)
|
||||
encryptedBuffer[i] ^= seed;
|
||||
seed = (seed + 1) & 0xff;
|
||||
}
|
||||
|
||||
return (new Common::MemoryReadStream(encryptedBuffer, size));
|
||||
}
|
||||
|
||||
extern byte kEGADefaultPalette[16][3];
|
||||
extern Common::MemoryReadStream *unpackEXE(Common::File &ms);
|
||||
|
||||
byte kEGARiddleFontPalette[16][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0x55, 0x00}
|
||||
};
|
||||
|
||||
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanes(Common::SeekableReadStream *file, int widthInBytes, int height) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(widthInBytes * 8 / 4, height, Graphics::PixelFormat::createFormatCLUT8());
|
||||
surface->fillRect(Common::Rect(0, 0, widthInBytes * 8 / 4, height), 0);
|
||||
loadFrameFromPlanesInternal(file, surface, widthInBytes, height);
|
||||
return surface;
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesInternal(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height) {
|
||||
byte *colors = (byte *)malloc(sizeof(byte) * height * width);
|
||||
file->read(colors, height * width);
|
||||
|
||||
for (int p = 0; p < 4; p++) {
|
||||
for (int i = 0; i < height * width; i++) {
|
||||
byte color = colors[i];
|
||||
for (int n = 0; n < 8; n++) {
|
||||
int y = i / width;
|
||||
int x = (i % width) * 8 + (7 - n);
|
||||
// Check that we are in the right plane
|
||||
if (x < width * (8 / 4) * p || x >= width * (8 / 4) * (p + 1))
|
||||
continue;
|
||||
|
||||
int bit = ((color >> n) & 0x01) << p;
|
||||
int sample = surface->getPixel(x % (width * 8 / 4), y) | bit;
|
||||
assert(sample < 16);
|
||||
surface->setPixel(x % (width * 8 / 4), y, sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
Common::Array <Graphics::ManagedSurface *>CastleEngine::loadFramesWithHeaderDOS(Common::SeekableReadStream *file, int numFrames) {
|
||||
uint8 header1 = file->readByte();
|
||||
uint8 header2 = file->readByte();
|
||||
int height = file->readByte();
|
||||
uint8 mask = file->readByte();
|
||||
int size = file->readUint16LE();
|
||||
|
||||
assert(size % height == 0);
|
||||
int widthBytes = (size / height);
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> frames;
|
||||
for (int i = 0; i < numFrames; i++) {
|
||||
Graphics::ManagedSurface *frame = loadFrameFromPlanes(file, widthBytes, height);
|
||||
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
frames.push_back(frame);
|
||||
}
|
||||
|
||||
debug("header: %x %x, height: %d, mask: %x, widthBytes: %d, size: %d", header1, header2, height, mask, widthBytes, size);
|
||||
return frames;
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *CastleEngine::loadFrameWithHeaderDOS(Common::SeekableReadStream *file) {
|
||||
uint8 header1 = file->readByte();
|
||||
uint8 header2 = file->readByte();
|
||||
int height = file->readByte();
|
||||
uint8 mask = file->readByte();
|
||||
int size = file->readUint16LE();
|
||||
|
||||
assert(size % height == 0);
|
||||
int widthBytes = (size / height);
|
||||
|
||||
Graphics::ManagedSurface *frame = loadFrameFromPlanes(file, widthBytes, height);
|
||||
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
|
||||
debug("header: %x %x, height: %d, mask: %x, widthBytes: %d, size: %d", header1, header2, height, mask, widthBytes, size);
|
||||
debug("pos: %x", (int32)file->pos());
|
||||
return frame;
|
||||
}
|
||||
|
||||
void CastleEngine::initDOS() {
|
||||
_viewArea = Common::Rect(40, 33 - 2, 280, 152);
|
||||
}
|
||||
|
||||
void CastleEngine::loadAssetsDOSFullGame() {
|
||||
Common::File file;
|
||||
Common::SeekableReadStream *stream = nullptr;
|
||||
|
||||
if (_renderMode == Common::kRenderEGA) {
|
||||
file.open("CME.EXE");
|
||||
stream = unpackEXE(file);
|
||||
if (stream) {
|
||||
loadSpeakerFxDOS(stream, 0x636d + 0x200, 0x63ed + 0x200, 30);
|
||||
|
||||
stream->seek(0x197c0);
|
||||
_endGameBackgroundFrame = loadFrameFromPlanes(stream, 112, 108);
|
||||
_endGameBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
|
||||
_background = loadFrameFromPlanes(stream, 504, 18);
|
||||
_background->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
debug("%x", (int32)stream->pos());
|
||||
// Eye widget is next to 0x1f058
|
||||
|
||||
stream->seek(0x1f4e3);
|
||||
for (int i = 0; i < 6; i++)
|
||||
debug("i: %d -> %x", i, stream->readByte());
|
||||
debug("%x", (int32)stream->pos());
|
||||
debug("extra: %x", stream->readByte());
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
|
||||
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
_keysBorderFrames.push_back(frame);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
|
||||
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
_keysMenuFrames.push_back(frame);
|
||||
}
|
||||
|
||||
//for (int i = 0; i < 6; i++)
|
||||
// debug("i: %d -> %x", i, stream->readByte());
|
||||
|
||||
//loadFrameWithHeaderDOS(stream);
|
||||
//debug("%lx", stream->pos());
|
||||
//assert(0);
|
||||
|
||||
stream->seek(0x20262);
|
||||
_strenghtBackgroundFrame = loadFrameWithHeaderDOS(stream);
|
||||
_strenghtBarFrame = loadFrameWithHeaderDOS(stream);
|
||||
_strenghtWeightsFrames = loadFramesWithHeaderDOS(stream, 4);
|
||||
_spiritsMeterIndicatorBackgroundFrame = loadFrameWithHeaderDOS(stream);
|
||||
_spiritsMeterIndicatorFrame = loadFrameWithHeaderDOS(stream);
|
||||
_spiritsMeterIndicatorSideFrame = loadFrameWithHeaderDOS(stream); // side
|
||||
loadFrameWithHeaderDOS(stream); // ???
|
||||
|
||||
/*for (int i = 0; i < 6; i++)
|
||||
debug("i: %d -> %x", i, stream->readByte());
|
||||
debug("%lx", stream->pos());*/
|
||||
//assert(0);
|
||||
|
||||
stream->seek(0x221ae);
|
||||
// No header?
|
||||
_menu = loadFrameFromPlanes(stream, 112, 115);
|
||||
_menu->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
|
||||
Common::Array <Graphics::ManagedSurface *> menuFrames = loadFramesWithHeaderDOS(stream, 5);
|
||||
_menuCrawlIndicator = menuFrames[0];
|
||||
_menuWalkIndicator = menuFrames[1];
|
||||
_menuRunIndicator = menuFrames[2];
|
||||
_menuFxOffIndicator = menuFrames[3];
|
||||
_menuFxOnIndicator = menuFrames[4];
|
||||
|
||||
_flagFrames = loadFramesWithHeaderDOS(stream, 4);
|
||||
_riddleTopFrame = loadFrameWithHeaderDOS(stream);
|
||||
_riddleBackgroundFrame = loadFrameWithHeaderDOS(stream);
|
||||
_riddleBottomFrame = loadFrameWithHeaderDOS(stream);
|
||||
_endGameThroneFrame = loadFrameWithHeaderDOS(stream);
|
||||
// No header
|
||||
Graphics::ManagedSurface *thunderFrame = loadFrameFromPlanes(stream, 32, 128);
|
||||
thunderFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
_thunderFrames.push_back(thunderFrame);
|
||||
|
||||
stream->seek(0x29696);
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
Common::Array<Graphics::ManagedSurface *> charsRiddle;
|
||||
for (int i = 0; i < 90; i++) {
|
||||
Graphics::ManagedSurface *img = loadFrameFromPlanes(stream, 8, 8);
|
||||
Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
|
||||
imgRiddle->copyFrom(*img);
|
||||
|
||||
chars.push_back(img);
|
||||
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
|
||||
charsRiddle.push_back(imgRiddle);
|
||||
charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
|
||||
}
|
||||
_font = Font(chars);
|
||||
_font.setCharWidth(9);
|
||||
|
||||
_fontRiddle = Font(charsRiddle);
|
||||
_fontRiddle.setCharWidth(9);
|
||||
_fontLoaded = true;
|
||||
}
|
||||
|
||||
delete stream;
|
||||
file.close();
|
||||
|
||||
file.open("CMLE.DAT");
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
file.close();
|
||||
|
||||
file.open("CMOE.DAT");
|
||||
_option = load8bitBinImage(&file, 0x0);
|
||||
_option->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
file.close();
|
||||
|
||||
file.open("CME.DAT");
|
||||
_border = load8bitBinImage(&file, 0x0);
|
||||
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
file.close();
|
||||
|
||||
switch (_language) {
|
||||
case Common::ES_ESP:
|
||||
stream = decryptFile("CMLS");
|
||||
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
|
||||
// Fixes for incorrect or wrong translations
|
||||
Common::replace(_riddleList[16]._lines[5]._text, "IN", "EN");
|
||||
break;
|
||||
case Common::FR_FRA:
|
||||
stream = decryptFile("CMLF");
|
||||
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
|
||||
break;
|
||||
case Common::DE_DEU:
|
||||
stream = decryptFile("CMLG");
|
||||
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
|
||||
break;
|
||||
case Common::EN_ANY:
|
||||
stream = decryptFile("CMLE");
|
||||
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
|
||||
break;
|
||||
default:
|
||||
error("Invalid or unsupported language: %x", _language);
|
||||
}
|
||||
|
||||
loadMessagesVariableSize(stream, 0x11, 164);
|
||||
delete stream;
|
||||
|
||||
stream = decryptFile("CMEDF");
|
||||
load8bitBinary(stream, 0, 16);
|
||||
delete stream;
|
||||
} else
|
||||
error("Not implemented yet");
|
||||
|
||||
|
||||
// CPC
|
||||
// file = gameDir.createReadStreamForMember("cm.bin");
|
||||
// if (file == nullptr)
|
||||
// error("Failed to open cm.bin");
|
||||
// load8bitBinary(file, 0x791a, 16);
|
||||
}
|
||||
|
||||
void CastleEngine::loadAssetsDOSDemo() {
|
||||
Common::File file;
|
||||
Common::SeekableReadStream *stream = nullptr;
|
||||
|
||||
if (_renderMode == Common::kRenderEGA) {
|
||||
file.open("CMDE.EXE");
|
||||
stream = unpackEXE(file);
|
||||
if (stream) {
|
||||
loadSpeakerFxDOS(stream, 0x636d + 0x200, 0x63ed + 0x200, 30);
|
||||
|
||||
stream->seek(0x197c0 - 0x2a0);
|
||||
_endGameBackgroundFrame = loadFrameFromPlanes(stream, 112, 108);
|
||||
_endGameBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
|
||||
_background = loadFrameFromPlanes(stream, 504, 18);
|
||||
_background->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
|
||||
stream->seek(0x1f4e3 - 0x2a0);
|
||||
for (int i = 0; i < 6; i++)
|
||||
debug("i: %d -> %x", i, stream->readByte());
|
||||
debug("%x", (int32)stream->pos());
|
||||
debug("extra: %x", stream->readByte());
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
|
||||
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
_keysBorderFrames.push_back(frame);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 11; i++) {
|
||||
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
|
||||
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
_keysMenuFrames.push_back(frame);
|
||||
}
|
||||
|
||||
stream->seek(0x20262 - 0x2a0);
|
||||
_strenghtBackgroundFrame = loadFrameWithHeaderDOS(stream);
|
||||
_strenghtBarFrame = loadFrameWithHeaderDOS(stream);
|
||||
_strenghtWeightsFrames = loadFramesWithHeaderDOS(stream, 4);
|
||||
_spiritsMeterIndicatorBackgroundFrame = loadFrameWithHeaderDOS(stream);
|
||||
_spiritsMeterIndicatorFrame = loadFrameWithHeaderDOS(stream);
|
||||
_spiritsMeterIndicatorSideFrame = loadFrameWithHeaderDOS(stream); // side
|
||||
loadFrameWithHeaderDOS(stream); // ???
|
||||
|
||||
stream->seek(0x221ae - 0x2a0);
|
||||
// No header?
|
||||
_menu = loadFrameFromPlanes(stream, 112, 115);
|
||||
_menu->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
|
||||
Common::Array <Graphics::ManagedSurface *> menuFrames = loadFramesWithHeaderDOS(stream, 5);
|
||||
_menuCrawlIndicator = menuFrames[0];
|
||||
_menuWalkIndicator = menuFrames[1];
|
||||
_menuRunIndicator = menuFrames[2];
|
||||
_menuFxOffIndicator = menuFrames[3];
|
||||
_menuFxOnIndicator = menuFrames[4];
|
||||
|
||||
_flagFrames = loadFramesWithHeaderDOS(stream, 4);
|
||||
_riddleTopFrame = loadFrameWithHeaderDOS(stream);
|
||||
_riddleBackgroundFrame = loadFrameWithHeaderDOS(stream);
|
||||
_riddleBottomFrame = loadFrameWithHeaderDOS(stream);
|
||||
_endGameThroneFrame = loadFrameWithHeaderDOS(stream);
|
||||
// No header
|
||||
Graphics::ManagedSurface *thunderFrame = loadFrameFromPlanes(stream, 32, 128);
|
||||
thunderFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
_thunderFrames.push_back(thunderFrame);
|
||||
|
||||
stream->seek(0x293f6); // TODO: check this
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
Common::Array<Graphics::ManagedSurface *> charsRiddle;
|
||||
for (int i = 0; i < 90; i++) {
|
||||
Graphics::ManagedSurface *img = loadFrameFromPlanes(stream, 8, 8);
|
||||
Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
|
||||
imgRiddle->copyFrom(*img);
|
||||
|
||||
chars.push_back(img);
|
||||
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
|
||||
|
||||
charsRiddle.push_back(imgRiddle);
|
||||
charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
|
||||
}
|
||||
_font = Font(chars);
|
||||
_font.setCharWidth(9);
|
||||
|
||||
_fontRiddle = Font(charsRiddle);
|
||||
_fontRiddle.setCharWidth(9);
|
||||
_fontLoaded = true;
|
||||
}
|
||||
|
||||
delete stream;
|
||||
file.close();
|
||||
|
||||
file.open("CMLE.DAT");
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
file.close();
|
||||
|
||||
file.open("CMOE.DAT");
|
||||
_option = load8bitBinImage(&file, 0x0);
|
||||
_option->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
file.close();
|
||||
|
||||
file.open("CME.DAT");
|
||||
_border = load8bitBinImage(&file, 0x0);
|
||||
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
file.close();
|
||||
|
||||
stream = decryptFile("CMLD"); // Only english
|
||||
loadMessagesVariableSize(stream, 0x11, 164);
|
||||
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
|
||||
delete stream;
|
||||
|
||||
stream = decryptFile("CDEDF");
|
||||
load8bitBinary(stream, 0, 16);
|
||||
delete stream;
|
||||
} else
|
||||
error("Not implemented yet");
|
||||
|
||||
}
|
||||
|
||||
void CastleEngine::drawDOSUI(Graphics::Surface *surface) {
|
||||
uint32 color = 10;
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
|
||||
uint8 r, g, b;
|
||||
drawLiftingGate(surface);
|
||||
drawDroppingGate(surface);
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = 0;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
Common::Rect backRect(97, 181, 232, 190);
|
||||
surface->fillRect(backRect, back);
|
||||
|
||||
Common::String message;
|
||||
int deadline = -1;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline > 0 && deadline <= _countdown) {
|
||||
drawStringInSurface(message, 97, 182, front, back, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else {
|
||||
if (_gameStateControl != kFreescapeGameStateEnd) {
|
||||
if (ghostInArea())
|
||||
drawStringInSurface(_messagesList[116], 97, 182, front, back, surface);
|
||||
else
|
||||
drawStringInSurface(_currentArea->_name, 97, 182, front, back, surface);
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < int(_keysCollected.size()); k++) {
|
||||
surface->copyRectToSurfaceWithKey((const Graphics::Surface)*_keysBorderFrames[k], 76 - k * 3, 179, Common::Rect(0, 0, 6, 14), black);
|
||||
}
|
||||
|
||||
drawEnergyMeter(surface, Common::Point(38, 158));
|
||||
int flagFrameIndex = (_ticks / 10) % 4;
|
||||
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 285, 5, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));
|
||||
|
||||
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorBackgroundFrame, 136, 162, Common::Rect(0, 0, _spiritsMeterIndicatorBackgroundFrame->w, _spiritsMeterIndicatorBackgroundFrame->h));
|
||||
surface->copyRectToSurfaceWithKey((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 125 + 6 + _spiritsMeterPosition, 161, Common::Rect(0, 0, _spiritsMeterIndicatorFrame->w, _spiritsMeterIndicatorFrame->h), black);
|
||||
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorSideFrame, 122 + 5 + 1, 157 + 5 - 1, Common::Rect(0, 0, _spiritsMeterIndicatorSideFrame->w / 2, _spiritsMeterIndicatorSideFrame->h));
|
||||
//surface->copyRectToSurface(*_spiritsMeterIndicatorFrame, 100, 50, Common::Rect(0, 0, _spiritsMeterIndicatorFrame->w, _spiritsMeterIndicatorFrame->h));
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
286
engines/freescape/games/castle/zx.cpp
Normal file
286
engines/freescape/games/castle/zx.cpp
Normal file
@@ -0,0 +1,286 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/castle/castle.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void CastleEngine::initZX() {
|
||||
_viewArea = Common::Rect(64, 36, 256, 148);
|
||||
_soundIndexShoot = 5;
|
||||
_soundIndexCollide = 3;
|
||||
_soundIndexStartFalling = -1;
|
||||
_soundIndexFallen = 1;
|
||||
_soundIndexFall = 6;
|
||||
_soundIndexStepUp = 12;
|
||||
_soundIndexStepDown = 12;
|
||||
_soundIndexMenu = 3;
|
||||
_soundIndexStart = 7;
|
||||
_soundIndexAreaChange = 7;
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *CastleEngine::loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
file->seek(pos);
|
||||
int16 width = file->readByte();
|
||||
int16 height = file->readByte();
|
||||
debugC(kFreescapeDebugParser, "Frame size: %d x %d", width, height);
|
||||
surface->create(width * 8, height, _gfx->_texturePixelFormat);
|
||||
|
||||
/*byte mask =*/ file->readByte();
|
||||
|
||||
surface->fillRect(Common::Rect(0, 0, width * 8, height), back);
|
||||
/*int frameSize =*/ file->readUint16LE();
|
||||
return loadFrame(file, surface, width, height, front);
|
||||
}
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> CastleEngine::loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back) {
|
||||
Graphics::ManagedSurface *surface = nullptr;
|
||||
file->seek(pos);
|
||||
int16 width = file->readByte();
|
||||
int16 height = file->readByte();
|
||||
/*byte mask =*/ file->readByte();
|
||||
|
||||
/*int frameSize =*/ file->readUint16LE();
|
||||
Common::Array<Graphics::ManagedSurface *> frames;
|
||||
for (int i = 0; i < numFrames; i++) {
|
||||
surface = new Graphics::ManagedSurface();
|
||||
surface->create(width * 8, height, _gfx->_texturePixelFormat);
|
||||
surface->fillRect(Common::Rect(0, 0, width * 8, height), back);
|
||||
frames.push_back(loadFrame(file, surface, width, height, front));
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
|
||||
Graphics::ManagedSurface *CastleEngine::loadFrame(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, uint32 front) {
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
byte color = file->readByte();
|
||||
for (int n = 0; n < 8; n++) {
|
||||
int y = i / width;
|
||||
int x = (i % width) * 8 + (7 - n);
|
||||
if ((color & (1 << n)))
|
||||
surface->setPixel(x, y, front);
|
||||
}
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
void CastleEngine::loadAssetsZXFullGame() {
|
||||
Common::File file;
|
||||
uint8 r, g, b;
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
|
||||
file.open("castlemaster.zx.title");
|
||||
if (file.isOpen()) {
|
||||
_title = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find castlemaster.zx.title");
|
||||
|
||||
file.close();
|
||||
file.open("castlemaster.zx.border");
|
||||
if (file.isOpen()) {
|
||||
_border = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find castlemaster.zx.border");
|
||||
file.close();
|
||||
|
||||
file.open("castlemaster.zx.data");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open castlemaster.zx.data");
|
||||
|
||||
loadMessagesVariableSize(&file, 0x4bd, 71);
|
||||
switch (_language) {
|
||||
case Common::ES_ESP:
|
||||
loadRiddles(&file, 0x1458, 9);
|
||||
load8bitBinary(&file, 0x6aa9, 16);
|
||||
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
|
||||
|
||||
file.seek(0x1228);
|
||||
for (int i = 0; i < 90; i++) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
|
||||
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
|
||||
}
|
||||
_font = Font(chars);
|
||||
_font.setCharWidth(9);
|
||||
_fontLoaded = true;
|
||||
|
||||
break;
|
||||
case Common::EN_ANY:
|
||||
if (_variant & GF_ZX_RETAIL) {
|
||||
loadRiddles(&file, 0x1448, 9);
|
||||
load8bitBinary(&file, 0x6a3b, 16);
|
||||
loadSpeakerFxZX(&file, 0xc91, 0xccd);
|
||||
file.seek(0x1219);
|
||||
} else if (_variant & GF_ZX_DISC) {
|
||||
loadRiddles(&file, 0x1457, 9);
|
||||
load8bitBinary(&file, 0x6a9b, 16);
|
||||
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
|
||||
file.seek(0x1228);
|
||||
} else {
|
||||
error("Unknown Castle Master ZX variant");
|
||||
}
|
||||
for (int i = 0; i < 90; i++) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
|
||||
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
|
||||
}
|
||||
_font = Font(chars);
|
||||
_font.setCharWidth(9);
|
||||
_fontLoaded = true;
|
||||
|
||||
break;
|
||||
default:
|
||||
error("Language not supported");
|
||||
break;
|
||||
}
|
||||
|
||||
loadColorPalette();
|
||||
_gfx->readFromPalette(2, r, g, b);
|
||||
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(7, r, g, b);
|
||||
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_keysBorderFrames.push_back(loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xe06 : 0xdf7, red, white));
|
||||
|
||||
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
|
||||
_spiritsMeterIndicatorFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xe5e : 0xe4f, green, white);
|
||||
|
||||
_gfx->readFromPalette(4, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int backgroundWidth = 16;
|
||||
int backgroundHeight = 18;
|
||||
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
|
||||
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
|
||||
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
|
||||
|
||||
file.seek(_variant & GF_ZX_DISC ? 0xfd3 : 0xfc4);
|
||||
_background = loadFrame(&file, background, backgroundWidth, backgroundHeight, front);
|
||||
|
||||
_gfx->readFromPalette(6, r, g, b);
|
||||
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0, 0);
|
||||
_strenghtBackgroundFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xee6 : 0xed7, yellow, black);
|
||||
_strenghtBarFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xf72 : 0xf63, yellow, black);
|
||||
_strenghtWeightsFrames = loadFramesWithHeader(&file, _variant & GF_ZX_DISC ? 0xf92 : 0xf83, 4, yellow, black);
|
||||
|
||||
_flagFrames = loadFramesWithHeader(&file, (_variant & GF_ZX_DISC ? 0x10e4 + 15 : 0x10e4), 4, green, black);
|
||||
|
||||
file.skip(24);
|
||||
int thunderWidth = 4;
|
||||
int thunderHeight = 44;
|
||||
Graphics::ManagedSurface *thunderFrame = new Graphics::ManagedSurface();
|
||||
thunderFrame->create(thunderWidth * 8, thunderHeight, _gfx->_texturePixelFormat);
|
||||
thunderFrame->fillRect(Common::Rect(0, 0, thunderWidth * 8, thunderHeight), 0);
|
||||
thunderFrame = loadFrame(&file, thunderFrame, thunderWidth, thunderHeight, front);
|
||||
|
||||
_thunderFrames.push_back(new Graphics::ManagedSurface);
|
||||
_thunderFrames.push_back(new Graphics::ManagedSurface);
|
||||
|
||||
_thunderFrames[0]->create(thunderWidth * 8 / 2, thunderHeight, _gfx->_texturePixelFormat);
|
||||
_thunderFrames[1]->create(thunderWidth * 8 / 2, thunderHeight, _gfx->_texturePixelFormat);
|
||||
|
||||
_thunderFrames[0]->copyRectToSurface(*thunderFrame, 0, 0, Common::Rect(0, 0, thunderWidth * 8 / 2, thunderHeight));
|
||||
_thunderFrames[1]->copyRectToSurface(*thunderFrame, 0, 0, Common::Rect(thunderWidth * 8 / 2, 0, thunderWidth * 8, thunderHeight));
|
||||
|
||||
Graphics::Surface *tmp;
|
||||
tmp = loadBundledImage("castle_riddle_top_frame");
|
||||
_riddleTopFrame = new Graphics::ManagedSurface;
|
||||
_riddleTopFrame->copyFrom(*tmp);
|
||||
tmp->free();
|
||||
delete tmp;
|
||||
_riddleTopFrame->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
|
||||
tmp = loadBundledImage("castle_riddle_background_frame");
|
||||
_riddleBackgroundFrame = new Graphics::ManagedSurface();
|
||||
_riddleBackgroundFrame->copyFrom(*tmp);
|
||||
tmp->free();
|
||||
delete tmp;
|
||||
_riddleBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
|
||||
tmp = loadBundledImage("castle_riddle_bottom_frame");
|
||||
_riddleBottomFrame = new Graphics::ManagedSurface();
|
||||
_riddleBottomFrame->copyFrom(*tmp);
|
||||
tmp->free();
|
||||
delete tmp;
|
||||
_riddleBottomFrame->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void CastleEngine::drawZXUI(Graphics::Surface *surface) {
|
||||
uint32 color = 5;
|
||||
uint8 r, g, b;
|
||||
|
||||
drawLiftingGate(surface);
|
||||
drawDroppingGate(surface);
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = 0;
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
Common::Rect backRect(123, 179, 242 + 5, 188);
|
||||
surface->fillRect(backRect, black);
|
||||
|
||||
Common::String message;
|
||||
int deadline = -1;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline > 0 && deadline <= _countdown) {
|
||||
//debug("deadline: %d countdown: %d", deadline, _countdown);
|
||||
drawStringInSurface(message, 120, 179, front, black, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else {
|
||||
if (_gameStateControl != kFreescapeGameStateEnd) {
|
||||
if (getGameBit(31)) { // The final cutscene is playing but it is not ended yet
|
||||
drawStringInSurface(_messagesList[5], 120, 179, front, black, surface); // "You did it!"
|
||||
} else
|
||||
drawStringInSurface(_currentArea->_name, 120, 179, front, black, surface);
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < int(_keysCollected.size()); k++) {
|
||||
surface->copyRectToSurface((const Graphics::Surface)*_keysBorderFrames[0], 99 - k * 4, 177, Common::Rect(0, 0, 6, 11));
|
||||
}
|
||||
|
||||
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
|
||||
|
||||
surface->fillRect(Common::Rect(152, 156, 216, 164), green);
|
||||
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 140 + _spiritsMeterPosition, 156, Common::Rect(0, 0, 15, 8));
|
||||
|
||||
surface->fillRect(Common::Rect(64, 155, 64 + 72, 155 + 15), _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00));
|
||||
drawEnergyMeter(surface, Common::Point(64, 155));
|
||||
|
||||
int ticks = g_system->getMillis() / 20;
|
||||
int flagFrameIndex = (ticks / 10) % 4;
|
||||
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 264, 9, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
170
engines/freescape/games/dark/amiga.cpp
Normal file
170
engines/freescape/games/dark/amiga.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/dark/dark.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void DarkEngine::loadAssetsAmigaFullGame() {
|
||||
Common::File file;
|
||||
file.open("0.drk");
|
||||
_title = loadAndConvertNeoImage(&file, 0x9930);
|
||||
file.close();
|
||||
|
||||
Common::SeekableReadStream *stream = decryptFileAmigaAtari("1.drk", "0.drk", 798);
|
||||
parseAmigaAtariHeader(stream);
|
||||
|
||||
_border = loadAndConvertNeoImage(stream, 0x1b762);
|
||||
load8bitBinary(stream, 0x2e96a, 16);
|
||||
loadPalettes(stream, 0x2e528);
|
||||
loadGlobalObjects(stream, 0x30f0 - 50, 24);
|
||||
loadMessagesVariableSize(stream, 0x3d37, 66);
|
||||
loadSoundsFx(stream, 0x34738 + 2, 11);
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
chars = getCharsAmigaAtariInternal(8, 8, - 7 - 8, 16, 16, stream, 0x1b0bc, 85);
|
||||
_fontBig = Font(chars);
|
||||
|
||||
chars = getCharsAmigaAtariInternal(8, 8, 0, 10, 8, stream, 0x1b0bc + 0x430, 85);
|
||||
_fontMedium = Font(chars);
|
||||
|
||||
chars = getCharsAmigaAtariInternal(8, 5, - 7 - 8, 10, 16, stream, 0x1b0bc + 0x430, 85);
|
||||
_fontSmall = Font(chars);
|
||||
_fontSmall.setCharWidth(4);
|
||||
|
||||
_fontLoaded = true;
|
||||
|
||||
GeometricObject *obj = nullptr;
|
||||
obj = (GeometricObject *)_areaMap[15]->objectWithID(18);
|
||||
assert(obj);
|
||||
obj->_cyclingColors = true;
|
||||
|
||||
obj = (GeometricObject *)_areaMap[15]->objectWithID(26);
|
||||
assert(obj);
|
||||
obj->_cyclingColors = true;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int16 id = 227 + i * 6 - 2;
|
||||
for (int j = 0; j < 2; j++) {
|
||||
//debugC(1, kFreescapeDebugParser, "Restoring object %d to from ECD %d", id, index);
|
||||
obj = (GeometricObject *)_areaMap[255]->objectWithID(id);
|
||||
assert(obj);
|
||||
obj->_cyclingColors = true;
|
||||
id--;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &area : _areaMap) {
|
||||
// Center and pad each area name so we do not have to do it at each frame
|
||||
area._value->_name = centerAndPadString(area._value->_name, 26);
|
||||
}
|
||||
}
|
||||
|
||||
void DarkEngine::drawAmigaAtariSTUI(Graphics::Surface *surface) {
|
||||
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xEE, 0xCC, 0x00);
|
||||
uint32 orange = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xEE, 0x88, 0x00);
|
||||
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xEE, 0x00, 0x00);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
|
||||
uint32 transparent = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
|
||||
uint32 grey = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x60, 0x60, 0x60);
|
||||
|
||||
uint32 grey8 = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x88, 0x88, 0x88);
|
||||
uint32 greyA = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xAA, 0xAA, 0xAA);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int ecds = _gameStateVars[kVariableActiveECDs];
|
||||
drawString(kDarkFontSmall, Common::String::format("%04d", int(2 * _position.x())), 19, 178, red, red, black, surface);
|
||||
drawString(kDarkFontSmall, Common::String::format("%04d", int(2 * _position.z())), 19, 184, red, red, black, surface);
|
||||
drawString(kDarkFontSmall, Common::String::format("%04d", int(2 * _position.y())), 19, 190, red, red, black, surface);
|
||||
|
||||
drawString(kDarkFontBig, Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 73, 178, red, red, black, surface);
|
||||
drawString(kDarkFontBig, Common::String::format("%3d", _playerSteps[_playerStepIndex]), 73, 186, red, red, black, surface);
|
||||
drawString(kDarkFontBig, Common::String::format("%07d", score), 93, 16, orange, yellow, black, surface);
|
||||
drawString(kDarkFontBig, Common::String::format("%3d%%", ecds), 181, 16, orange, yellow, black, surface);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawString(kDarkFontSmall, message, 32, 157, grey8, greyA, transparent, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
}
|
||||
|
||||
drawString(kDarkFontSmall, _currentArea->_name, 32, 151, grey8, greyA, transparent, surface);
|
||||
drawBinaryClock(surface, 6, 110, white, grey);
|
||||
|
||||
int x = 229;
|
||||
int y = 180;
|
||||
for (int i = 0; i < _maxShield / 2; i++) {
|
||||
if (i < _gameStateVars[k8bitVariableShield] / 2) {
|
||||
surface->drawLine(x, y, x, y + 3, orange);
|
||||
surface->drawLine(x, y + 1, x, y + 2, yellow);
|
||||
} else
|
||||
surface->drawLine(x, y, x, y + 3, red);
|
||||
x += 2;
|
||||
}
|
||||
|
||||
x = 229;
|
||||
y = 188;
|
||||
for (int i = 0; i < _maxEnergy / 2; i++) {
|
||||
if (i < _gameStateVars[k8bitVariableEnergy] / 2) {
|
||||
surface->drawLine(x, y, x, y + 3, orange);
|
||||
surface->drawLine(x, y + 1, x, y + 2, yellow);
|
||||
} else
|
||||
surface->drawLine(x, y, x, y + 3, red);
|
||||
x += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void DarkEngine::initAmigaAtari() {
|
||||
_viewArea = Common::Rect(32, 33, 287, 130);
|
||||
}
|
||||
|
||||
void DarkEngine::drawString(const DarkFontSize size, const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface) {
|
||||
if (!_fontLoaded)
|
||||
return;
|
||||
|
||||
Font *font = nullptr;
|
||||
|
||||
if (size == kDarkFontBig) {
|
||||
font = &_fontBig;
|
||||
} else if (size == kDarkFontMedium) {
|
||||
font = &_fontMedium;
|
||||
} else if (size == kDarkFontSmall) {
|
||||
font = &_fontSmall;
|
||||
} else {
|
||||
error("Invalid font size %d", size);
|
||||
return;
|
||||
}
|
||||
|
||||
Common::String ustr = str;
|
||||
ustr.toUppercase();
|
||||
font->setBackground(backColor);
|
||||
font->setSecondaryColor(secondaryColor);
|
||||
font->drawString(surface, ustr, x, y, _screenW, primaryColor);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
84
engines/freescape/games/dark/atari.cpp
Normal file
84
engines/freescape/games/dark/atari.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/dark/dark.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void DarkEngine::loadAssetsAtariFullGame() {
|
||||
Common::File file;
|
||||
file.open("0.drk");
|
||||
_title = loadAndConvertNeoImage(&file, 0x13ec);
|
||||
file.close();
|
||||
|
||||
Common::SeekableReadStream *stream = decryptFileAmigaAtari("1.drk", "0.drk", 840);
|
||||
parseAmigaAtariHeader(stream);
|
||||
|
||||
_border = loadAndConvertNeoImage(stream, 0xd710);
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
chars = getCharsAmigaAtariInternal(8, 8, - 7 - 8, 16, 16, stream, 0xd06a, 85);
|
||||
_fontBig = Font(chars);
|
||||
|
||||
chars = getCharsAmigaAtariInternal(8, 8, 0, 10, 8, stream, 0xd49a, 85);
|
||||
_fontMedium = Font(chars);
|
||||
|
||||
chars = getCharsAmigaAtariInternal(8, 5, - 7 - 8, 10, 16, stream, 0xd49a, 85);
|
||||
_fontSmall = Font(chars);
|
||||
_fontSmall.setCharWidth(4);
|
||||
|
||||
_fontLoaded = true;
|
||||
load8bitBinary(stream, 0x20918, 16);
|
||||
loadMessagesVariableSize(stream, 0x3f6f, 66);
|
||||
loadPalettes(stream, 0x204d6);
|
||||
loadGlobalObjects(stream, 0x32f6, 24);
|
||||
loadSoundsFx(stream, 0x266e8, 11);
|
||||
|
||||
GeometricObject *obj = nullptr;
|
||||
obj = (GeometricObject *)_areaMap[15]->objectWithID(18);
|
||||
assert(obj);
|
||||
obj->_cyclingColors = true;
|
||||
|
||||
obj = (GeometricObject *)_areaMap[15]->objectWithID(26);
|
||||
assert(obj);
|
||||
obj->_cyclingColors = true;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int16 id = 227 + i * 6 - 2;
|
||||
for (int j = 0; j < 2; j++) {
|
||||
//debugC(1, kFreescapeDebugParser, "Restoring object %d to from ECD %d", id, index);
|
||||
obj = (GeometricObject *)_areaMap[255]->objectWithID(id);
|
||||
assert(obj);
|
||||
obj->_cyclingColors = true;
|
||||
id--;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &area : _areaMap) {
|
||||
// Center and pad each area name so we do not have to do it at each frame
|
||||
area._value->_name = centerAndPadString(area._value->_name, 26);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
249
engines/freescape/games/dark/c64.cpp
Normal file
249
engines/freescape/games/dark/c64.cpp
Normal file
@@ -0,0 +1,249 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/dark/dark.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void DarkEngine::initC64() {
|
||||
_viewArea = Common::Rect(32, 24, 288, 127);
|
||||
}
|
||||
|
||||
extern byte kC64Palette[16][3];
|
||||
|
||||
void DarkEngine::loadAssetsC64FullGame() {
|
||||
Common::File file;
|
||||
file.open("darkside.c64.data");
|
||||
|
||||
if (_variant & GF_C64_TAPE) {
|
||||
int size = file.size();
|
||||
|
||||
byte *buffer = (byte *)malloc(size * sizeof(byte));
|
||||
file.read(buffer, file.size());
|
||||
|
||||
_extraBuffer = decompressC64RLE(buffer, &size, 0xdf);
|
||||
// size should be the size of the decompressed data
|
||||
Common::MemoryReadStream dfile(_extraBuffer, size, DisposeAfterUse::NO);
|
||||
|
||||
loadMessagesFixedSize(&dfile, 0x1edf, 16, 27);
|
||||
loadFonts(&dfile, 0xc3e);
|
||||
loadGlobalObjects(&dfile, 0x20bd, 23);
|
||||
load8bitBinary(&dfile, 0x9b3e, 16);
|
||||
} else if (_variant & GF_C64_DISC) {
|
||||
loadMessagesFixedSize(&file, 0x16a3, 16, 27);
|
||||
loadFonts(&file, 0x402);
|
||||
|
||||
// It is unclear why this C64 has this byte changed at 0x1881
|
||||
// Once the game is loaded, it will be set to 0x66
|
||||
// and the game will work
|
||||
file.seek(0x1881);
|
||||
_extraBuffer = (byte *)malloc(0x300 * sizeof(byte));
|
||||
file.read(_extraBuffer, 0x300);
|
||||
_extraBuffer[0] = 0x66;
|
||||
Common::MemoryReadStream stream(_extraBuffer, 0x300, DisposeAfterUse::NO);
|
||||
loadGlobalObjects(&stream, 0x0, 23);
|
||||
load8bitBinary(&file, 0x8914, 16);
|
||||
} else
|
||||
error("Unknown C64 variant %x", _variant);
|
||||
|
||||
// The color map from the data is not correct,
|
||||
// so we'll just hardcode the one that we found in the executable
|
||||
|
||||
for (int i = 0; i < 15; i++) {
|
||||
_colorMap[i][0] = 0;
|
||||
_colorMap[i][1] = 0;
|
||||
_colorMap[i][2] = 0;
|
||||
_colorMap[i][3] = 0;
|
||||
}
|
||||
|
||||
_colorMap[1][0] = 0x55;
|
||||
_colorMap[1][1] = 0x55;
|
||||
_colorMap[1][2] = 0x55;
|
||||
_colorMap[1][3] = 0x55;
|
||||
|
||||
_colorMap[2][0] = 0xaa;
|
||||
_colorMap[2][1] = 0xaa;
|
||||
_colorMap[2][2] = 0xaa;
|
||||
_colorMap[2][3] = 0xaa;
|
||||
|
||||
_colorMap[3][0] = 0xff;
|
||||
_colorMap[3][1] = 0xff;
|
||||
_colorMap[3][2] = 0xff;
|
||||
_colorMap[3][3] = 0xff;
|
||||
|
||||
_colorMap[4][0] = 0x44;
|
||||
_colorMap[4][1] = 0x11;
|
||||
_colorMap[4][2] = 0x44;
|
||||
_colorMap[4][3] = 0x11;
|
||||
|
||||
_colorMap[5][0] = 0x88;
|
||||
_colorMap[5][1] = 0x22;
|
||||
_colorMap[5][2] = 0x88;
|
||||
_colorMap[5][3] = 0x22;
|
||||
|
||||
_colorMap[6][0] = 0xcc;
|
||||
_colorMap[6][1] = 0x33;
|
||||
_colorMap[6][2] = 0xcc;
|
||||
_colorMap[6][3] = 0x33;
|
||||
|
||||
_colorMap[7][0] = 0x66;
|
||||
_colorMap[7][1] = 0x99;
|
||||
_colorMap[7][2] = 0x66;
|
||||
_colorMap[7][3] = 0x99;
|
||||
|
||||
_colorMap[8][0] = 0x77;
|
||||
_colorMap[8][1] = 0xdd;
|
||||
_colorMap[8][2] = 0x77;
|
||||
_colorMap[8][3] = 0xdd;
|
||||
|
||||
_colorMap[9][0] = 0xbb;
|
||||
_colorMap[9][1] = 0xee;
|
||||
_colorMap[9][2] = 0xbb;
|
||||
_colorMap[9][3] = 0xee;
|
||||
|
||||
_colorMap[10][0] = 0x5a;
|
||||
_colorMap[10][1] = 0xa5;
|
||||
_colorMap[10][2] = 0x5a;
|
||||
_colorMap[10][3] = 0xa5;
|
||||
|
||||
// TODO
|
||||
_colorMap[12][0] = 0x00;
|
||||
_colorMap[12][1] = 0x00;
|
||||
_colorMap[12][2] = 0x00;
|
||||
_colorMap[12][3] = 0x00;
|
||||
|
||||
_colorMap[13][0] = 0x77;
|
||||
_colorMap[13][1] = 0xdd;
|
||||
_colorMap[13][2] = 0x77;
|
||||
_colorMap[13][3] = 0xdd;
|
||||
|
||||
// TODO
|
||||
_colorMap[14][0] = 0xcc;
|
||||
_colorMap[14][1] = 0xcc;
|
||||
_colorMap[14][2] = 0xcc;
|
||||
_colorMap[14][3] = 0xcc;
|
||||
|
||||
Graphics::Surface *surf = loadBundledImage("dark_border");
|
||||
surf->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
_border = new Graphics::ManagedSurface();
|
||||
_border->copyFrom(*surf);
|
||||
surf->free();
|
||||
delete surf;
|
||||
|
||||
file.close();
|
||||
file.open("darkside.c64.title.bitmap");
|
||||
|
||||
Common::File colorFile1;
|
||||
colorFile1.open("darkside.c64.title.colors1");
|
||||
Common::File colorFile2;
|
||||
colorFile2.open("darkside.c64.title.colors2");
|
||||
|
||||
_title = loadAndConvertDoodleImage(&file, &colorFile1, &colorFile2, (byte *)&kC64Palette);
|
||||
}
|
||||
|
||||
|
||||
void DarkEngine::drawC64UI(Graphics::Surface *surface) {
|
||||
uint8 r, g, b;
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xAA, 0xAA, 0xAA);
|
||||
|
||||
uint32 color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int ecds = _gameStateVars[kVariableActiveECDs];
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 206, 137 + 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 206, 145 + 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 206, 153 + 8, front, back, surface);
|
||||
|
||||
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 68 + 5 + 5, 168 + 9, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 70, 177 + 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%07d", score), 86, 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d%%", ecds), 198, 8, front, back, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 120, 185, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else
|
||||
drawStringInSurface(_currentArea->_name, 120, 185, front, back, surface);
|
||||
|
||||
int energy = _gameStateVars[k8bitVariableEnergy]; // called fuel in this game
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
_gfx->readFromPalette(6, r, g, b); // Violet Blue
|
||||
uint32 outBarColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(14, r, g, b); // Violet
|
||||
uint32 inBarColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(3, r, g, b); // Light Blue
|
||||
uint32 lineColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
Common::Rect coverBar;
|
||||
coverBar = Common::Rect(64, 144, 135, 151);
|
||||
surface->fillRect(coverBar, back);
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect shieldBar;
|
||||
|
||||
shieldBar = Common::Rect(64, 144, 127 - (_maxShield - shield), 151);
|
||||
surface->fillRect(shieldBar, outBarColor);
|
||||
|
||||
shieldBar = Common::Rect(64, 146, 127 - (_maxShield - shield), 149);
|
||||
surface->fillRect(shieldBar, inBarColor);
|
||||
if (shield >= 1)
|
||||
surface->drawLine(64, 147, 127 - (_maxShield - shield) - 1, 147, lineColor);
|
||||
}
|
||||
|
||||
coverBar = Common::Rect(64, 144 + 8, 127, 159);
|
||||
surface->fillRect(coverBar, back);
|
||||
|
||||
if (energy >= 0) {
|
||||
Common::Rect energyBar;
|
||||
energyBar = Common::Rect(64, 144 + 8, 127 - (_maxEnergy - energy), 159);
|
||||
surface->fillRect(energyBar, outBarColor);
|
||||
|
||||
energyBar = Common::Rect(64, 146 + 8, 127 - (_maxEnergy - energy), 157);
|
||||
surface->fillRect(energyBar, inBarColor);
|
||||
if (energy >= 1)
|
||||
surface->drawLine(64, 147 + 8, 127 - (_maxEnergy - energy) - 1, 155, lineColor);
|
||||
}
|
||||
drawBinaryClock(surface, 304, 124, front, back);
|
||||
drawVerticalCompass(surface, 17, 77, _pitch, front);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
171
engines/freescape/games/dark/cpc.cpp
Normal file
171
engines/freescape/games/dark/cpc.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/dark/dark.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void DarkEngine::initCPC() {
|
||||
_viewArea = Common::Rect(36, 24, 284, 125);
|
||||
_soundIndexShoot = 0xa;
|
||||
_soundIndexStart = 0x17;
|
||||
_soundIndexAreaChange = 0x1c;
|
||||
_soundIndexDestroyECD = 0x1b;
|
||||
_soundIndexRestoreECD = 8;
|
||||
}
|
||||
|
||||
extern byte kCPCPaletteTitleData[4][3];
|
||||
extern byte kCPCPaletteBorderData[4][3];
|
||||
|
||||
byte kCPCPaletteDarkTitle[16][3] = {
|
||||
{0x00, 0x00, 0x00}, // 0: X
|
||||
{0xff, 0xff, 0xff}, // 1: ?
|
||||
{0x80, 0x80, 0x80}, // 2: X
|
||||
{0xff, 0x00, 0xff}, // 3: X
|
||||
{0x80, 0x80, 0x80}, // 4: X
|
||||
{0xff, 0xff, 0x00}, // 5: X
|
||||
{0x80, 0x00, 0x00}, // 6: X
|
||||
{0xff, 0x00, 0x00}, // 7: X
|
||||
{0x00, 0x80, 0x80}, // 8: X
|
||||
{0xff, 0x00, 0x80}, // 9: X
|
||||
{0xff, 0x80, 0x00}, // 10: X
|
||||
{0xff, 0x80, 0x80}, // 11: X
|
||||
{0x00, 0xff, 0x00}, // 12: X
|
||||
{0x00, 0x00, 0x80}, // 13: X
|
||||
{0x00, 0x00, 0xff}, // 14: X
|
||||
{0x00, 0x80, 0x00}, // 15: X
|
||||
};
|
||||
|
||||
extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode0);
|
||||
|
||||
void DarkEngine::loadAssetsCPCFullGame() {
|
||||
Common::File file;
|
||||
|
||||
file.open("DARK1.SCR");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DARK1.SCR");
|
||||
|
||||
_title = readCPCImage(&file, false);
|
||||
_title->setPalette((byte*)&kCPCPaletteDarkTitle, 0, 16);
|
||||
|
||||
file.close();
|
||||
file.open("DARK2.SCR");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DARK2.SCR");
|
||||
|
||||
_border = readCPCImage(&file, true);
|
||||
_border->setPalette((byte*)&kCPCPaletteBorderData, 0, 4);
|
||||
|
||||
file.close();
|
||||
file.open("DARKCODE.BIN");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DARKCODE.BIN");
|
||||
|
||||
loadMessagesFixedSize(&file, 0x5d9, 16, 27);
|
||||
loadFonts(&file, 0x60f3);
|
||||
loadGlobalObjects(&file, 0x9a, 23);
|
||||
load8bitBinary(&file, 0x6255, 16);
|
||||
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void DarkEngine::drawCPCUI(Graphics::Surface *surface) {
|
||||
uint32 color = _currentArea->_underFireBackgroundColor;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
// Drawing the horizontal compass should be done first, so that the background is properly filled
|
||||
drawHorizontalCompass(200, 143, _yaw, front, back, surface);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int ecds = _gameStateVars[kVariableActiveECDs];
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 200, 137, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 200, 145, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 200, 153, front, back, surface);
|
||||
|
||||
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 72, 168, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 72, 177, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%07d", score), 95, 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d%%", ecds), 191, 8, front, back, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 111, 173 + 4, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else
|
||||
drawStringInSurface(_currentArea->_name, 111, 173 + 4, front, back, surface);
|
||||
|
||||
int energy = _gameStateVars[k8bitVariableEnergy]; // called fuel in this game
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
_gfx->readFromPalette(_gfx->_inkColor, r, g, b);
|
||||
uint32 inkColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect shieldBar;
|
||||
shieldBar = Common::Rect(72, 141 - 1, 143 - (_maxShield - shield), 146);
|
||||
surface->fillRect(shieldBar, inkColor);
|
||||
|
||||
shieldBar = Common::Rect(72, 143 - 1, 143 - (_maxShield - shield), 144);
|
||||
surface->fillRect(shieldBar, front);
|
||||
}
|
||||
|
||||
if (energy >= 0) {
|
||||
Common::Rect energyBar;
|
||||
energyBar = Common::Rect(72, 147 + 1, 143 - (_maxEnergy - energy), 155 - 1);
|
||||
surface->fillRect(energyBar, inkColor);
|
||||
|
||||
energyBar = Common::Rect(72, 148 + 2, 143 - (_maxEnergy - energy), 154 - 2);
|
||||
surface->fillRect(energyBar, front);
|
||||
}
|
||||
drawBinaryClock(surface, 300, 124, front, back);
|
||||
drawIndicator(surface, 160, 136);
|
||||
drawVerticalCompass(surface, 24, 76, _pitch, front);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
1024
engines/freescape/games/dark/dark.cpp
Normal file
1024
engines/freescape/games/dark/dark.cpp
Normal file
File diff suppressed because it is too large
Load Diff
125
engines/freescape/games/dark/dark.h
Normal file
125
engines/freescape/games/dark/dark.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/* 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 "audio/mixer.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
enum {
|
||||
kVariableDarkEnding = 28,
|
||||
kVariableDarkECD = 29,
|
||||
kVariableActiveECDs = 60,
|
||||
};
|
||||
|
||||
enum {
|
||||
kDarkEndingEvathDestroyed = 1,
|
||||
kDarkEndingECDsDestroyed = 2,
|
||||
};
|
||||
|
||||
struct ECD {
|
||||
uint16 _area;
|
||||
int _id;
|
||||
};
|
||||
|
||||
enum DarkFontSize {
|
||||
kDarkFontSmall,
|
||||
kDarkFontMedium,
|
||||
kDarkFontBig,
|
||||
};
|
||||
|
||||
class DarkEngine : public FreescapeEngine {
|
||||
public:
|
||||
DarkEngine(OSystem *syst, const ADGameDescription *gd);
|
||||
|
||||
uint32 _initialEnergy;
|
||||
uint32 _initialShield;
|
||||
uint32 _jetFuelSeconds;
|
||||
void addSkanner(Area *area);
|
||||
|
||||
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
|
||||
void initGameState() override;
|
||||
void borderScreen() override;
|
||||
bool checkIfGameEnded() override;
|
||||
void endGame() override;
|
||||
|
||||
void gotoArea(uint16 areaID, int entranceID) override;
|
||||
void pressedKey(const int keycode) override;
|
||||
void executePrint(FCLInstruction &instruction) override;
|
||||
|
||||
void initDOS();
|
||||
void initC64();
|
||||
void initAmigaAtari();
|
||||
void initZX();
|
||||
void initCPC();
|
||||
|
||||
void loadAssets() override;
|
||||
void loadAssetsDOSFullGame() override;
|
||||
void loadAssetsDOSDemo() override;
|
||||
void loadAssetsC64FullGame() override;
|
||||
void loadAssetsAmigaFullGame() override;
|
||||
void loadAssetsAtariFullGame() override;
|
||||
|
||||
void loadAssetsCPCFullGame() override;
|
||||
|
||||
void loadAssetsZXDemo() override;
|
||||
void loadAssetsZXFullGame() override;
|
||||
void loadMessagesVariableSize(Common::SeekableReadStream *file, int offset, int number) override;
|
||||
|
||||
int _lastTenSeconds;
|
||||
int _lastSecond;
|
||||
void updateTimeVariables() override;
|
||||
|
||||
void drawBinaryClock(Graphics::Surface *surface, int xPosition, int yPosition, uint32 front, uint32 back);
|
||||
void drawIndicator(Graphics::Surface *surface, int xPosition, int yPosition);
|
||||
|
||||
void drawSensorShoot(Sensor *sensor) override;
|
||||
void drawDOSUI(Graphics::Surface *surface) override;
|
||||
void drawC64UI(Graphics::Surface *surface) override;
|
||||
void drawZXUI(Graphics::Surface *surface) override;
|
||||
void drawCPCUI(Graphics::Surface *surface) override;
|
||||
void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
|
||||
|
||||
Font _fontBig;
|
||||
Font _fontMedium;
|
||||
Font _fontSmall;
|
||||
int _soundIndexRestoreECD;
|
||||
int _soundIndexDestroyECD;
|
||||
Audio::SoundHandle _soundFxHandleJetpack;
|
||||
|
||||
void drawString(const DarkFontSize size, const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface);
|
||||
void drawInfoMenu() override;
|
||||
|
||||
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
|
||||
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
|
||||
|
||||
private:
|
||||
void addECDs(Area *area);
|
||||
void addECD(Area *area, const Math::Vector3d position, int index);
|
||||
void restoreECD(Area &area, int index);
|
||||
bool checkECD(uint16 areaID, int index);
|
||||
bool tryDestroyECD(int index);
|
||||
bool tryDestroyECDFullGame(int index);
|
||||
void addWalls(Area *area);
|
||||
void drawVerticalCompass(Graphics::Surface *surface, int x, int y, float angle, uint32 color);
|
||||
void drawHorizontalCompass(int x, int y, float angle, uint32 front, uint32 back, Graphics::Surface *surface);
|
||||
};
|
||||
|
||||
}
|
||||
250
engines/freescape/games/dark/dos.cpp
Normal file
250
engines/freescape/games/dark/dos.cpp
Normal file
@@ -0,0 +1,250 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/dark/dark.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
extern byte kEGADefaultPalette[16][3];
|
||||
|
||||
byte kDarkCGAPalettePinkBlue[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0xaa, 0xaa},
|
||||
{0xaa, 0x00, 0xaa},
|
||||
{0xaa, 0xaa, 0xaa},
|
||||
};
|
||||
|
||||
byte kDarkCGAPaletteRedGreen[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0xaa, 0x00},
|
||||
{0xaa, 0x00, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
};
|
||||
|
||||
void DarkEngine::initDOS() {
|
||||
if (_renderMode == Common::kRenderEGA)
|
||||
_viewArea = Common::Rect(40, 24, 280, 125);
|
||||
else if (_renderMode == Common::kRenderCGA)
|
||||
_viewArea = Common::Rect(40, 24, 280, 125);
|
||||
else
|
||||
error("Invalid or unknown render mode");
|
||||
|
||||
_maxEnergy = 79;
|
||||
_maxShield = 79;
|
||||
}
|
||||
|
||||
void DarkEngine::loadAssetsDOSDemo() {
|
||||
Common::File file;
|
||||
if (_renderMode == Common::kRenderEGA) {
|
||||
file.open("SCN1E.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
}
|
||||
file.close();
|
||||
file.open("DSIDEE.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DSIDEE.EXE");
|
||||
|
||||
loadSpeakerFxDOS(&file, 0x4837 + 0x200, 0x46e8 + 0x200, 20);
|
||||
loadMessagesFixedSize(&file, 0x4525, 16, 27);
|
||||
loadMessagesFixedSize(&file, 0x993f - 2, 308, 5);
|
||||
loadFonts(&file, 0xa598);
|
||||
loadGlobalObjects(&file, 0x3d04, 23);
|
||||
load8bitBinary(&file, 0xa700, 16);
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
|
||||
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
|
||||
} else if (_renderMode == Common::kRenderCGA) {
|
||||
file.open("SCN1C.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte *)&kDarkCGAPalettePinkBlue, 0, 4);
|
||||
}
|
||||
file.close();
|
||||
file.open("DSIDEC.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DSIDEC.EXE");
|
||||
|
||||
loadSpeakerFxDOS(&file, 0x3077 + 0x200, 0x2f28 + 0x200, 20);
|
||||
loadFonts(&file, 0x8907);
|
||||
loadMessagesFixedSize(&file, 0x2d65, 16, 27);
|
||||
loadMessagesFixedSize(&file, 0x7c3a, 308, 5);
|
||||
loadGlobalObjects(&file, 0x2554, 23);
|
||||
load8bitBinary(&file, 0x8a70, 4);
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte *)&kDarkCGAPalettePinkBlue, 0, 4);
|
||||
|
||||
swapPalette(1);
|
||||
} else
|
||||
error("Invalid or unsupported render mode %s for Dark Side", Common::getRenderModeDescription(_renderMode));
|
||||
}
|
||||
|
||||
void DarkEngine::loadAssetsDOSFullGame() {
|
||||
Common::File file;
|
||||
if (_renderMode == Common::kRenderEGA) {
|
||||
file.open("SCN1E.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
}
|
||||
file.close();
|
||||
file.open("DSIDEE.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DSIDEE.EXE");
|
||||
|
||||
loadSpeakerFxDOS(&file, 0x4837 + 0x200, 0x46e8 + 0x200, 20);
|
||||
loadFonts(&file, 0xa113);
|
||||
loadMessagesFixedSize(&file, 0x4525, 16, 27);
|
||||
loadGlobalObjects(&file, 0x3d04, 23);
|
||||
load8bitBinary(&file, 0xa280, 16);
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
|
||||
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
|
||||
} else if (_renderMode == Common::kRenderCGA) {
|
||||
file.open("SCN1C.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte *)&kDarkCGAPalettePinkBlue, 0, 4);
|
||||
}
|
||||
file.close();
|
||||
file.open("DSIDEC.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DSIDEC.EXE");
|
||||
|
||||
loadSpeakerFxDOS(&file, 0x3077 + 0x200, 0x2f28 + 0x200, 20);
|
||||
loadFonts(&file, 0x8497);
|
||||
loadMessagesFixedSize(&file, 0x2d65, 16, 27);
|
||||
loadGlobalObjects(&file, 0x2554, 23);
|
||||
load8bitBinary(&file, 0x8600, 16);
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte *)&kDarkCGAPalettePinkBlue, 0, 4);
|
||||
|
||||
swapPalette(1);
|
||||
} else
|
||||
error("Invalid or unsupported render mode %s for Dark Side", Common::getRenderModeDescription(_renderMode));
|
||||
}
|
||||
|
||||
void DarkEngine::drawDOSUI(Graphics::Surface *surface) {
|
||||
uint32 color = _renderMode == Common::kRenderCGA ? 3 : 14;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
// Drawing the horizontal compass should be done first, so that the background is properly filled
|
||||
drawHorizontalCompass(200, 143, _yaw, front, back, surface);
|
||||
Common::Rect stepBackgroundRect = Common::Rect(69, 177, 98, 185);
|
||||
surface->fillRect(stepBackgroundRect, back);
|
||||
|
||||
Common::Rect positionBackgroundRect = Common::Rect(199, 135, 232, 160);
|
||||
surface->fillRect(positionBackgroundRect, back);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int ecds = _gameStateVars[kVariableActiveECDs];
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 199, 137, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 199, 145, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 199, 153, front, back, surface);
|
||||
|
||||
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 71, 168, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 71, 177, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%07d", score), 95, 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d%%", ecds), 192, 8, front, back, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 112, 177, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else
|
||||
drawStringInSurface(_currentArea->_name, 112, 177, front, back, surface);
|
||||
|
||||
int energy = _gameStateVars[k8bitVariableEnergy]; // called fuel in this game
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
_gfx->readFromPalette(_renderMode == Common::kRenderCGA ? 1 : 9, r, g, b);
|
||||
uint32 blue = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect shieldBar;
|
||||
shieldBar = Common::Rect(72, 140, 151 - (_maxShield - shield), 141); // Upper outer shieldBar
|
||||
surface->fillRect(shieldBar, front);
|
||||
shieldBar = Common::Rect(72, 145, 151 - (_maxShield - shield), 146); // Lower outer shieldBar
|
||||
surface->fillRect(shieldBar, front);
|
||||
|
||||
shieldBar = Common::Rect(72, 142, 151 - (_maxShield - shield), 144); // Inner shieldBar
|
||||
surface->fillRect(shieldBar, blue);
|
||||
}
|
||||
|
||||
if (energy >= 0) {
|
||||
Common::Rect energyBar;
|
||||
energyBar = Common::Rect(72, 148, 151 - (_maxEnergy - energy), 149); // Upper outer energyBar
|
||||
surface->fillRect(energyBar, front);
|
||||
energyBar = Common::Rect(72, 153, 151 - (_maxEnergy - energy), 154); // Lower outer energyBar
|
||||
surface->fillRect(energyBar, front);
|
||||
|
||||
energyBar = Common::Rect(72, 150, 151 - (_maxEnergy - energy), 152); // Inner energyBar
|
||||
surface->fillRect(energyBar, blue);
|
||||
}
|
||||
uint32 clockColor = _renderMode == Common::kRenderCGA ? front : _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
drawBinaryClock(surface, 300, 124, clockColor, back);
|
||||
drawIndicator(surface, 160, 136);
|
||||
drawVerticalCompass(surface, 24, 76, _pitch, blue);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
206
engines/freescape/games/dark/zx.cpp
Normal file
206
engines/freescape/games/dark/zx.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/dark/dark.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void DarkEngine::initZX() {
|
||||
_viewArea = Common::Rect(56, 28, 265, 132);
|
||||
_maxEnergy = 63;
|
||||
_maxShield = 63;
|
||||
|
||||
_soundIndexShoot = 1;
|
||||
_soundIndexCollide = -1; // Scripted
|
||||
_soundIndexStepDown = 3;
|
||||
_soundIndexStepUp = 4;
|
||||
_soundIndexMenu = 25;
|
||||
_soundIndexStart = 11;
|
||||
_soundIndexAreaChange = 0x1c;
|
||||
_soundIndexRestoreECD = 30;
|
||||
|
||||
_soundIndexNoShield = 14;
|
||||
_soundIndexNoEnergy = 14;
|
||||
_soundIndexFallen = 7;
|
||||
_soundIndexTimeout = 14;
|
||||
_soundIndexForceEndGame = 14;
|
||||
_soundIndexCrushed = 25;
|
||||
_soundIndexMissionComplete = 8;
|
||||
}
|
||||
|
||||
void DarkEngine::loadAssetsZXFullGame() {
|
||||
Common::File file;
|
||||
|
||||
file.open("darkside.zx.title");
|
||||
if (file.isOpen()) {
|
||||
_title = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find darkside.zx.title");
|
||||
|
||||
file.close();
|
||||
file.open("darkside.zx.border");
|
||||
if (file.isOpen()) {
|
||||
_border = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find driller.zx.border");
|
||||
file.close();
|
||||
|
||||
file.open("darkside.zx.data");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open darksize.zx.data");
|
||||
|
||||
loadMessagesFixedSize(&file, 0x56b - 6, 16, 27);
|
||||
|
||||
loadFonts(&file, 0x5d60 - 6);
|
||||
loadGlobalObjects(&file, 0x1a, 23);
|
||||
load8bitBinary(&file, 0x5ec0 - 4, 4);
|
||||
loadSpeakerFxZX(&file, 0x9c1, 0xa55);
|
||||
|
||||
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void DarkEngine::loadAssetsZXDemo() {
|
||||
Common::File file;
|
||||
|
||||
file.open("darkside.zx.title");
|
||||
if (file.isOpen()) {
|
||||
_title = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find darkside.zx.title");
|
||||
|
||||
file.close();
|
||||
file.open("darkside.zx.border");
|
||||
if (file.isOpen()) {
|
||||
_border = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find driller.zx.border");
|
||||
file.close();
|
||||
|
||||
file.open("darkside.zx.data");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open darksize.zx.data");
|
||||
|
||||
loadMessagesFixedSize(&file, 0x56b, 16, 27);
|
||||
loadMessagesFixedSize(&file, 0x5761, 264, 5);
|
||||
loadSpeakerFxZX(&file, 0x9c7, 0xa5b);
|
||||
|
||||
loadFonts(&file, 0x6164);
|
||||
loadGlobalObjects(&file, 0x20, 23);
|
||||
load8bitBinary(&file, 0x62c6, 4);
|
||||
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
|
||||
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void DarkEngine::drawZXUI(Graphics::Surface *surface) {
|
||||
uint32 color = 7;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
uint32 transparent = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
// Drawing the horizontal compass should be done first, so that the background is properly filled
|
||||
drawHorizontalCompass(192, 141, _yaw, front, back, surface);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int ecds = _gameStateVars[kVariableActiveECDs];
|
||||
surface->fillRect(Common::Rect(193, 140, 223, 163), back);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 191, 141, front, transparent, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 191, 149, front, transparent, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 191, 157, front, transparent, surface);
|
||||
|
||||
surface->fillRect(Common::Rect(80, 165, 95, 172), back);
|
||||
surface->fillRect(Common::Rect(80, 172, 102, 179), back);
|
||||
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 79, 165, front, transparent, surface);
|
||||
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 79, 173, front, transparent, surface);
|
||||
surface->fillRect(Common::Rect(96, 12, 151, 19), back);
|
||||
drawStringInSurface(Common::String::format("%07d", score), 95, 13, front, transparent, surface);
|
||||
drawStringInSurface(Common::String::format("%3d%%", ecds), 191, 13, front, back, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 112, 173, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else
|
||||
drawStringInSurface(_currentArea->_name, 112, 173, front, back, surface);
|
||||
|
||||
int energy = _gameStateVars[k8bitVariableEnergy]; // called fuel in this game
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect shieldBar;
|
||||
shieldBar = Common::Rect(80, 141, 143 - (_maxShield - shield), 148);
|
||||
surface->fillRect(shieldBar, back);
|
||||
|
||||
shieldBar = Common::Rect(80, 142, 143 - (_maxShield - shield), 147);
|
||||
surface->fillRect(shieldBar, front);
|
||||
|
||||
shieldBar = Common::Rect(80, 144, 143 - (_maxShield - shield), 145);
|
||||
surface->fillRect(shieldBar, back);
|
||||
}
|
||||
|
||||
if (energy >= 0) {
|
||||
Common::Rect energyBar;
|
||||
energyBar = Common::Rect(80, 148, 143 - (_maxEnergy - energy), 155);
|
||||
surface->fillRect(energyBar, back);
|
||||
|
||||
energyBar = Common::Rect(80, 149, 143 - (_maxEnergy - energy), 154);
|
||||
surface->fillRect(energyBar, front);
|
||||
|
||||
energyBar = Common::Rect(80, 151, 143 - (_maxEnergy - energy), 152);
|
||||
surface->fillRect(energyBar, back);
|
||||
}
|
||||
uint32 clockColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0x00, 0x00);
|
||||
drawBinaryClock(surface, 273, 128, clockColor, back);
|
||||
drawIndicator(surface, 152, 140);
|
||||
drawVerticalCompass(surface, 47, 79, _pitch, front);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
349
engines/freescape/games/driller/amiga.cpp
Normal file
349
engines/freescape/games/driller/amiga.cpp
Normal file
@@ -0,0 +1,349 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/driller/driller.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void DrillerEngine::loadAssetsAmigaFullGame() {
|
||||
Common::File file;
|
||||
if (_variant & GF_AMIGA_RETAIL) {
|
||||
file.open("driller");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'driller' executable for Amiga");
|
||||
|
||||
_border = loadAndConvertNeoImage(&file, 0x137f4);
|
||||
_title = loadAndConvertNeoImage(&file, 0xce);
|
||||
|
||||
loadFonts(&file, 0x8940);
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, &file, 0x8940 + 112 * 33 + 1, 100);
|
||||
_fontSmall = Font(chars);
|
||||
_fontSmall.setCharWidth(5);
|
||||
|
||||
loadMessagesFixedSize(&file, 0xc66e, 14, 20);
|
||||
loadGlobalObjects(&file, 0xbd62, 8);
|
||||
load8bitBinary(&file, 0x29c16, 16);
|
||||
loadPalettes(&file, 0x297d4);
|
||||
loadSoundsFx(&file, 0x30e80, 25);
|
||||
} else if (_variant & GF_AMIGA_BUDGET) {
|
||||
file.open("lift.neo");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'lift.neo' file");
|
||||
|
||||
_title = loadAndConvertNeoImage(&file, 0);
|
||||
|
||||
file.close();
|
||||
file.open("console.neo");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'console.neo' file");
|
||||
|
||||
_border = loadAndConvertNeoImage(&file, 0);
|
||||
|
||||
file.close();
|
||||
file.open("driller");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'driller' executable for Amiga");
|
||||
|
||||
loadFonts(&file, 0xa62);
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, &file, 0xa62 + 112 * 33 + 1, 100);
|
||||
_fontSmall = Font(chars);
|
||||
_fontSmall.setCharWidth(5);
|
||||
|
||||
loadMessagesFixedSize(&file, 0x499a, 14, 20);
|
||||
loadGlobalObjects(&file, 0x4098, 8);
|
||||
load8bitBinary(&file, 0x21a3e, 16);
|
||||
loadPalettes(&file, 0x215fc);
|
||||
|
||||
file.close();
|
||||
file.open("soundfx");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'soundfx' executable for Amiga");
|
||||
|
||||
loadSoundsFx(&file, 0, 25);
|
||||
} else
|
||||
error("Invalid or unknown Amiga release");
|
||||
|
||||
|
||||
for (auto &area : _areaMap) {
|
||||
// Center and pad each area name so we do not have to do it at each frame
|
||||
area._value->_name = centerAndPadString(area._value->_name, 14);
|
||||
}
|
||||
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_0"));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_1"));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_2"));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_3"));
|
||||
_indicators.push_back(loadBundledImage("driller_ship_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void DrillerEngine::loadAssetsAmigaDemo() {
|
||||
Common::File file;
|
||||
file.open("lift.neo");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'lift.neo' file");
|
||||
|
||||
_title = loadAndConvertNeoImage(&file, 0);
|
||||
|
||||
file.close();
|
||||
file.open("console.neo");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'console.neo' file");
|
||||
|
||||
_border = loadAndConvertNeoImage(&file, 0);
|
||||
|
||||
file.close();
|
||||
file.open("demo.cmd");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'demo.cmd' file");
|
||||
|
||||
loadDemoData(&file, 0, 0x1000);
|
||||
|
||||
file.close();
|
||||
file.open("driller");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'driller' file");
|
||||
|
||||
if (_variant & GF_AMIGA_MAGAZINE_DEMO) {
|
||||
loadMessagesFixedSize(&file, 0x3df0, 14, 20);
|
||||
loadGlobalObjects(&file, 0x3ba6, 8);
|
||||
_demoMode = false;
|
||||
|
||||
loadFonts(&file, 0xa62);
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, &file, 0xa62 + 112 * 33 + 1, 100);
|
||||
_fontSmall = Font(chars);
|
||||
_fontSmall.setCharWidth(5);
|
||||
} else {
|
||||
loadFonts(&file, 0xa30);
|
||||
loadMessagesFixedSize(&file, 0x3960, 14, 20);
|
||||
loadGlobalObjects(&file, 0x3716, 8);
|
||||
}
|
||||
|
||||
file.close();
|
||||
file.open("data");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'data' file");
|
||||
|
||||
load8bitBinary(&file, 0x442, 16);
|
||||
loadPalettes(&file, 0x0);
|
||||
|
||||
file.close();
|
||||
file.open("soundfx");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'soundfx' executable for Amiga");
|
||||
|
||||
loadSoundsFx(&file, 0, 25);
|
||||
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_0"));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_1"));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_2"));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_3"));
|
||||
_indicators.push_back(loadBundledImage("driller_ship_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
/*
|
||||
The following function contains specific UI code for both Amiga and AtariST
|
||||
*/
|
||||
|
||||
void DrillerEngine::drawAmigaAtariSTUI(Graphics::Surface *surface) {
|
||||
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0x55);
|
||||
uint32 brownish = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x9E, 0x80, 0x20);
|
||||
uint32 brown = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x7E, 0x60, 0x19);
|
||||
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xE0, 0x00, 0x00);
|
||||
uint32 redish = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xE0, 0x60, 0x20);
|
||||
uint32 primaryFontColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xA0, 0x80, 0x00);
|
||||
uint32 secondaryFontColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x60, 0x40, 0x00);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
|
||||
uint32 transparent = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
Common::String coords;
|
||||
|
||||
// It seems that some demos will not include the complete font
|
||||
if (!isDemo() || (_variant & GF_AMIGA_MAGAZINE_DEMO) || (_variant & GF_ATARI_MAGAZINE_DEMO)) {
|
||||
|
||||
drawString(kDrillerFontSmall, ":", 38, 18, white, white, transparent, surface); // ":" is the next character to "9" representing "x"
|
||||
coords = Common::String::format("%04d", 2 * int(_position.x()));
|
||||
drawString(kDrillerFontSmall, coords, 47, 18, white, transparent, transparent, surface);
|
||||
|
||||
drawString(kDrillerFontSmall, ";", 37, 26, white, white, transparent, surface); // ";" is the next character to ":" representing "y"
|
||||
coords = Common::String::format("%04d", 2 * int(_position.z())); // Coords y and z are swapped!
|
||||
drawString(kDrillerFontSmall, coords, 47, 26, white, transparent, transparent, surface);
|
||||
|
||||
drawString(kDrillerFontSmall, "<", 37, 34, white, white, transparent, surface); // "<" is the next character to ";" representing "z"
|
||||
coords = Common::String::format("%04d", 2 * int(_position.y())); // Coords y and z are swapped!
|
||||
drawString(kDrillerFontSmall, coords, 47, 34, white, transparent, transparent, surface);
|
||||
}
|
||||
|
||||
drawStringInSurface(_currentArea->_name, 189, 185, primaryFontColor, secondaryFontColor, black, surface);
|
||||
drawStringInSurface(Common::String::format("%07d", score), 241, 129, primaryFontColor, secondaryFontColor, black, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
drawStringInSurface(Common::String::format("%02d:", hours), 210, 7, primaryFontColor, secondaryFontColor, black, surface);
|
||||
drawStringInSurface(Common::String::format("%02d:", minutes), 230, 7, primaryFontColor, secondaryFontColor, black, surface);
|
||||
drawStringInSurface(Common::String::format("%02d", seconds), 254, 7, primaryFontColor, secondaryFontColor, black, surface);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 188, 177, yellow, secondaryFontColor, black, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else {
|
||||
if (_currentArea->_gasPocketRadius == 0)
|
||||
message = _messagesList[2];
|
||||
else if (_drillStatusByArea[_currentArea->getAreaID()])
|
||||
message = _messagesList[0];
|
||||
else
|
||||
message = _messagesList[1];
|
||||
|
||||
drawStringInSurface(message, 188, 177, primaryFontColor, secondaryFontColor, black, surface);
|
||||
}
|
||||
|
||||
int energy = _gameStateVars[k8bitVariableEnergy];
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect shieldBar;
|
||||
shieldBar = Common::Rect(11, 178, 74 - (_maxShield - shield), 184);
|
||||
surface->fillRect(shieldBar, brown);
|
||||
|
||||
if (shield > 11)
|
||||
shieldBar = Common::Rect(11, 178, 25, 184);
|
||||
else
|
||||
shieldBar = Common::Rect(11, 178, 74 - (_maxShield - shield), 184);
|
||||
surface->fillRect(shieldBar, red);
|
||||
|
||||
shieldBar = Common::Rect(11, 179, 74 - (_maxShield - shield), 183);
|
||||
surface->fillRect(shieldBar, brownish);
|
||||
|
||||
if (shield > 11)
|
||||
shieldBar = Common::Rect(11, 179, 25, 183);
|
||||
else
|
||||
shieldBar = Common::Rect(11, 179, 74 - (_maxShield - shield), 183);
|
||||
surface->fillRect(shieldBar, redish);
|
||||
|
||||
shieldBar = Common::Rect(11, 180, 74 - (_maxShield - shield), 182);
|
||||
surface->fillRect(shieldBar, yellow);
|
||||
}
|
||||
|
||||
if (energy >= 0) {
|
||||
Common::Rect energyBar;
|
||||
energyBar = Common::Rect(11, 186, 74 - (_maxEnergy - energy), 192);
|
||||
surface->fillRect(energyBar, brown);
|
||||
|
||||
if (energy > 11)
|
||||
energyBar = Common::Rect(11, 186, 24, 192);
|
||||
else
|
||||
energyBar = Common::Rect(11, 186, 74 - (_maxEnergy - energy), 192);
|
||||
surface->fillRect(energyBar, red);
|
||||
|
||||
energyBar = Common::Rect(11, 187, 74 - (_maxEnergy - energy), 191);
|
||||
surface->fillRect(energyBar, brownish);
|
||||
|
||||
if (energy > 11)
|
||||
energyBar = Common::Rect(11, 187, 24, 191);
|
||||
else
|
||||
energyBar = Common::Rect(11, 187, 74 - (_maxEnergy - energy), 191);
|
||||
surface->fillRect(energyBar, redish);
|
||||
|
||||
energyBar = Common::Rect(11, 188, 74 - (_maxEnergy - energy), 190);
|
||||
surface->fillRect(energyBar, yellow);
|
||||
}
|
||||
|
||||
if (_indicators.size() > 0) {
|
||||
if (_flyMode)
|
||||
surface->copyRectToSurface(*_indicators[4], 106, 128, Common::Rect(_indicators[1]->w, _indicators[1]->h));
|
||||
else
|
||||
surface->copyRectToSurface(*_indicators[_playerHeightNumber], 106, 128, Common::Rect(_indicators[1]->w, _indicators[1]->h));
|
||||
}
|
||||
}
|
||||
|
||||
void DrillerEngine::drawString(const DrillerFontSize size, const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface) {
|
||||
if (!_fontLoaded)
|
||||
return;
|
||||
|
||||
Font *font = nullptr;
|
||||
|
||||
if (size == kDrillerFontNormal) {
|
||||
font = &_font;
|
||||
} else if (size == kDrillerFontSmall) {
|
||||
font = &_fontSmall;
|
||||
} else {
|
||||
error("Invalid font size %d", size);
|
||||
return;
|
||||
}
|
||||
|
||||
Common::String ustr = str;
|
||||
ustr.toUppercase();
|
||||
font->setBackground(backColor);
|
||||
font->setSecondaryColor(secondaryColor);
|
||||
font->drawString(surface, ustr, x, y, _screenW, primaryColor);
|
||||
}
|
||||
|
||||
void DrillerEngine::initAmigaAtari() {
|
||||
_viewArea = Common::Rect(36, 16, 284, 118);
|
||||
|
||||
_moveFowardArea = Common::Rect(184, 125, 199, 144);
|
||||
_moveLeftArea = Common::Rect(161, 145, 174, 164);
|
||||
_moveRightArea = Common::Rect(207, 145, 222, 164);
|
||||
_moveBackArea = Common::Rect(184, 152, 199, 171);
|
||||
_moveUpArea = Common::Rect(231, 145, 246, 164);
|
||||
_moveDownArea = Common::Rect(254, 145, 269, 164);
|
||||
_deployDrillArea = Common::Rect(284, 145, 299, 166);
|
||||
_infoScreenArea = Common::Rect(125, 172, 152, 197);
|
||||
_saveGameArea = Common::Rect(9, 145, 39, 154);
|
||||
_loadGameArea = Common::Rect(9, 156, 39, 164);
|
||||
|
||||
_borderExtra = nullptr;
|
||||
_borderExtraTexture = nullptr;
|
||||
|
||||
_soundIndexShoot = 1;
|
||||
_soundIndexCollide = 19;
|
||||
_soundIndexStepDown = 19;
|
||||
_soundIndexStepUp = 19;
|
||||
_soundIndexAreaChange = 5;
|
||||
_soundIndexHit = 2;
|
||||
_soundIndexFall = 25;
|
||||
_soundIndexFallen = 11;
|
||||
_soundIndexForceEndGame = 11;
|
||||
_soundIndexNoShield = 11;
|
||||
_soundIndexNoEnergy = 11;
|
||||
_soundIndexTimeout = 11;
|
||||
_soundIndexCrushed = 11;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
386
engines/freescape/games/driller/atari.cpp
Normal file
386
engines/freescape/games/driller/atari.cpp
Normal file
@@ -0,0 +1,386 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
#include "common/endian.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/driller/driller.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
namespace {
|
||||
// A simple implementation of memmem, which is a non-standard GNU extension.
|
||||
const void *local_memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) {
|
||||
if (needle_len == 0) {
|
||||
return haystack;
|
||||
}
|
||||
if (haystack_len < needle_len) {
|
||||
return nullptr;
|
||||
}
|
||||
const char *h = (const char *)haystack;
|
||||
for (size_t i = 0; i <= haystack_len - needle_len; ++i) {
|
||||
if (memcmp(h + i, needle, needle_len) == 0) {
|
||||
return h + i;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Common::SeekableReadStream *DrillerEngine::decryptFileAtariVirtualWorlds(const Common::Path &filename) {
|
||||
Common::File file;
|
||||
if (!file.open(filename)) {
|
||||
error("Failed to open %s", filename.toString().c_str());
|
||||
}
|
||||
const int size = file.size();
|
||||
byte *data = (byte *)malloc(size);
|
||||
file.read(data, size);
|
||||
|
||||
int start = 0;
|
||||
int valid_offset = -1;
|
||||
int chunk_size = 0;
|
||||
|
||||
while (true) {
|
||||
const byte *found = (const byte *)local_memmem(data + start, size - start, "CBCP", 4);
|
||||
if (!found) break;
|
||||
|
||||
int idx = found - data;
|
||||
if (idx + 8 <= size) {
|
||||
int sz = READ_BE_UINT32(data + idx + 4);
|
||||
if (sz > 0 && sz < size + 0x20000) {
|
||||
valid_offset = idx;
|
||||
chunk_size = sz;
|
||||
}
|
||||
}
|
||||
start = idx + 1;
|
||||
}
|
||||
|
||||
if (valid_offset == -1) {
|
||||
error("No valid CBCP chunk found in %s", filename.toString().c_str());
|
||||
}
|
||||
|
||||
const byte *payload = data + valid_offset + 8;
|
||||
const int payload_size = chunk_size;
|
||||
|
||||
if (payload_size < 12) {
|
||||
error("Payload too short in %s", filename.toString().c_str());
|
||||
}
|
||||
|
||||
uint32 bit_buf_init = READ_BE_UINT32(payload + payload_size - 12);
|
||||
uint32 checksum_init = READ_BE_UINT32(payload + payload_size - 8);
|
||||
uint32 decoded_size = READ_BE_UINT32(payload + payload_size - 4);
|
||||
|
||||
byte *out_buffer = (byte *)malloc(decoded_size);
|
||||
int dst_idx = decoded_size;
|
||||
|
||||
struct BitStream {
|
||||
const byte *_src_data;
|
||||
int _src_idx;
|
||||
uint32 _bit_buffer;
|
||||
uint32 _checksum;
|
||||
int _refill_carry;
|
||||
|
||||
BitStream(const byte *src_data, int start_idx, uint32 bit_buffer, uint32 checksum) :
|
||||
_src_data(src_data), _src_idx(start_idx), _bit_buffer(bit_buffer), _checksum(checksum), _refill_carry(0) {}
|
||||
|
||||
void refill() {
|
||||
if (_src_idx < 0) {
|
||||
_refill_carry = 0;
|
||||
_bit_buffer = 0x80000000;
|
||||
return;
|
||||
}
|
||||
uint32 val = READ_BE_UINT32(_src_data + _src_idx);
|
||||
_src_idx -= 4;
|
||||
_checksum ^= val;
|
||||
_refill_carry = val & 1;
|
||||
_bit_buffer = (val >> 1) | 0x80000000;
|
||||
}
|
||||
|
||||
int getBits(int count) {
|
||||
uint32 result = 0;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
int carry = _bit_buffer & 1;
|
||||
_bit_buffer >>= 1;
|
||||
if (_bit_buffer == 0) {
|
||||
refill();
|
||||
carry = _refill_carry;
|
||||
}
|
||||
result = (result << 1) | carry;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
int src_idx = payload_size - 16;
|
||||
uint32 checksum = checksum_init ^ bit_buf_init;
|
||||
BitStream bs(payload, src_idx, bit_buf_init, checksum);
|
||||
|
||||
while (dst_idx > 0) {
|
||||
if (bs.getBits(1) == 0) {
|
||||
if (bs.getBits(1) == 1) {
|
||||
int offset = bs.getBits(8);
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
dst_idx--;
|
||||
if (dst_idx >= 0) {
|
||||
out_buffer[dst_idx] = out_buffer[dst_idx + offset];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int count = bs.getBits(3) + 1;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
dst_idx--;
|
||||
if (dst_idx >= 0) {
|
||||
out_buffer[dst_idx] = bs.getBits(8);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int tag = bs.getBits(2);
|
||||
if (tag == 3) {
|
||||
int count = bs.getBits(8) + 9;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
dst_idx--;
|
||||
if (dst_idx >= 0) {
|
||||
out_buffer[dst_idx] = bs.getBits(8);
|
||||
}
|
||||
}
|
||||
} else if (tag == 2) {
|
||||
int length = bs.getBits(8) + 1;
|
||||
int offset = bs.getBits(12);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
dst_idx--;
|
||||
if (dst_idx >= 0) {
|
||||
out_buffer[dst_idx] = out_buffer[dst_idx + offset];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int bits_offset = 9 + tag;
|
||||
int length = 3 + tag;
|
||||
int offset = bs.getBits(bits_offset);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
dst_idx--;
|
||||
if (dst_idx >= 0) {
|
||||
out_buffer[dst_idx] = out_buffer[dst_idx + offset];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
return new Common::MemoryReadStream(out_buffer, decoded_size);
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *DrillerEngine::decryptFileAtari(const Common::Path &filename) {
|
||||
Common::File file;
|
||||
file.open(filename);
|
||||
if (!file.isOpen())
|
||||
error("Failed to open %s", filename.toString().c_str());
|
||||
|
||||
int size = file.size();
|
||||
byte *encryptedBuffer = (byte *)malloc(size);
|
||||
file.read(encryptedBuffer, size);
|
||||
file.close();
|
||||
|
||||
byte *a6 = encryptedBuffer + 0x118;
|
||||
byte *a5 = encryptedBuffer + size - 4;
|
||||
uint64 key = 0xb9f11bce;
|
||||
|
||||
while (a6 <= a5) {
|
||||
uint64 d0 = (a6[0] << 24) | (a6[1] << 16) | (a6[2] << 8) | a6[3];
|
||||
d0 += key;
|
||||
d0 = uint32(d0);
|
||||
|
||||
a6[0] = byte((d0 >> 24) & 0xFF);
|
||||
a6[1] = byte((d0 >> 16) & 0xFF);
|
||||
a6[2] = byte((d0 >> 8) & 0xFF);
|
||||
a6[3] = byte(d0 & 0xFF);
|
||||
|
||||
key += 0x51684624;
|
||||
key = uint32(key);
|
||||
a6 += 4;
|
||||
}
|
||||
|
||||
return (new Common::MemoryReadStream(encryptedBuffer, size));
|
||||
}
|
||||
|
||||
void DrillerEngine::loadAssetsAtariFullGame() {
|
||||
Common::SeekableReadStream *stream = nullptr;
|
||||
if (_variant & GF_ATARI_RETAIL) {
|
||||
stream = decryptFileAtari("x.prg");
|
||||
|
||||
_border = loadAndConvertNeoImage(stream, 0x14b96);
|
||||
_borderExtra = loadAndConvertNeoImage(stream, 0x1c916);
|
||||
_title = loadAndConvertNeoImage(stream, 0x3f6);
|
||||
|
||||
loadFonts(stream, 0x8a92);
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, stream, 0x8a92 + 112 * 33 + 1, 100);
|
||||
_fontSmall = Font(chars);
|
||||
_fontSmall.setCharWidth(5);
|
||||
|
||||
loadMessagesFixedSize(stream, 0xda22, 14, 20);
|
||||
loadGlobalObjects(stream, 0xd116, 8);
|
||||
load8bitBinary(stream, 0x2afb8, 16);
|
||||
loadPalettes(stream, 0x2ab76);
|
||||
loadSoundsFx(stream, 0x30da6 + 0x147c, 25);
|
||||
} else if (_variant & GF_ATARI_BUDGET) {
|
||||
Common::File file;
|
||||
file.open("x.prg");
|
||||
|
||||
if (!file.isOpen()) {
|
||||
stream = decryptFileAtariVirtualWorlds("dril.all");
|
||||
} else
|
||||
stream = &file;
|
||||
|
||||
if (isSpaceStationOblivion()) {
|
||||
_border = loadAndConvertNeoImage(&file, 0x13544);
|
||||
byte palette[16 * 3];
|
||||
for (int i = 0; i < 16; i++) { // gray scale palette
|
||||
palette[i * 3 + 0] = i * (255 / 16);
|
||||
palette[i * 3 + 1] = i * (255 / 16);
|
||||
palette[i * 3 + 2] = i * (255 / 16);
|
||||
}
|
||||
_title = loadAndConvertNeoImage(&file, 0x10, palette);
|
||||
|
||||
loadFonts(&file, 0x8a32 - 0x1d6);
|
||||
loadMessagesFixedSize(&file, 0xc5d8 - 0x1da, 14, 20);
|
||||
loadGlobalObjects(&file, 0xbccc - 0x1da, 8);
|
||||
load8bitBinary(&file, 0x29b3c - 0x1d6, 16);
|
||||
loadPalettes(&file, 0x296fa - 0x1d6);
|
||||
loadSoundsFx(&file, 0x30da6 - 0x1d6, 25);
|
||||
} else {
|
||||
_border = loadAndConvertNeoImage(stream, 0x1371a);
|
||||
_title = loadAndConvertNeoImage(stream, 0x396);
|
||||
|
||||
loadFonts(stream, 0x8a32);
|
||||
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, stream, 0x8a32 + 112 * 33 + 1, 100);
|
||||
_fontSmall = Font(chars);
|
||||
_fontSmall.setCharWidth(5);
|
||||
|
||||
loadMessagesFixedSize(stream, 0xc5d8, 14, 20);
|
||||
loadGlobalObjects(stream, 0xbccc, 8);
|
||||
load8bitBinary(stream, 0x29b3c, 16);
|
||||
loadPalettes(stream, 0x296fa);
|
||||
loadSoundsFx(stream, 0x30da6, 25);
|
||||
}
|
||||
} else
|
||||
error("Unknown Atari ST Driller variant");
|
||||
|
||||
for (auto &area : _areaMap) {
|
||||
// Center and pad each area name so we do not have to do it at each frame
|
||||
area._value->_name = centerAndPadString(area._value->_name, 14);
|
||||
}
|
||||
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_0_Amiga", false));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_1_Amiga", false));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_2_Amiga", false));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_3_Amiga", false));
|
||||
_indicators.push_back(loadBundledImage("driller_ship_indicator_Amiga", false));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void DrillerEngine::loadAssetsAtariDemo() {
|
||||
Common::File file;
|
||||
file.open("lift.neo");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'lift.neo' file");
|
||||
|
||||
_title = loadAndConvertNeoImage(&file, 0);
|
||||
|
||||
file.close();
|
||||
file.open("console.neo");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'console.neo' file");
|
||||
|
||||
_border = loadAndConvertNeoImage(&file, 0);
|
||||
|
||||
file.close();
|
||||
file.open("demo.cmd");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'demo.cmd' file");
|
||||
|
||||
loadDemoData(&file, 0, 0x1000);
|
||||
|
||||
file.close();
|
||||
if (_variant & GF_ATARI_MAGAZINE_DEMO) {
|
||||
file.open("auto_x.prg");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'auto_x.prg' file");
|
||||
_demoMode = false;
|
||||
} else {
|
||||
file.open("x.prg");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'x.prg' file");
|
||||
}
|
||||
|
||||
if (_variant & GF_ATARI_MAGAZINE_DEMO) {
|
||||
loadMessagesFixedSize(&file, 0x40d2, 14, 20);
|
||||
loadGlobalObjects(&file, 0x3e88, 8);
|
||||
|
||||
loadFonts(&file, 0x7ee);
|
||||
Common::Array<Graphics::ManagedSurface *> chars;
|
||||
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, &file, 0x7ee + 112 * 33 + 1, 100);
|
||||
_fontSmall = Font(chars);
|
||||
_fontSmall.setCharWidth(5);
|
||||
} else {
|
||||
loadFonts(&file, 0x7bc);
|
||||
loadMessagesFixedSize(&file, 0x3b90, 14, 20);
|
||||
loadGlobalObjects(&file, 0x3946, 8);
|
||||
}
|
||||
|
||||
file.close();
|
||||
file.open("data");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'data' file");
|
||||
|
||||
load8bitBinary(&file, 0x442, 16);
|
||||
loadPalettes(&file, 0x0);
|
||||
|
||||
file.close();
|
||||
file.open("soundfx");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'soundfx' executable for AtariST demo");
|
||||
|
||||
loadSoundsFx(&file, 0, 25);
|
||||
|
||||
for (auto &area : _areaMap) {
|
||||
// Center and pad each area name so we do not have to do it at each frame
|
||||
area._value->_name = centerAndPadString(area._value->_name, 14);
|
||||
}
|
||||
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_0_Amiga", false));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_1_Amiga", false));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_2_Amiga", false));
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator_3_Amiga", false));
|
||||
_indicators.push_back(loadBundledImage("driller_ship_indicator_Amiga", false));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
249
engines/freescape/games/driller/c64.cpp
Normal file
249
engines/freescape/games/driller/c64.cpp
Normal file
@@ -0,0 +1,249 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/driller/driller.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
extern byte kC64Palette[16][3];
|
||||
|
||||
void DrillerEngine::initC64() {
|
||||
_viewArea = Common::Rect(32, 16, 288, 120);
|
||||
}
|
||||
|
||||
void DrillerEngine::loadAssetsC64FullGame() {
|
||||
Common::File file;
|
||||
if (_targetName.hasPrefix("spacestationoblivion")) {
|
||||
file.open("spacestationoblivion.c64.data");
|
||||
loadMessagesFixedSize(&file, 0x167a, 14, 20);
|
||||
//loadFonts(&file, 0xae54);
|
||||
load8bitBinary(&file, 0x8e02, 4);
|
||||
loadGlobalObjects(&file, 0x1855, 8);
|
||||
} else if (_targetName.hasPrefix("driller")) {
|
||||
file.open("driller.c64.data");
|
||||
|
||||
if (_variant) {
|
||||
loadMessagesFixedSize(&file, 0x167a, 14, 20);
|
||||
loadGlobalObjects(&file, 0x1855, 8);
|
||||
loadFonts(&file, 0x402);
|
||||
load8bitBinary(&file, 0x8b04, 16);
|
||||
/*} else if (_variant & GF_C64_BUDGET) {
|
||||
//loadFonts(&file, 0x402);
|
||||
load8bitBinary(&file, 0x7df7, 16);
|
||||
loadMessagesFixedSize(&file, 0x1399, 14, 20);
|
||||
loadGlobalObjects(&file, 0x150a, 8);*/
|
||||
} else
|
||||
error("Unknown C64 variant %x", _variant);
|
||||
|
||||
// The color map from the data is not correct,
|
||||
// so we'll just hardcode the one that we found in the executable
|
||||
|
||||
for (int i = 0; i < 15; i++) {
|
||||
_colorMap[i][0] = 0;
|
||||
_colorMap[i][1] = 0;
|
||||
_colorMap[i][2] = 0;
|
||||
_colorMap[i][3] = 0;
|
||||
}
|
||||
|
||||
_colorMap[1][0] = 0x55;
|
||||
_colorMap[1][1] = 0x55;
|
||||
_colorMap[1][2] = 0x55;
|
||||
_colorMap[1][3] = 0x55;
|
||||
|
||||
_colorMap[2][0] = 0xaa;
|
||||
_colorMap[2][1] = 0xaa;
|
||||
_colorMap[2][2] = 0xaa;
|
||||
_colorMap[2][3] = 0xaa;
|
||||
|
||||
_colorMap[3][0] = 0xff;
|
||||
_colorMap[3][1] = 0xff;
|
||||
_colorMap[3][2] = 0xff;
|
||||
_colorMap[3][3] = 0xff;
|
||||
|
||||
_colorMap[4][0] = 0x44;
|
||||
_colorMap[4][1] = 0x11;
|
||||
_colorMap[4][2] = 0x44;
|
||||
_colorMap[4][3] = 0x11;
|
||||
|
||||
_colorMap[5][0] = 0x88;
|
||||
_colorMap[5][1] = 0x22;
|
||||
_colorMap[5][2] = 0x88;
|
||||
_colorMap[5][3] = 0x22;
|
||||
|
||||
_colorMap[6][0] = 0xcc;
|
||||
_colorMap[6][1] = 0x33;
|
||||
_colorMap[6][2] = 0xcc;
|
||||
_colorMap[6][3] = 0x33;
|
||||
|
||||
_colorMap[7][0] = 0x66;
|
||||
_colorMap[7][1] = 0x99;
|
||||
_colorMap[7][2] = 0x66;
|
||||
_colorMap[7][3] = 0x99;
|
||||
|
||||
_colorMap[8][0] = 0x77;
|
||||
_colorMap[8][1] = 0xdd;
|
||||
_colorMap[8][2] = 0x77;
|
||||
_colorMap[8][3] = 0xdd;
|
||||
|
||||
_colorMap[9][0] = 0xbb;
|
||||
_colorMap[9][1] = 0xee;
|
||||
_colorMap[9][2] = 0xbb;
|
||||
_colorMap[9][3] = 0xee;
|
||||
|
||||
_colorMap[10][0] = 0x5a;
|
||||
_colorMap[10][1] = 0xa5;
|
||||
_colorMap[10][2] = 0x5a;
|
||||
_colorMap[10][3] = 0xa5;
|
||||
|
||||
_colorMap[11][0] = 0xaf;
|
||||
_colorMap[11][1] = 0xfa;
|
||||
_colorMap[11][2] = 0xaf;
|
||||
_colorMap[11][3] = 0xfa;
|
||||
|
||||
|
||||
_colorMap[12][0] = 0x77;
|
||||
_colorMap[12][1] = 0xdd;
|
||||
_colorMap[12][2] = 0x77;
|
||||
_colorMap[12][3] = 0xdd;
|
||||
|
||||
_colorMap[13][0] = 0xcc;
|
||||
_colorMap[13][1] = 0xcc;
|
||||
_colorMap[13][2] = 0xcc;
|
||||
_colorMap[13][3] = 0xcc;
|
||||
|
||||
// TODO
|
||||
_colorMap[14][0] = 0x77;
|
||||
_colorMap[14][1] = 0xdd;
|
||||
_colorMap[14][2] = 0x77;
|
||||
_colorMap[14][3] = 0xdd;
|
||||
|
||||
Graphics::Surface *surf = loadBundledImage("driller_border");
|
||||
surf->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
_border = new Graphics::ManagedSurface();
|
||||
_border->copyFrom(*surf);
|
||||
surf->free();
|
||||
delete surf;
|
||||
|
||||
file.close();
|
||||
file.open("driller.c64.title.bitmap");
|
||||
|
||||
Common::File colorFile1;
|
||||
colorFile1.open("driller.c64.title.colors1");
|
||||
Common::File colorFile2;
|
||||
colorFile2.open("driller.c64.title.colors2");
|
||||
|
||||
_title = loadAndConvertDoodleImage(&file, &colorFile1, &colorFile2, (byte *)&kC64Palette);
|
||||
} else
|
||||
error("Unknown C64 release");
|
||||
|
||||
_playerSid = new DrillerSIDPlayer();
|
||||
}
|
||||
|
||||
|
||||
void DrillerEngine::drawC64UI(Graphics::Surface *surface) {
|
||||
|
||||
uint8 r, g, b;
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xAA, 0xAA, 0xAA);
|
||||
|
||||
Common::Rect cover;
|
||||
|
||||
uint32 color = 0;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
drawStringInSurface(_currentArea->_name, 200, 184, front, back, surface);
|
||||
cover = Common::Rect(150, 143, 183, 167);
|
||||
|
||||
surface->fillRect(cover, back);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 150, 148 - 4, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 150, 156 - 4, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 150, 164 - 4, front, back, surface);
|
||||
if (_playerHeightNumber >= 0)
|
||||
drawStringInSurface(Common::String::format("%d", _playerHeightNumber), 54 + 6, 164 - 3, front, back, surface);
|
||||
else
|
||||
drawStringInSurface(Common::String::format("%s", "J"), 54 + 6, 164 - 3, front, back, surface);
|
||||
|
||||
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 46, 148 - 3, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 46, 156 - 3, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%07d", score), 239, 128, front, back, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
drawStringInSurface(Common::String::format("%02d", hours), 207, 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%02d", minutes), 230, 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%02d", seconds), 254, 8, front, back, surface);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 191, 176, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else {
|
||||
if (_currentArea->_gasPocketRadius == 0)
|
||||
message = _messagesList[2];
|
||||
else if (_drillStatusByArea[_currentArea->getAreaID()])
|
||||
message = _messagesList[0];
|
||||
else
|
||||
message = _messagesList[1];
|
||||
|
||||
drawStringInSurface(message, 191, 176, front, back, surface);
|
||||
}
|
||||
|
||||
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x68, 0xa9, 0x41);
|
||||
int energy = _gameStateVars[k8bitVariableEnergy];
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
if (energy >= 0) {
|
||||
Common::Rect backBar(21, 183, 85 - energy, 190);
|
||||
surface->fillRect(backBar, back);
|
||||
Common::Rect energyBar(84 - energy, 184, 84, 190);
|
||||
surface->fillRect(energyBar, green);
|
||||
}
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect backBar(25 - 4, 180 - 4, 89 - shield - 4, 186 - 4);
|
||||
surface->fillRect(backBar, back);
|
||||
|
||||
Common::Rect shieldBar(88 - 4 - shield, 180 - 4, 88 - 4, 186 - 4);
|
||||
surface->fillRect(shieldBar, green);
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(7, r, g, b);
|
||||
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
surface->fillRect(Common::Rect(87, 156, 104, 166), back);
|
||||
drawCompass(surface, 94, 156, _yaw - 30, 11, 75, yellow);
|
||||
surface->fillRect(Common::Rect(224, 151, 235, 160), back);
|
||||
drawCompass(surface, 223, 156, _pitch - 30, 12, 60, yellow);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
1072
engines/freescape/games/driller/c64.music.cpp
Normal file
1072
engines/freescape/games/driller/c64.music.cpp
Normal file
File diff suppressed because it is too large
Load Diff
239
engines/freescape/games/driller/c64.music.h
Normal file
239
engines/freescape/games/driller/c64.music.h
Normal file
@@ -0,0 +1,239 @@
|
||||
/* 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 "audio/sid.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class DrillerSIDPlayer {
|
||||
|
||||
// --- Voice State Structure ---
|
||||
struct VoiceState {
|
||||
// Pointers & Indices
|
||||
const uint8_t *trackDataPtr; // Pointer to current track data array
|
||||
uint8_t trackIndex; // Index within trackDataPtr
|
||||
const uint8_t *patternDataPtr; // Pointer to current pattern data array
|
||||
uint8_t patternIndex; // Index within patternDataPtr
|
||||
uint8_t instrumentIndex; // Current instrument (0-21, scaled by 8 for lookup)
|
||||
|
||||
// Playback Control & Tempo
|
||||
int8_t delayCounter; // Counts down frames for note duration (maps to voiceX_ctrl2)
|
||||
uint8_t noteDuration; // Duration set by FD xx (maps to voiceX_something+2)
|
||||
uint8_t gateMask; // Control gating/retriggering (maps to control3 behavior)
|
||||
|
||||
// Note & Frequency
|
||||
uint8_t currentNote; // Current raw note value (0-95)
|
||||
uint8_t portaTargetNote; // Target note for portamento
|
||||
uint16_t currentFreq; // Current frequency being sent to SID
|
||||
uint16_t baseFreq; // Note frequency without effects
|
||||
uint16_t targetFreq; // Used for portamento target
|
||||
|
||||
// Pulse Width
|
||||
uint16_t pulseWidth; // Current pulse width
|
||||
// Placeholder for PWM effects if needed later
|
||||
|
||||
// ADSR
|
||||
uint8_t attackDecay; // SID Attack / Decay register value
|
||||
uint8_t sustainRelease; // SID Sustain / Release register value
|
||||
|
||||
// Effects State
|
||||
uint8_t effect; // Current active effect (0:None, 1:Arpeggio, 2:Vibrato, 3:Portamento Up, 4:Portamento Down, 5: PWM LFO?)
|
||||
uint8_t arpeggioIndex; // Index in arpeggio table
|
||||
uint8_t arpeggioSpeed; // Counter divisor for arpeggio step
|
||||
uint8_t arpeggioCounter; // Counter for arpeggio step
|
||||
uint8_t arpeggioNoteOffsetIndex; // 0, 1, 2 for arpeggio notes
|
||||
|
||||
int16_t vibratoDepth; // Depth for vibrato effect
|
||||
uint8_t vibratoSpeed; // Speed/delay for vibrato effect
|
||||
uint8_t vibratoDelay; // Counter for vibrato step
|
||||
uint8_t vibratoDirection; // 0: up, 1: down
|
||||
int16_t vibratoCurrentOffset; // Current frequency offset for vibrato
|
||||
|
||||
int16_t portaSpeed; // Speed for portamento effect (positive for up, negative for down)
|
||||
|
||||
// Hard Restart / Buzz Effect (from L1005, possibly instrument related)
|
||||
uint8_t hardRestartValue; // Value from instrument table (a1+5)
|
||||
uint8_t hardRestartDelay; // Counter for delay phase (voiceX_whatever+3)
|
||||
uint8_t hardRestartCounter; // Counter for frequency change phase (voiceX_whatever+4)
|
||||
bool hardRestartActive; // Is the effect currently running?
|
||||
|
||||
// From disassembly variables (mapping might need refinement)
|
||||
// voice1_whatever: 0CCE[5] - effect state? (arp, vib, porta)
|
||||
uint8_t whatever0; // 0CCE - Vibrato state? (0=off, 1=active, 3-4=sweep?)
|
||||
uint8_t whatever1; // 0CCF - Arpeggio state? (0=off, 1=active)
|
||||
uint8_t whatever2; // 0CD0 - Portamento type (0=off, 1=down(FB), 2=up(FC), 3=down H(FB), 4=up H(FC))?
|
||||
uint8_t whatever3; // 0CD1 - Hard restart delay counter
|
||||
uint8_t whatever4; // 0CD2 - Hard restart step counter
|
||||
|
||||
// voice1_whatever2: 0CD4 - Vibrato direction toggle?
|
||||
uint8_t whatever2_vibDirToggle;
|
||||
|
||||
// voice1_something: 0CE3[3] - Porta speed?, Note duration
|
||||
uint16_t portaStepRaw; // 0CE3/4 - Raw value from FB/FC command
|
||||
// uint8_t noteDuration // 0CE5 - Covered above
|
||||
|
||||
// voice1_something_else: 0CE7[3] - PW Low, PW High? (ADSR in disassembly?) - Needs clarification
|
||||
uint8_t something_else[3]; // Re-add this array as it's used in the code logic
|
||||
|
||||
// voice1_ctrl0: 0CF8 - ADSR lower nibble (Sustain/Release)
|
||||
uint8_t ctrl0; // Re-add this as it's used in the code logic
|
||||
|
||||
// voice1_ctrl1: 0CF9 - Arpeggio table index / Arp speed upper nibble
|
||||
uint8_t arpTableIndex;
|
||||
uint8_t arpSpeedHiNibble;
|
||||
|
||||
// voice1_ctrl2: 0CFE - Note delay counter (covered by delayCounter)
|
||||
|
||||
// voice1_stuff: 0D14[7] - Current freq, base freq, hard restart freq store? Arp counter?
|
||||
uint16_t stuff_freq_porta_vib; // 0D14/15 - Current frequency including porta/vib
|
||||
uint16_t stuff_freq_base; // 0D16/17 - Base frequency of the note
|
||||
uint16_t stuff_freq_hard_restart; // 0D18/19 - Frequency stored during hard restart buzz
|
||||
uint8_t stuff_arp_counter; // 0D1A - Arpeggio counter (0..speed-1)
|
||||
uint8_t stuff_arp_note_index; // 0D1B - Index into arp notes (0, 1, 2)
|
||||
|
||||
// voice1_things: 0D29[7] - Vibrato state/params
|
||||
uint8_t things_vib_state; // 0D29 - Vibrato state (0=down1, 1=up, 2=down2, 3=sweepdown1, 4=sweepup)
|
||||
uint16_t things_vib_depth; // 0D2A/2B - Vibrato depth
|
||||
uint8_t things_vib_delay_reload; // 0D2C - Vibrato delay reload value
|
||||
uint8_t things_vib_delay_ctr; // 0D2D - Vibrato delay counter
|
||||
// 0D2E/F unused?
|
||||
uint8_t currentNoteSlideTarget; // 0D30 - Last played note (used for slide target?)
|
||||
|
||||
// voice1_two_ctr: 0D3E - Glide down timer? (Instrument related)
|
||||
uint8_t glideDownTimer;
|
||||
|
||||
// Temp values during processing
|
||||
uint8_t waveform; // Current waveform for SID
|
||||
bool keyOn; // Current key state (attack vs release)
|
||||
bool sync; // Sync bit state
|
||||
bool ringMod; // Ring mod bit state
|
||||
|
||||
// Pulse width parts matching something_else (if it maps to PW)
|
||||
uint8_t pwLo() const { return something_else[0]; } // Example mapping
|
||||
uint8_t pwHi() const { return something_else[2]; } // Example mapping
|
||||
void setPwLo(uint8_t val) { something_else[0] = val; }
|
||||
void setPwHi(uint8_t val) { something_else[2] = val; }
|
||||
|
||||
void reset() {
|
||||
trackDataPtr = nullptr;
|
||||
trackIndex = 0;
|
||||
patternDataPtr = nullptr;
|
||||
patternIndex = 0;
|
||||
instrumentIndex = 0;
|
||||
delayCounter = 0;
|
||||
noteDuration = 0;
|
||||
gateMask = 0xFF;
|
||||
currentNote = 0;
|
||||
portaTargetNote = 0;
|
||||
currentFreq = 0;
|
||||
baseFreq = 0;
|
||||
targetFreq = 0;
|
||||
pulseWidth = 0;
|
||||
attackDecay = 0;
|
||||
sustainRelease = 0;
|
||||
effect = 0;
|
||||
arpeggioIndex = 0;
|
||||
arpeggioSpeed = 0;
|
||||
arpeggioCounter = 0;
|
||||
arpeggioNoteOffsetIndex = 0;
|
||||
vibratoDepth = 0;
|
||||
vibratoSpeed = 0;
|
||||
vibratoDelay = 0;
|
||||
vibratoDirection = 0;
|
||||
vibratoCurrentOffset = 0;
|
||||
portaSpeed = 0;
|
||||
hardRestartValue = 0;
|
||||
hardRestartDelay = 0;
|
||||
hardRestartCounter = 0;
|
||||
hardRestartActive = false;
|
||||
waveform = 0x10; // Default to triangle?
|
||||
keyOn = false;
|
||||
sync = false;
|
||||
ringMod = false;
|
||||
|
||||
// Reset mapped vars
|
||||
whatever0 = 0;
|
||||
whatever1 = 0;
|
||||
whatever2 = 0;
|
||||
whatever3 = 0;
|
||||
whatever4 = 0;
|
||||
whatever2_vibDirToggle = 0;
|
||||
portaStepRaw = 0;
|
||||
memset(something_else, 0, sizeof(something_else)); // Reset the array
|
||||
ctrl0 = 0; // Reset the added member
|
||||
arpTableIndex = 0;
|
||||
arpSpeedHiNibble = 0;
|
||||
stuff_freq_porta_vib = 0;
|
||||
stuff_freq_base = 0;
|
||||
stuff_freq_hard_restart = 0;
|
||||
stuff_arp_counter = 0;
|
||||
stuff_arp_note_index = 0;
|
||||
things_vib_state = 0;
|
||||
things_vib_depth = 0;
|
||||
things_vib_delay_reload = 0;
|
||||
things_vib_delay_ctr = 0;
|
||||
currentNoteSlideTarget = 0;
|
||||
glideDownTimer = 0;
|
||||
}
|
||||
};
|
||||
|
||||
// --- Member Variables ---
|
||||
SID::SID *_sid;
|
||||
|
||||
// Player State
|
||||
enum PlayState { STOPPED,
|
||||
PLAYING,
|
||||
CHANGING_TUNE };
|
||||
PlayState _playState;
|
||||
uint8_t _targetTuneIndex; // Tune index requested via startMusic
|
||||
|
||||
// Global Timing
|
||||
uint8_t _globalTempo; // Tempo value for current tune (0xD10)
|
||||
int8_t _globalTempoCounter; // Frame counter for tempo (0xD12), signed to handle < 0 check
|
||||
uint8_t _framePhase; // Tracks which voice is being processed (0, 7, 14)
|
||||
|
||||
// Voice States
|
||||
VoiceState _voiceState[3];
|
||||
|
||||
// Internal helpers
|
||||
uint8_t _tempControl3; // Temporary storage for gate mask (0xD13)
|
||||
// uint8_t _tempControl1; // Temp storage from instrument data (0xD11)
|
||||
|
||||
public:
|
||||
DrillerSIDPlayer();
|
||||
~DrillerSIDPlayer();
|
||||
void startMusic(int tuneIndex = 1);
|
||||
void stopMusic();
|
||||
|
||||
private:
|
||||
void SID_Write(int reg, uint8_t data);
|
||||
void initSID();
|
||||
void onTimer();
|
||||
void handleChangeTune(int tuneIndex);
|
||||
void handleResetVoices();
|
||||
void playVoice(int voiceIndex);
|
||||
void applyNote(VoiceState &v, int sidOffset, const uint8_t *instA0, const uint8_t *instA1, int voiceIndex);
|
||||
void applyContinuousEffects(VoiceState &v, int sidOffset, const uint8_t *instA0, const uint8_t *instA1);
|
||||
void applyHardRestart(VoiceState &v, int sidOffset, const uint8_t *instA0, const uint8_t *instA1);
|
||||
};
|
||||
|
||||
} // namespace Freescape
|
||||
243
engines/freescape/games/driller/cpc.cpp
Normal file
243
engines/freescape/games/driller/cpc.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/driller/driller.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void DrillerEngine::initCPC() {
|
||||
_viewArea = Common::Rect(36, 16, 284, 117);
|
||||
}
|
||||
|
||||
byte kCPCPaletteTitleData[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0x80, 0xff},
|
||||
{0xff, 0x00, 0x00},
|
||||
{0xff, 0xff, 0x00},
|
||||
};
|
||||
|
||||
byte kCPCPaletteBorderData[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0xff, 0x80, 0x00},
|
||||
{0x80, 0xff, 0xff},
|
||||
{0x00, 0x80, 0x00},
|
||||
};
|
||||
|
||||
byte getCPCPixelMode1(byte cpc_byte, int index) {
|
||||
if (index == 0)
|
||||
return ((cpc_byte & 0x08) >> 2) | ((cpc_byte & 0x80) >> 7);
|
||||
else if (index == 1)
|
||||
return ((cpc_byte & 0x04) >> 1) | ((cpc_byte & 0x40) >> 6);
|
||||
else if (index == 2)
|
||||
return (cpc_byte & 0x02) | ((cpc_byte & 0x20) >> 5);
|
||||
else if (index == 3)
|
||||
return ((cpc_byte & 0x01) << 1) | ((cpc_byte & 0x10) >> 4);
|
||||
else
|
||||
error("Invalid index %d requested", index);
|
||||
}
|
||||
|
||||
byte getCPCPixelMode0(byte cpc_byte, int index) {
|
||||
if (index == 0) {
|
||||
// Extract Pixel 0 from the byte
|
||||
return ((cpc_byte & 0x02) >> 1) | // Bit 1 -> Bit 3 (MSB)
|
||||
((cpc_byte & 0x20) >> 4) | // Bit 5 -> Bit 2
|
||||
((cpc_byte & 0x08) >> 1) | // Bit 3 -> Bit 1
|
||||
((cpc_byte & 0x80) >> 7); // Bit 7 -> Bit 0 (LSB)
|
||||
}
|
||||
else if (index == 2) {
|
||||
// Extract Pixel 1 from the byte
|
||||
return ((cpc_byte & 0x01) << 3) | // Bit 0 -> Bit 3 (MSB)
|
||||
((cpc_byte & 0x10) >> 2) | // Bit 4 -> Bit 2
|
||||
((cpc_byte & 0x04) >> 1) | // Bit 2 -> Bit 1
|
||||
((cpc_byte & 0x40) >> 6); // Bit 6 -> Bit 0 (LSB)
|
||||
}
|
||||
else {
|
||||
error("Invalid index %d requested", index);
|
||||
}
|
||||
}
|
||||
|
||||
byte getCPCPixel(byte cpc_byte, int index, bool mode1) {
|
||||
if (mode1)
|
||||
return getCPCPixelMode1(cpc_byte, index);
|
||||
else
|
||||
return getCPCPixelMode0(cpc_byte, index);
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode1) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
|
||||
surface->fillRect(Common::Rect(0, 0, 320, 200), 0);
|
||||
|
||||
int x, y;
|
||||
file->seek(0x80);
|
||||
for (int block = 0; block < 8; block++) {
|
||||
for (int line = 0; line < 25; line++) {
|
||||
for (int offset = 0; offset < 320 / 4; offset++) {
|
||||
byte cpc_byte = file->readByte(); // Get CPC byte
|
||||
|
||||
// Process first pixel
|
||||
int pixel_0 = getCPCPixel(cpc_byte, 0, mode1); // %Aa
|
||||
y = line * 8 + block ; // Coord Y for the pixel
|
||||
x = 4 * offset + 0; // Coord X for the pixel
|
||||
surface->setPixel(x, y, pixel_0);
|
||||
|
||||
// Process second pixel
|
||||
y = line * 8 + block ; // Coord Y for the pixel
|
||||
x = 4 * offset + 1; // Coord X for the pixel
|
||||
if (mode1) {
|
||||
int pixel_1 = getCPCPixel(cpc_byte, 1, mode1); // %Bb
|
||||
surface->setPixel(x, y, pixel_1);
|
||||
} else
|
||||
surface->setPixel(x, y, pixel_0);
|
||||
|
||||
// Process third pixel
|
||||
int pixel_2 = getCPCPixel(cpc_byte, 2, mode1); // %Cc
|
||||
y = line * 8 + block ; // Coord Y for the pixel
|
||||
x = 4 * offset + 2; // Coord X for the pixel
|
||||
surface->setPixel(x, y, pixel_2);
|
||||
|
||||
// Process fourth pixel
|
||||
y = line * 8 + block ; // Coord Y for the pixel
|
||||
x = 4 * offset + 3; // Coord X for the pixel
|
||||
if (mode1) {
|
||||
int pixel_3 = getCPCPixel(cpc_byte, 3, mode1); // %Dd
|
||||
surface->setPixel(x, y, pixel_3);
|
||||
} else
|
||||
surface->setPixel(x, y, pixel_2);
|
||||
}
|
||||
}
|
||||
// We should skip the next 48 bytes, because they are padding the block to be 2048 bytes
|
||||
file->seek(48, SEEK_CUR);
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
void DrillerEngine::loadAssetsCPCFullGame() {
|
||||
Common::File file;
|
||||
|
||||
file.open("DSCN1.BIN");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DSCN1.BIN");
|
||||
|
||||
_title = readCPCImage(&file, true);
|
||||
_title->setPalette((byte*)&kCPCPaletteTitleData, 0, 4);
|
||||
|
||||
file.close();
|
||||
file.open("DSCN2.BIN");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DSCN2.BIN");
|
||||
|
||||
_border = readCPCImage(&file, true);
|
||||
_border->setPalette((byte*)&kCPCPaletteBorderData, 0, 4);
|
||||
|
||||
file.close();
|
||||
file.open("DRILL.BIN");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DRILL.BIN");
|
||||
|
||||
loadMessagesFixedSize(&file, 0x214c, 14, 20);
|
||||
loadFonts(&file, 0x5b69);
|
||||
loadGlobalObjects(&file, 0x1d07, 8);
|
||||
load8bitBinary(&file, 0x5ccb, 16);
|
||||
}
|
||||
|
||||
void DrillerEngine::drawCPCUI(Graphics::Surface *surface) {
|
||||
uint32 color = _currentArea->_underFireBackgroundColor;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
drawStringInSurface(_currentArea->_name, 200, 185, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 151, 145, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 151, 153, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 151, 161, front, back, surface);
|
||||
if (_playerHeightNumber >= 0)
|
||||
drawStringInSurface(Common::String::format("%d", _playerHeightNumber), 54, 161, front, back, surface);
|
||||
else
|
||||
drawStringInSurface(Common::String::format("%s", "J"), 54, 161, front, back, surface);
|
||||
|
||||
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 47, 145, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 44, 153, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%07d", score), 239, 129, front, back, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
drawStringInSurface(Common::String::format("%02d", hours), 209, 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%02d", minutes), 232, 8, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%02d", seconds), 255, 8, front, back, surface);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 191, 177, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else if (_messagesList.size() > 0) {
|
||||
if (_currentArea->_gasPocketRadius == 0)
|
||||
message = _messagesList[2];
|
||||
else if (_drillStatusByArea[_currentArea->getAreaID()])
|
||||
message = _messagesList[0];
|
||||
else
|
||||
message = _messagesList[1];
|
||||
|
||||
drawStringInSurface(message, 191, 177, front, back, surface);
|
||||
}
|
||||
|
||||
int energy = _gameStateVars[k8bitVariableEnergy];
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
if (energy >= 0) {
|
||||
Common::Rect backBar(25, 184, 89 - energy, 191);
|
||||
surface->fillRect(backBar, back);
|
||||
Common::Rect energyBar(88 - energy, 184, 88, 191);
|
||||
surface->fillRect(energyBar, front);
|
||||
}
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect backBar(25, 177, 89 - shield, 183);
|
||||
surface->fillRect(backBar, back);
|
||||
|
||||
Common::Rect shieldBar(88 - shield, 177, 88, 183);
|
||||
surface->fillRect(shieldBar, front);
|
||||
}
|
||||
|
||||
drawCompass(surface, 87, 156, _yaw - 30, 10, 75, front);
|
||||
drawCompass(surface, 230, 156, _pitch - 30, 10, 60, front);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
457
engines/freescape/games/driller/dos.cpp
Normal file
457
engines/freescape/games/driller/dos.cpp
Normal file
@@ -0,0 +1,457 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/driller/driller.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
extern byte kEGADefaultPalette[16][3];
|
||||
extern byte kCGAPaletteRedGreen[4][3];
|
||||
extern byte kCGAPalettePinkBlue[4][3];
|
||||
extern byte kHerculesPaletteGreen[2][3];
|
||||
|
||||
void DrillerEngine::initDOS() {
|
||||
if (_renderMode == Common::kRenderEGA)
|
||||
_viewArea = Common::Rect(40, 16, 280, 117);
|
||||
else if (_renderMode == Common::kRenderHercG)
|
||||
_viewArea = Common::Rect(112, 64, 607, 224);
|
||||
else if (_renderMode == Common::kRenderCGA)
|
||||
_viewArea = Common::Rect(36, 16, 284, 117);
|
||||
else
|
||||
error("Invalid or unknown render mode");
|
||||
|
||||
_moveFowardArea = Common::Rect(73, 144, 101, 152);
|
||||
_moveLeftArea = Common::Rect(73, 150, 86, 159);
|
||||
_moveRightArea = Common::Rect(88, 152, 104, 160);
|
||||
_moveBackArea = Common::Rect(73, 160, 101, 168);
|
||||
_moveUpArea = Common::Rect(219, 144, 243, 155);
|
||||
_moveDownArea = Common::Rect(219, 157, 243, 167);
|
||||
_deployDrillArea = Common::Rect(140, 175, 179, 191);
|
||||
_infoScreenArea = Common::Rect(130, 125, 188, 144);
|
||||
|
||||
_soundIndexShoot = 1;
|
||||
_soundIndexCollide = 2;
|
||||
_soundIndexStepDown = 3;
|
||||
_soundIndexStepUp = 4;
|
||||
_soundIndexMenu = 2;
|
||||
_soundIndexStart = 9;
|
||||
_soundIndexAreaChange = 5;
|
||||
_soundIndexHit = 2;
|
||||
|
||||
_soundIndexFall = 14;
|
||||
_soundIndexNoShield = 20;
|
||||
_soundIndexNoEnergy = 20;
|
||||
_soundIndexFallen = 20;
|
||||
_soundIndexTimeout = 20;
|
||||
_soundIndexForceEndGame = 20;
|
||||
_soundIndexCrushed = 20;
|
||||
}
|
||||
|
||||
/*
|
||||
The following functions are only used for decoding title images for
|
||||
the US release of Driller ("Space Station Oblivion")
|
||||
*/
|
||||
|
||||
uint32 DrillerEngine::getPixel8bitTitleImage(int index) {
|
||||
if (index < 4 || _renderMode == Common::kRenderEGA) {
|
||||
return index;
|
||||
}
|
||||
return index / 4;
|
||||
}
|
||||
|
||||
void DrillerEngine::renderPixels8bitTitleImage(Graphics::ManagedSurface *surface, int &x, int &y, int pixels) {
|
||||
int c1 = pixels >> 4;
|
||||
int c2 = pixels & 0xf;
|
||||
|
||||
if (x == 320) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_renderMode == Common::kRenderCGA) {
|
||||
surface->setPixel(x, y, getPixel8bitTitleImage(c1 / 4));
|
||||
x++;
|
||||
if (x == 320) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
surface->setPixel(x, y, getPixel8bitTitleImage(c1));
|
||||
x++;
|
||||
|
||||
if (x == 320) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_renderMode == Common::kRenderCGA) {
|
||||
surface->setPixel(x, y, getPixel8bitTitleImage(c2 / 4));
|
||||
x++;
|
||||
|
||||
if (x == 320) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
surface->setPixel(x, y, getPixel8bitTitleImage(c2));
|
||||
x++;
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *DrillerEngine::load8bitTitleImage(Common::SeekableReadStream *file, int offset) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(_screenW, _screenH, Graphics::PixelFormat::createFormatCLUT8());
|
||||
surface->fillRect(Common::Rect(0, 0, 320, 200), 0);
|
||||
|
||||
file->seek(offset);
|
||||
for (int y = 0; y < 200; ++y) {
|
||||
if (file->eos ()) break;
|
||||
|
||||
// Start of line data (0x02) or [premature] end of data (0x00)
|
||||
int sol = file->readByte();
|
||||
if (sol == 0) break;
|
||||
assert(sol == 2);
|
||||
|
||||
int x = 0;
|
||||
while (x < 320) {
|
||||
int command = file->readByte();
|
||||
if (command & 0x80) {
|
||||
// Copy 2*N bytes verbatim
|
||||
int repeat = (257 - command) * 2;
|
||||
for (int i = 0; i < repeat; ++i) {
|
||||
int pixels = file->readByte();
|
||||
renderPixels8bitTitleImage(surface, x, y, pixels);
|
||||
}
|
||||
} else {
|
||||
// Repeat 2 bytes of the input N times
|
||||
int repeat = command + 1;
|
||||
int pixels1 = file->readByte();
|
||||
int pixels2 = file->readByte();
|
||||
for (int i = 0; i < repeat; ++i) {
|
||||
renderPixels8bitTitleImage(surface, x, y, pixels1);
|
||||
renderPixels8bitTitleImage(surface, x, y, pixels2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
byte kCGAPalettePinkBlueWhiteData[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x55, 0xff, 0xff},
|
||||
{0xff, 0x55, 0xff},
|
||||
{0xff, 0xff, 0xff},
|
||||
};
|
||||
|
||||
/*
|
||||
The following function is only used for decoding images for
|
||||
the Driller DOS demo
|
||||
*/
|
||||
|
||||
Graphics::ManagedSurface *DrillerEngine::load8bitDemoImage(Common::SeekableReadStream *file, int offset) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
|
||||
surface->fillRect(Common::Rect(0, 0, 320, 200), 0);
|
||||
file->seek(offset);
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (true) {
|
||||
byte pixels = file->readByte();
|
||||
for (int b = 0; b < 4; b++) {
|
||||
int color = pixels & 3;
|
||||
pixels = pixels >> 2;
|
||||
surface->setPixel(i + (3 - b), 2 * j, color);
|
||||
}
|
||||
i = i + 4;
|
||||
if (i == 320) {
|
||||
i = 0;
|
||||
j++;
|
||||
}
|
||||
if (j == 100)
|
||||
break;
|
||||
}
|
||||
file->seek(0xc0, SEEK_CUR);
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (true) {
|
||||
byte pixels = file->readByte();
|
||||
for (int b = 0; b < 4; b++) {
|
||||
int color = pixels & 3;
|
||||
pixels = pixels >> 2;
|
||||
surface->setPixel(i + (3 - b), 2 * j + 1, color);
|
||||
}
|
||||
i = i + 4;
|
||||
if (i == 320) {
|
||||
i = 0;
|
||||
j++;
|
||||
}
|
||||
if (j == 100)
|
||||
break;
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
void DrillerEngine::loadAssetsDOSFullGame() {
|
||||
Common::File file;
|
||||
if (_renderMode == Common::kRenderEGA) {
|
||||
file.open("SCN1E.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte*)&kEGADefaultPalette, 0, 16);
|
||||
}
|
||||
file.close();
|
||||
file.open("EGATITLE.RL");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitTitleImage(&file, 0x1b2);
|
||||
_title->setPalette((byte*)&kEGADefaultPalette, 0, 16);
|
||||
}
|
||||
file.close();
|
||||
|
||||
file.open("DRILLE.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DRILLE.EXE");
|
||||
|
||||
loadSpeakerFxDOS(&file, 0x4397 + 0x200, 0x4324 + 0x200, 20);
|
||||
loadMessagesFixedSize(&file, 0x4135, 14, 20);
|
||||
loadFonts(&file, 0x99dd);
|
||||
loadGlobalObjects(&file, 0x3b42, 8);
|
||||
load8bitBinary(&file, 0x9b40, 16);
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte*)&kEGADefaultPalette, 0, 16);
|
||||
} else if (_renderMode == Common::kRenderCGA) {
|
||||
file.open("SCN1C.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
|
||||
}
|
||||
file.close();
|
||||
file.open("CGATITLE.RL");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitTitleImage(&file, 0x1b2);
|
||||
_title->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
|
||||
}
|
||||
file.close();
|
||||
file.open("DRILLC.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DRILLC.EXE");
|
||||
|
||||
loadSpeakerFxDOS(&file, 0x27e7 + 0x200, 0x2774 + 0x200, 20);
|
||||
|
||||
loadFonts(&file, 0x07a4a);
|
||||
loadMessagesFixedSize(&file, 0x2585, 14, 20);
|
||||
loadGlobalObjects(&file, 0x1fa2, 8);
|
||||
load8bitBinary(&file, 0x7bb0, 4);
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
|
||||
swapPalette(1);
|
||||
} else if (_renderMode == Common::kRenderHercG) {
|
||||
file.open("SCN1H.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte*)&kHerculesPaletteGreen, 0, 2);
|
||||
}
|
||||
file.close();
|
||||
file.open("DRILLH.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open DRILLH.EXE");
|
||||
|
||||
//loadSpeakerFxDOS(&file, 0x27e7 + 0x200, 0x2774 + 0x200, 20);
|
||||
|
||||
loadFonts(&file, 0x8871);
|
||||
loadMessagesFixedSize(&file, 0x3411, 14, 20);
|
||||
load8bitBinary(&file, 0x89e0, 4);
|
||||
loadGlobalObjects(&file, 0x2d02, 8);
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte*)&kHerculesPaletteGreen, 0, 2);
|
||||
} else
|
||||
error("Unsupported video mode for DOS");
|
||||
|
||||
if (_renderMode != Common::kRenderHercG) {
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator"));
|
||||
_indicators.push_back(loadBundledImage("driller_ship_indicator"));
|
||||
|
||||
_indicators[0]->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
_indicators[1]->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
}
|
||||
|
||||
void DrillerEngine::loadAssetsDOSDemo() {
|
||||
Common::File file;
|
||||
_renderMode = Common::kRenderCGA; // DOS demos is CGA only
|
||||
_viewArea = Common::Rect(36, 16, 284, 117); // correct view area
|
||||
_gfx->_renderMode = _renderMode;
|
||||
file.open("d1");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'd1' file");
|
||||
|
||||
_title = load8bitDemoImage(&file, 0x0);
|
||||
_title->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
|
||||
|
||||
file.close();
|
||||
file.open("d2");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open 'd2' file");
|
||||
|
||||
loadFonts(&file, 0x4eb0);
|
||||
loadMessagesFixedSize(&file, 0x636, 14, 20);
|
||||
loadGlobalObjects(&file, 0x53, 8);
|
||||
load8bitBinary(&file, 0x55b0, 4);
|
||||
_border = load8bitDemoImage(&file, 0x6220);
|
||||
_border->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
|
||||
|
||||
// Fixes corrupted area names in the demo data
|
||||
_areaMap[2]->_name = "LAPIS LAZULI";
|
||||
_areaMap[3]->_name = "EMERALD";
|
||||
_areaMap[8]->_name = "TOPAZ";
|
||||
file.close();
|
||||
|
||||
_indicators.push_back(loadBundledImage("driller_tank_indicator"));
|
||||
_indicators.push_back(loadBundledImage("driller_ship_indicator"));
|
||||
|
||||
_indicators[0]->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
_indicators[1]->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void DrillerEngine::drawDOSUI(Graphics::Surface *surface) {
|
||||
uint32 color = _renderMode == Common::kRenderCGA || _renderMode == Common::kRenderHercG ? 1 : 14;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
Common::Point currentAreaPos = _renderMode == Common::kRenderHercG ? Common::Point(437, 293) : Common::Point(197, 185);
|
||||
drawStringInSurface(_currentArea->_name, currentAreaPos.x, currentAreaPos.y, front, back, surface);
|
||||
|
||||
Common::Point coordinateXPos = _renderMode == Common::kRenderHercG ? Common::Point(345, 253) : Common::Point(151, 145);
|
||||
Common::Point coordinateYPos = _renderMode == Common::kRenderHercG ? Common::Point(345, 261) : Common::Point(151, 153);
|
||||
Common::Point coordinateZPos = _renderMode == Common::kRenderHercG ? Common::Point(345, 269) : Common::Point(151, 161);
|
||||
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), coordinateXPos.x, coordinateXPos.y, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), coordinateYPos.x, coordinateYPos.y, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), coordinateZPos.x, coordinateZPos.y, front, back, surface);
|
||||
|
||||
Common::Point playerHeightPos = _renderMode == Common::kRenderHercG ? Common::Point(157, 269) : Common::Point(57, 161);
|
||||
if (_playerHeightNumber >= 0)
|
||||
drawStringInSurface(Common::String::format("%d", _playerHeightNumber), playerHeightPos.x, playerHeightPos.y, front, back, surface);
|
||||
else
|
||||
drawStringInSurface(Common::String::format("%s", "J"), playerHeightPos.x, playerHeightPos.y, front, back, surface);
|
||||
|
||||
Common::Point anglePos = _renderMode == Common::kRenderHercG ? Common::Point(141, 253) : Common::Point(47, 145);
|
||||
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), anglePos.x, anglePos.y, front, back, surface);
|
||||
|
||||
Common::Point playerStepsPos;
|
||||
|
||||
if (_renderMode == Common::kRenderHercG)
|
||||
playerStepsPos = Common::Point(130, 261);
|
||||
else if (_renderMode == Common::kRenderCGA)
|
||||
playerStepsPos = Common::Point(44, 153);
|
||||
else
|
||||
playerStepsPos = Common::Point(47, 153);
|
||||
|
||||
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), playerStepsPos.x, playerStepsPos.y, front, back, surface);
|
||||
|
||||
Common::Point scorePos = _renderMode == Common::kRenderHercG ? Common::Point(522, 237) : Common::Point(239, 129);
|
||||
drawStringInSurface(Common::String::format("%07d", score), scorePos.x, scorePos.y, front, back, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
|
||||
Common::Point hoursPos = _renderMode == Common::kRenderHercG ? Common::Point(462, 56) : Common::Point(208, 8);
|
||||
drawStringInSurface(Common::String::format("%02d", hours), hoursPos.x, hoursPos.y, front, back, surface);
|
||||
|
||||
Common::Point minutesPos = _renderMode == Common::kRenderHercG ? Common::Point(506, 56) : Common::Point(231, 8);
|
||||
drawStringInSurface(Common::String::format("%02d", minutes), minutesPos.x, minutesPos.y, front, back, surface);
|
||||
|
||||
Common::Point secondsPos = _renderMode == Common::kRenderHercG ? Common::Point(554, 56) : Common::Point(255, 8);
|
||||
drawStringInSurface(Common::String::format("%02d", seconds), secondsPos.x, secondsPos.y, front, back, surface);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
Common::Point messagePos = _renderMode == Common::kRenderHercG ? Common::Point(424, 285) : Common::Point(191, 177);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, messagePos.x, messagePos.y, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else {
|
||||
if (_currentArea->_gasPocketRadius == 0)
|
||||
message = _messagesList[2];
|
||||
else if (_drillStatusByArea[_currentArea->getAreaID()])
|
||||
message = _messagesList[0];
|
||||
else
|
||||
message = _messagesList[1];
|
||||
|
||||
drawStringInSurface(message, messagePos.x, messagePos.y, front, back, surface);
|
||||
}
|
||||
|
||||
int energy = _gameStateVars[k8bitVariableEnergy];
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
if (_renderMode != Common::kRenderHercG) {
|
||||
if (energy >= 0) {
|
||||
Common::Rect backBar(20, 185, 88 - energy, 191);
|
||||
surface->fillRect(backBar, back);
|
||||
Common::Rect energyBar(87 - energy, 185, 88, 191);
|
||||
surface->fillRect(energyBar, front);
|
||||
}
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect backBar(20, 177, 88 - shield, 183);
|
||||
surface->fillRect(backBar, back);
|
||||
|
||||
Common::Rect shieldBar(87 - shield, 177, 88, 183);
|
||||
surface->fillRect(shieldBar, front);
|
||||
}
|
||||
}
|
||||
|
||||
if (_indicators.size() >= 2) {
|
||||
if (!_flyMode)
|
||||
surface->copyRectToSurface(*_indicators[0], 132, 127, Common::Rect(_indicators[0]->w, _indicators[0]->h));
|
||||
else
|
||||
surface->copyRectToSurface(*_indicators[1], 132, 127, Common::Rect(_indicators[1]->w, _indicators[1]->h));
|
||||
}
|
||||
|
||||
color = _renderMode == Common::kRenderHercG ? 1 : 2;
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 other = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
Common::Point compassYawPos = _renderMode == Common::kRenderHercG ? Common::Point(214, 264) : Common::Point(87, 156);
|
||||
drawCompass(surface, compassYawPos.x, compassYawPos.y, _yaw - 30, 10, 75, other);
|
||||
Common::Point compassPitchPos = _renderMode == Common::kRenderHercG ? Common::Point(502, 264) : Common::Point(230, 156);
|
||||
drawCompass(surface, compassPitchPos.x, compassPitchPos.y, _pitch - 30, 10, 60, other);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
1054
engines/freescape/games/driller/driller.cpp
Normal file
1054
engines/freescape/games/driller/driller.cpp
Normal file
File diff suppressed because it is too large
Load Diff
134
engines/freescape/games/driller/driller.h
Normal file
134
engines/freescape/games/driller/driller.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/* 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 "audio/audiostream.h"
|
||||
#include "audio/mixer.h"
|
||||
|
||||
#include "engines/freescape/games/driller/c64.music.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
enum DrillerFontSize {
|
||||
kDrillerFontSmall,
|
||||
kDrillerFontNormal,
|
||||
};
|
||||
|
||||
class DrillerEngine : public FreescapeEngine {
|
||||
public:
|
||||
DrillerEngine(OSystem *syst, const ADGameDescription *gd);
|
||||
~DrillerEngine();
|
||||
|
||||
uint32 _initialJetEnergy;
|
||||
uint32 _initialJetShield;
|
||||
|
||||
uint32 _initialTankEnergy;
|
||||
uint32 _initialTankShield;
|
||||
|
||||
bool _useAutomaticDrilling;
|
||||
|
||||
DrillerSIDPlayer *_playerSid;
|
||||
|
||||
// Only used for Amiga and Atari ST
|
||||
Font _fontSmall;
|
||||
void drawString(const DrillerFontSize size, const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface);
|
||||
|
||||
Common::HashMap<uint16, uint32> _drillStatusByArea;
|
||||
Common::HashMap<uint16, uint32> _drillMaxScoreByArea;
|
||||
Common::HashMap<uint16, uint32> _drillSuccessByArea;
|
||||
|
||||
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
|
||||
void initGameState() override;
|
||||
bool checkIfGameEnded() override;
|
||||
void endGame() override;
|
||||
|
||||
void gotoArea(uint16 areaID, int entranceID) override;
|
||||
|
||||
void drawInfoMenu() override;
|
||||
void drawSensorShoot(Sensor *sensor) override;
|
||||
void drawCompass(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, double fov, uint32 color);
|
||||
|
||||
void pressedKey(const int keycode) override;
|
||||
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
|
||||
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
|
||||
|
||||
private:
|
||||
bool drillDeployed(Area *area);
|
||||
GeometricObject *_drillBase;
|
||||
Math::Vector3d drillPosition();
|
||||
void addDrill(const Math::Vector3d position, bool gasFound);
|
||||
bool checkDrill(const Math::Vector3d position);
|
||||
void removeDrill(Area *area);
|
||||
void addSkanner(Area *area);
|
||||
|
||||
void loadAssets() override;
|
||||
void loadAssetsAtariFullGame() override;
|
||||
void loadAssetsAtariDemo() override;
|
||||
void loadAssetsAmigaFullGame() override;
|
||||
void loadAssetsAmigaDemo() override;
|
||||
void loadAssetsDOSFullGame() override;
|
||||
void loadAssetsDOSDemo() override;
|
||||
void loadAssetsZXFullGame() override;
|
||||
void loadAssetsCPCFullGame() override;
|
||||
void loadAssetsC64FullGame() override;
|
||||
|
||||
void drawDOSUI(Graphics::Surface *surface) override;
|
||||
void drawZXUI(Graphics::Surface *surface) override;
|
||||
void drawCPCUI(Graphics::Surface *surface) override;
|
||||
void drawC64UI(Graphics::Surface *surface) override;
|
||||
void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
|
||||
bool onScreenControls(Common::Point mouse) override;
|
||||
void initAmigaAtari();
|
||||
void initDOS();
|
||||
void initZX();
|
||||
void initCPC();
|
||||
void initC64();
|
||||
|
||||
void updateTimeVariables() override;
|
||||
|
||||
Common::Rect _moveFowardArea;
|
||||
Common::Rect _moveLeftArea;
|
||||
Common::Rect _moveRightArea;
|
||||
Common::Rect _moveBackArea;
|
||||
Common::Rect _moveUpArea;
|
||||
Common::Rect _moveDownArea;
|
||||
Common::Rect _deployDrillArea;
|
||||
Common::Rect _infoScreenArea;
|
||||
Common::Rect _saveGameArea;
|
||||
Common::Rect _loadGameArea;
|
||||
|
||||
Graphics::ManagedSurface *load8bitTitleImage(Common::SeekableReadStream *file, int offset);
|
||||
Graphics::ManagedSurface *load8bitDemoImage(Common::SeekableReadStream *file, int offset);
|
||||
|
||||
uint32 getPixel8bitTitleImage(int index);
|
||||
void renderPixels8bitTitleImage(Graphics::ManagedSurface *surface, int &i, int &j, int pixels);
|
||||
Graphics::ManagedSurface *_borderExtra;
|
||||
Texture *_borderExtraTexture;
|
||||
|
||||
Common::SeekableReadStream *decryptFileAtari(const Common::Path &filename);
|
||||
Common::SeekableReadStream *decryptFileAtariVirtualWorlds(const Common::Path &filename);
|
||||
};
|
||||
|
||||
enum DrillerReleaseFlags {
|
||||
GF_AMIGA_MAGAZINE_DEMO = (1 << 0),
|
||||
GF_ATARI_MAGAZINE_DEMO = (1 << 1),
|
||||
};
|
||||
|
||||
}
|
||||
160
engines/freescape/games/driller/zx.cpp
Normal file
160
engines/freescape/games/driller/zx.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/driller/driller.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void DrillerEngine::initZX() {
|
||||
_viewArea = Common::Rect(56, 20, 264, 124);
|
||||
_soundIndexAreaChange = 10;
|
||||
}
|
||||
|
||||
void DrillerEngine::loadAssetsZXFullGame() {
|
||||
Common::File file;
|
||||
file.open("driller.zx.title");
|
||||
if (file.isOpen()) {
|
||||
_title = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find driller.zx.title");
|
||||
|
||||
file.close();
|
||||
|
||||
file.open("driller.zx.border");
|
||||
if (file.isOpen()) {
|
||||
_border = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find driller.zx.border");
|
||||
file.close();
|
||||
|
||||
file.open("driller.zx.data");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open driller.zx.data");
|
||||
|
||||
if (_variant & GF_ZX_DISC)
|
||||
loadMessagesFixedSize(&file, 0x2164, 14, 20);
|
||||
else
|
||||
loadMessagesFixedSize(&file, 0x20e4, 14, 20);
|
||||
|
||||
if (_variant & GF_ZX_RETAIL)
|
||||
loadFonts(&file, 0x62ca);
|
||||
else if (_variant & GF_ZX_BUDGET)
|
||||
loadFonts(&file, 0x5aa8);
|
||||
else if (_variant & GF_ZX_DISC)
|
||||
loadFonts(&file, 0x63f0);
|
||||
|
||||
if (_variant & GF_ZX_DISC)
|
||||
loadGlobalObjects(&file, 0x1d13, 8);
|
||||
else
|
||||
loadGlobalObjects(&file, 0x1c93, 8);
|
||||
|
||||
if (_variant & GF_ZX_RETAIL)
|
||||
load8bitBinary(&file, 0x642c, 4);
|
||||
else if (_variant & GF_ZX_BUDGET)
|
||||
load8bitBinary(&file, 0x5c0a, 4);
|
||||
else if (_variant & GF_ZX_DISC)
|
||||
load8bitBinary(&file, 0x6552, 4);
|
||||
|
||||
else
|
||||
error("Unknown ZX spectrum variant");
|
||||
}
|
||||
|
||||
void DrillerEngine::drawZXUI(Graphics::Surface *surface) {
|
||||
uint32 color = 5;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
drawStringInSurface(_currentArea->_name, 174, 188, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 151, 149, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 151, 157, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 151, 165, front, back, surface);
|
||||
if (_playerHeightNumber >= 0)
|
||||
drawStringInSurface(Common::String::format("%d", _playerHeightNumber), 72, 165, front, back, surface);
|
||||
else
|
||||
drawStringInSurface(Common::String::format("%s", "J"), 72, 165, front, back, surface);
|
||||
|
||||
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 63, 149, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 63, 157, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%07d", score), 215, 133, white, back, surface);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
drawStringInSurface(Common::String::format("%02d", hours), 185, 12, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%02d", minutes), 207, 12, front, back, surface);
|
||||
drawStringInSurface(Common::String::format("%02d", seconds), 231, 12, front, back, surface);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 168, 181, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else {
|
||||
if (_currentArea->_gasPocketRadius == 0)
|
||||
message = _messagesList[2];
|
||||
else if (_drillStatusByArea[_currentArea->getAreaID()])
|
||||
message = _messagesList[0];
|
||||
else
|
||||
message = _messagesList[1];
|
||||
|
||||
drawStringInSurface(message, 168, 181, front, back, surface);
|
||||
}
|
||||
|
||||
int energy = _gameStateVars[k8bitVariableEnergy];
|
||||
int shield = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
if (energy >= 0) {
|
||||
Common::Rect backBar(43, 188, 107 - energy, 194);
|
||||
surface->fillRect(backBar, back);
|
||||
Common::Rect energyBar(106 - energy, 188, 106, 194);
|
||||
surface->fillRect(energyBar, front);
|
||||
}
|
||||
|
||||
if (shield >= 0) {
|
||||
Common::Rect backBar(43, 181, 107 - shield, 187);
|
||||
surface->fillRect(backBar, back);
|
||||
|
||||
Common::Rect shieldBar(106 - shield, 181, 106, 187);
|
||||
surface->fillRect(shieldBar, front);
|
||||
}
|
||||
|
||||
drawCompass(surface, 103, 160, _yaw - 30, 10, 75, front);
|
||||
drawCompass(surface, 220 - 3, 160, _pitch - 30, 10, 60, front);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
190
engines/freescape/games/eclipse/atari.cpp
Normal file
190
engines/freescape/games/eclipse/atari.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/eclipse/eclipse.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void EclipseEngine::initAmigaAtari() {
|
||||
_viewArea = Common::Rect(32, 16, 288, 118);
|
||||
}
|
||||
|
||||
/*void EclipseEngine::loadAssetsCPCFullGame() {
|
||||
Common::File file;
|
||||
|
||||
if (isEclipse2())
|
||||
file.open("TE2.BI1");
|
||||
else
|
||||
file.open("TESCR.SCR");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TESCR.SCR/TE2.BI1");
|
||||
|
||||
_title = readCPCImage(&file, true);
|
||||
_title->setPalette((byte*)&kCPCPaletteTitleData, 0, 4);
|
||||
|
||||
file.close();
|
||||
if (isEclipse2())
|
||||
file.open("TE2.BI3");
|
||||
else
|
||||
file.open("TECON.SCR");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TECON.SCR/TE2.BI3");
|
||||
|
||||
_border = readCPCImage(&file, true);
|
||||
_border->setPalette((byte*)&kCPCPaletteTitleData, 0, 4);
|
||||
|
||||
file.close();
|
||||
if (isEclipse2())
|
||||
file.open("TE2.BI2");
|
||||
else
|
||||
file.open("TECODE.BIN");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TECODE.BIN/TE2.BI2");
|
||||
|
||||
if (isEclipse2()) {
|
||||
loadFonts(&file, 0x60bc, _font);
|
||||
loadMessagesFixedSize(&file, 0x326, 16, 30);
|
||||
load8bitBinary(&file, 0x62b4, 16);
|
||||
} else {
|
||||
loadFonts(&file, 0x6076, _font);
|
||||
loadMessagesFixedSize(&file, 0x326, 16, 30);
|
||||
load8bitBinary(&file, 0x626e, 16);
|
||||
}
|
||||
|
||||
for (auto &it : _areaMap) {
|
||||
it._value->addStructure(_areaMap[255]);
|
||||
|
||||
if (isEclipse2() && it._value->getAreaID() == 1)
|
||||
continue;
|
||||
|
||||
if (isEclipse2() && it._value->getAreaID() == _startArea)
|
||||
continue;
|
||||
|
||||
for (int16 id = 183; id < 207; id++)
|
||||
it._value->addObjectFromArea(id, _areaMap[255]);
|
||||
}
|
||||
loadColorPalette();
|
||||
swapPalette(1);
|
||||
|
||||
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void EclipseEngine::drawCPCUI(Graphics::Surface *surface) {
|
||||
uint32 color = _currentArea->_underFireBackgroundColor;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_inkColor;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 other = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
|
||||
shield = shield < 0 ? 0 : shield;
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 102, 135, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else if (!_currentAreaMessages.empty())
|
||||
drawStringInSurface(_currentArea->_name, 102, 135, back, front, surface);
|
||||
|
||||
Common::String scoreStr = Common::String::format("%07d", score);
|
||||
drawStringInSurface(scoreStr, 136, 6, back, other, surface, 'Z' - '0' + 1);
|
||||
|
||||
int x = 171;
|
||||
if (shield < 10)
|
||||
x = 179;
|
||||
else if (shield < 100)
|
||||
x = 175;
|
||||
|
||||
Common::String shieldStr = Common::String::format("%d", shield);
|
||||
drawStringInSurface(shieldStr, x, 162, back, other, surface);
|
||||
|
||||
drawStringInSurface(Common::String('0' + _angleRotationIndex - 3), 79, 135, back, front, surface, 'Z' - '$' + 1);
|
||||
drawStringInSurface(Common::String('3' - _playerStepIndex), 63, 135, back, front, surface, 'Z' - '$' + 1);
|
||||
drawStringInSurface(Common::String('7' - _playerHeightNumber), 240, 135, back, front, surface, 'Z' - '$' + 1);
|
||||
|
||||
if (_shootingFrames > 0) {
|
||||
drawStringInSurface("4", 232, 135, back, front, surface, 'Z' - '$' + 1);
|
||||
drawStringInSurface("<", 240, 135, back, front, surface, 'Z' - '$' + 1);
|
||||
}
|
||||
drawAnalogClock(surface, 90, 172, back, other, front);
|
||||
drawIndicator(surface, 45, 4, 12);
|
||||
drawEclipseIndicator(surface, 228, 0, front, other);
|
||||
}*/
|
||||
|
||||
void EclipseEngine::loadAssetsAtariFullGame() {
|
||||
Common::File file;
|
||||
file.open("0.tec");
|
||||
_title = loadAndConvertNeoImage(&file, 0x17ac);
|
||||
file.close();
|
||||
|
||||
Common::SeekableReadStream *stream = decryptFileAmigaAtari("1.tec", "0.tec", 0x1774 - 4 * 1024);
|
||||
parseAmigaAtariHeader(stream);
|
||||
|
||||
loadMessagesVariableSize(stream, 0x87a6, 28);
|
||||
load8bitBinary(stream, 0x2a53c, 16);
|
||||
|
||||
_border = loadAndConvertNeoImage(stream, 0x139c8);
|
||||
loadPalettes(stream, 0x2a0fa);
|
||||
loadSoundsFx(stream, 0x3030c, 6);
|
||||
|
||||
/*
|
||||
loadFonts(stream, 0xd06b, _fontBig);
|
||||
loadFonts(stream, 0xd49a, _fontMedium);
|
||||
loadFonts(stream, 0xd49b, _fontSmall);
|
||||
|
||||
load8bitBinary(stream, 0x20918, 16);
|
||||
loadMessagesVariableSize(stream, 0x3f6f, 66);
|
||||
|
||||
loadPalettes(stream, 0x204d6);
|
||||
loadGlobalObjects(stream, 0x32f6, 24);
|
||||
loadSoundsFx(stream, 0x266e8, 11);*/
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
180
engines/freescape/games/eclipse/c64.cpp
Normal file
180
engines/freescape/games/eclipse/c64.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/eclipse/eclipse.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void EclipseEngine::initC64() {
|
||||
_viewArea = Common::Rect(32, 32, 288, 136);
|
||||
|
||||
_maxEnergy = 35;
|
||||
}
|
||||
|
||||
extern byte kC64Palette[16][3];
|
||||
|
||||
void EclipseEngine::loadAssetsC64FullGame() {
|
||||
Common::File file;
|
||||
file.open(isEclipse2() ? "totaleclipse2.c64.data" : "totaleclipse.c64.data");
|
||||
|
||||
if (_variant & GF_C64_TAPE) {
|
||||
int size = file.size();
|
||||
|
||||
byte *buffer = (byte *)malloc(size * sizeof(byte));
|
||||
file.read(buffer, file.size());
|
||||
|
||||
_extraBuffer = decompressC64RLE(buffer, &size, isEclipse2() ? 0xd2 : 0xe1);
|
||||
// size should be the size of the decompressed data
|
||||
Common::MemoryReadStream dfile(_extraBuffer, size, DisposeAfterUse::NO);
|
||||
|
||||
loadMessagesFixedSize(&dfile, 0x1d84, 16, 30);
|
||||
loadFonts(&dfile, 0xc3e);
|
||||
load8bitBinary(&dfile, 0x9a3e, 16);
|
||||
} else if (_variant & GF_C64_DISC) {
|
||||
loadMessagesFixedSize(&file, 0x1534, 16, 30);
|
||||
loadFonts(&file, 0x3f2);
|
||||
if (isEclipse2())
|
||||
load8bitBinary(&file, 0x7ac4, 16);
|
||||
else
|
||||
load8bitBinary(&file, 0x7ab4, 16);
|
||||
} else
|
||||
error("Unknown C64 variant %x", _variant);
|
||||
|
||||
Graphics::Surface *surf = loadBundledImage("eclipse_border");
|
||||
surf->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
_border = new Graphics::ManagedSurface();
|
||||
_border->copyFrom(*surf);
|
||||
surf->free();
|
||||
delete surf;
|
||||
|
||||
file.close();
|
||||
file.open(isEclipse2() ? "totaleclipse2.c64.title.bitmap" : "totaleclipse.c64.title.bitmap");
|
||||
|
||||
Common::File colorFile1;
|
||||
colorFile1.open(isEclipse2() ? "totaleclipse2.c64.title.colors1" : "totaleclipse.c64.title.colors1");
|
||||
Common::File colorFile2;
|
||||
colorFile2.open(isEclipse2() ? "totaleclipse2.c64.title.colors2" : "totaleclipse.c64.title.colors2");
|
||||
|
||||
_title = loadAndConvertDoodleImage(&file, &colorFile1, &colorFile2, (byte *)&kC64Palette);
|
||||
|
||||
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
|
||||
void EclipseEngine::drawC64UI(Graphics::Surface *surface) {
|
||||
uint32 color = _currentArea->_underFireBackgroundColor;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(13, r, g, b);
|
||||
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(3, r, g, b);
|
||||
uint32 blue = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(2, r, g, b);
|
||||
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(0, r, g, b);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(1, r, g, b);
|
||||
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
|
||||
int energy = _gameStateVars[k8bitVariableEnergy];
|
||||
shield = shield < 0 ? 0 : shield;
|
||||
|
||||
_gfx->readFromPalette(7, r, g, b);
|
||||
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 104, 138, back, yellow, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else if (!_currentAreaMessages.empty())
|
||||
drawStringInSurface(_currentArea->_name, 104, 138, back, yellow, surface);
|
||||
|
||||
drawScoreString(score, 128, 7, black, white, surface);
|
||||
|
||||
Common::String shieldStr = Common::String::format("%d", shield);
|
||||
|
||||
int x = 174;
|
||||
if (shield < 10)
|
||||
x = 182;
|
||||
else if (shield < 100)
|
||||
x = 179;
|
||||
|
||||
if (energy < 0)
|
||||
energy = 0;
|
||||
|
||||
drawStringInSurface(shieldStr, x, 161, back, red, surface);
|
||||
|
||||
Common::Rect jarBackground(112, 170, 144, 196);
|
||||
surface->fillRect(jarBackground, back);
|
||||
|
||||
Common::Rect jarWater(112, 196 - energy, 144, 196);
|
||||
surface->fillRect(jarWater, blue);
|
||||
|
||||
// TODO
|
||||
/*drawStringInSurface(shiftStr("0", 'Z' - '$' + 1 - _angleRotationIndex), 79, 138, back, yellow, surface);
|
||||
drawStringInSurface(shiftStr("3", 'Z' - '$' + 1 - _playerStepIndex), 63, 138, back, yellow, surface);
|
||||
drawStringInSurface(shiftStr("7", 'Z' - '$' + 1 - _playerHeightNumber), 240, 138, back, yellow, surface);
|
||||
|
||||
if (_shootingFrames > 0) {
|
||||
drawStringInSurface(shiftStr("4", 'Z' - '$' + 1), 232, 138, back, yellow, surface);
|
||||
drawStringInSurface(shiftStr("<", 'Z' - '$' + 1) , 240, 138, back, yellow, surface);
|
||||
}*/
|
||||
|
||||
drawAnalogClockHand(surface, 72, 172, 38 * 6 - 90, 11, white);
|
||||
drawAnalogClockHand(surface, 72, 172, 37 * 6 - 90, 11, white);
|
||||
drawAnalogClockHand(surface, 72, 172, 36 * 6 - 90, 11, white);
|
||||
drawAnalogClock(surface, 72, 172, back, red, white);
|
||||
|
||||
surface->fillRect(Common::Rect(236, 170, 258, 187), white);
|
||||
drawCompass(surface, 247, 177, _yaw, 13, back);
|
||||
|
||||
drawIndicator(surface, 56, 4, 8);
|
||||
drawEclipseIndicator(surface, 224, 0, front, green);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
203
engines/freescape/games/eclipse/cpc.cpp
Normal file
203
engines/freescape/games/eclipse/cpc.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/eclipse/eclipse.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void EclipseEngine::initCPC() {
|
||||
_viewArea = Common::Rect(36 + 3, 24 + 8, 284, 130 + 3);
|
||||
}
|
||||
|
||||
byte kCPCPaletteEclipseTitleData[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0xff, 0xff, 0x00},
|
||||
{0xff, 0x00, 0xff},
|
||||
{0xff, 0x80, 0x00},
|
||||
};
|
||||
|
||||
byte kCPCPaletteEclipseBorderData[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0xff, 0x80, 0x00},
|
||||
{0x80, 0xff, 0xff},
|
||||
{0x00, 0x80, 0x00},
|
||||
};
|
||||
|
||||
|
||||
extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode0);
|
||||
|
||||
void EclipseEngine::loadAssetsCPCFullGame() {
|
||||
Common::File file;
|
||||
|
||||
if (isEclipse2())
|
||||
file.open("TE2.BI1");
|
||||
else
|
||||
file.open("TESCR.SCR");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TESCR.SCR/TE2.BI1");
|
||||
|
||||
_title = readCPCImage(&file, true);
|
||||
_title->setPalette((byte*)&kCPCPaletteEclipseTitleData, 0, 4);
|
||||
|
||||
file.close();
|
||||
if (isEclipse2())
|
||||
file.open("TE2.BI3");
|
||||
else
|
||||
file.open("TECON.SCR");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TECON.SCR/TE2.BI3");
|
||||
|
||||
_border = readCPCImage(&file, true);
|
||||
_border->setPalette((byte*)&kCPCPaletteEclipseBorderData, 0, 4);
|
||||
|
||||
file.close();
|
||||
if (isEclipse2())
|
||||
file.open("TE2.BI2");
|
||||
else
|
||||
file.open("TECODE.BIN");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TECODE.BIN/TE2.BI2");
|
||||
|
||||
if (isEclipse2()) {
|
||||
loadFonts(&file, 0x60bc);
|
||||
loadMessagesFixedSize(&file, 0x326, 16, 30);
|
||||
load8bitBinary(&file, 0x62b4, 16);
|
||||
} else {
|
||||
loadFonts(&file, 0x6076);
|
||||
loadMessagesFixedSize(&file, 0x326, 16, 30);
|
||||
load8bitBinary(&file, 0x626e, 16);
|
||||
}
|
||||
|
||||
loadColorPalette();
|
||||
swapPalette(1);
|
||||
|
||||
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void EclipseEngine::loadAssetsCPCDemo() {
|
||||
Common::File file;
|
||||
|
||||
file.open("TECON.BIN");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TECON.BIN");
|
||||
|
||||
_border = readCPCImage(&file, true);
|
||||
_border->setPalette((byte*)&kCPCPaletteEclipseTitleData, 0, 4);
|
||||
|
||||
file.close();
|
||||
file.open("TEPROG.BIN");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TEPROG.BIN");
|
||||
|
||||
loadFonts(&file, 0x63ce);
|
||||
loadMessagesFixedSize(&file, 0x362, 16, 23);
|
||||
loadMessagesFixedSize(&file, 0x570b, 264, 5);
|
||||
load8bitBinary(&file, 0x65c6, 16);
|
||||
loadColorPalette();
|
||||
swapPalette(1);
|
||||
|
||||
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void EclipseEngine::drawCPCUI(Graphics::Surface *surface) {
|
||||
uint32 color = _currentArea->_underFireBackgroundColor;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_inkColor;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 other = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
|
||||
shield = shield < 0 ? 0 : shield;
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 102, 135, back, front, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else if (!_currentAreaMessages.empty())
|
||||
drawStringInSurface(_currentArea->_name, 102, 135, back, front, surface);
|
||||
|
||||
drawScoreString(score, 136, 6, back, other, surface);
|
||||
|
||||
int x = 171;
|
||||
if (shield < 10)
|
||||
x = 179;
|
||||
else if (shield < 100)
|
||||
x = 175;
|
||||
|
||||
Common::String shieldStr = Common::String::format("%d", shield);
|
||||
drawStringInSurface(shieldStr, x, 162, back, other, surface);
|
||||
|
||||
drawStringInSurface(shiftStr("0", 'Z' - '$' + 1 - _angleRotationIndex), 79, 135, back, front, surface);
|
||||
drawStringInSurface(shiftStr("3", 'Z' - '$' + 1 - _playerStepIndex), 63, 135, back, front, surface);
|
||||
drawStringInSurface(shiftStr("7", 'Z' - '$' + 1 - _playerHeightNumber), 240, 135, back, front, surface);
|
||||
|
||||
if (_shootingFrames > 0) {
|
||||
drawStringInSurface(shiftStr("4", 'Z' - '$' + 1), 232, 135, back, front, surface);
|
||||
drawStringInSurface(shiftStr("<", 'Z' - '$' + 1), 240, 135, back, front, surface);
|
||||
}
|
||||
drawAnalogClock(surface, 90, 172, back, other, front);
|
||||
drawIndicator(surface, 45, 4, 12);
|
||||
drawEclipseIndicator(surface, 228, 0, front, other);
|
||||
|
||||
Common::Rect jarBackground(124, 165, 148, 192);
|
||||
surface->fillRect(jarBackground, back);
|
||||
|
||||
Common::Rect jarWater(124, 192 - _gameStateVars[k8bitVariableEnergy], 148, 192);
|
||||
surface->fillRect(jarWater, color);
|
||||
|
||||
surface->fillRect(Common::Rect(225, 168, 235, 187), front);
|
||||
drawCompass(surface, 229, 177, _yaw, 10, back);
|
||||
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
207
engines/freescape/games/eclipse/dos.cpp
Normal file
207
engines/freescape/games/eclipse/dos.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
/* 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 "audio/audiostream.h"
|
||||
#include "audio/decoders/raw.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/eclipse/eclipse.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
extern byte kEGADefaultPalette[16][3];
|
||||
extern byte kCGAPaletteRedGreen[4][3];
|
||||
extern byte kCGAPalettePinkBlue[4][3];
|
||||
|
||||
void EclipseEngine::initDOS() {
|
||||
_viewArea = Common::Rect(40, 33, 280, 133);
|
||||
_soundIndexShoot = 18;
|
||||
_soundIndexCollide = 1;
|
||||
_soundIndexStepDown = 3;
|
||||
_soundIndexStepUp = 3;
|
||||
_soundIndexMenu = -1;
|
||||
_soundIndexStart = 9;
|
||||
_soundIndexAreaChange = 5;
|
||||
}
|
||||
|
||||
void EclipseEngine::loadAssetsDOSFullGame() {
|
||||
Common::File file;
|
||||
if (_renderMode == Common::kRenderEGA) {
|
||||
file.open("SCN1E.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
}
|
||||
file.close();
|
||||
file.open("TOTEE.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TOTEE.EXE");
|
||||
|
||||
loadMessagesFixedSize(&file, 0x710f, 16, 20);
|
||||
loadSoundsFx(&file, 0xd670, 5);
|
||||
loadSpeakerFxDOS(&file, 0x7396 + 0x200, 0x72a1 + 0x200, 20);
|
||||
loadFonts(&file, 0xd403);
|
||||
load8bitBinary(&file, 0x3ce0, 16);
|
||||
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
|
||||
|
||||
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
|
||||
} else if (_renderMode == Common::kRenderCGA) {
|
||||
file.open("SCN1C.DAT");
|
||||
if (file.isOpen()) {
|
||||
_title = load8bitBinImage(&file, 0x0);
|
||||
_title->setPalette((byte *)&kCGAPaletteRedGreen, 0, 4);
|
||||
}
|
||||
file.close();
|
||||
file.open("TOTEC.EXE");
|
||||
|
||||
if (!file.isOpen())
|
||||
error("Failed to open TOTEC.EXE");
|
||||
|
||||
loadMessagesFixedSize(&file, 0x594f, 16, 20);
|
||||
loadSoundsFx(&file, 0xb9f0, 5);
|
||||
loadFonts(&file, 0xb785);
|
||||
load8bitBinary(&file, 0x2530, 4);
|
||||
_border = load8bitBinImage(&file, 0x210);
|
||||
_border->setPalette((byte *)&kCGAPaletteRedGreen, 0, 4);
|
||||
swapPalette(_startArea);
|
||||
} else
|
||||
error("Invalid or unsupported render mode %s for Total Eclipse", Common::getRenderModeDescription(_renderMode));
|
||||
}
|
||||
|
||||
void EclipseEngine::drawDOSUI(Graphics::Surface *surface) {
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
|
||||
shield = shield < 0 ? 0 : shield;
|
||||
|
||||
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0x55);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
|
||||
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0x00, 0x00);
|
||||
uint32 blue = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x55, 0x55, 0xFF);
|
||||
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x55, 0xFF, 0x55);
|
||||
uint32 redish = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0x55, 0x55);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 102, 135, black, yellow, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else if (!_currentAreaMessages.empty())
|
||||
drawStringInSurface(_currentArea->_name, 102, 135, black, yellow, surface);
|
||||
|
||||
drawScoreString(score, 136, 6, black, white, surface);
|
||||
|
||||
int x = 171;
|
||||
if (shield < 10)
|
||||
x = 179;
|
||||
else if (shield < 100)
|
||||
x = 175;
|
||||
|
||||
Common::String shieldStr = Common::String::format("%d", shield);
|
||||
drawStringInSurface(shieldStr, x, 162, black, redish, surface);
|
||||
|
||||
drawStringInSurface(shiftStr("0", 'Z' - '$' + 1 - _angleRotationIndex), 79, 135, black, yellow, surface);
|
||||
drawStringInSurface(shiftStr("3", 'Z' - '$' + 1 - _playerStepIndex), 63, 135, black, yellow, surface);
|
||||
drawStringInSurface(shiftStr("7", 'Z' - '$' + 1 - _playerHeightNumber), 240, 135, black, yellow, surface);
|
||||
|
||||
if (_shootingFrames > 0) {
|
||||
drawStringInSurface(shiftStr("4", 'Z' - '$' + 1), 232, 135, black, yellow, surface);
|
||||
drawStringInSurface(shiftStr("<", 'Z' - '$' + 1), 240, 135, black, yellow, surface);
|
||||
}
|
||||
drawAnalogClock(surface, 90, 172, black, red, white);
|
||||
|
||||
Common::Rect jarBackground(124, 165, 148, 192);
|
||||
surface->fillRect(jarBackground, black);
|
||||
|
||||
Common::Rect jarWater(124, 192 - _gameStateVars[k8bitVariableEnergy], 148, 192);
|
||||
surface->fillRect(jarWater, blue);
|
||||
|
||||
drawIndicator(surface, 41, 4, 16);
|
||||
drawEclipseIndicator(surface, 228, 0, yellow, green);
|
||||
surface->fillRect(Common::Rect(225, 168, 235, 187), white);
|
||||
drawCompass(surface, 229, 177, _yaw, 10, black);
|
||||
}
|
||||
|
||||
soundFx *EclipseEngine::load1bPCM(Common::SeekableReadStream *file, int offset) {
|
||||
soundFx *sound = (soundFx *)malloc(sizeof(soundFx));
|
||||
file->seek(offset);
|
||||
sound->size = file->readUint16LE();
|
||||
debugC(1, kFreescapeDebugParser, "size: %d", sound->size);
|
||||
sound->sampleRate = file->readUint16LE();
|
||||
debugC(1, kFreescapeDebugParser, "sample rate?: %f", sound->sampleRate);
|
||||
|
||||
uint8 *data = (uint8 *)malloc(sound->size * sizeof(uint8) * 8);
|
||||
for (int i = 0; i < sound->size; i++) {
|
||||
uint8 byte = file->readByte();
|
||||
for (int j = 0; j < 8; j++) {
|
||||
data[8 * i + j] = byte & 1 ? 255 : 0;
|
||||
byte = byte >> 1;
|
||||
}
|
||||
}
|
||||
sound->size = sound->size * 8;
|
||||
sound->data = (byte *)data;
|
||||
return sound;
|
||||
}
|
||||
|
||||
void EclipseEngine::loadSoundsFx(Common::SeekableReadStream *file, int offset, int number) {
|
||||
if (isAmiga() || isAtariST()) {
|
||||
FreescapeEngine::loadSoundsFx(file, offset, number);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
_soundsFx[i] = load1bPCM(file, offset);
|
||||
offset += (_soundsFx[i]->size / 8) + 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EclipseEngine::playSoundFx(int index, bool sync) {
|
||||
if (isAmiga() || isAtariST()) {
|
||||
FreescapeEngine::playSoundFx(index, sync);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_soundsFx.size() == 0) {
|
||||
debugC(1, kFreescapeDebugMedia, "WARNING: Sounds are not loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
int size = _soundsFx[index]->size;
|
||||
//int sampleRate = _soundsFx[index]->sampleRate;
|
||||
byte *data = _soundsFx[index]->data;
|
||||
|
||||
Audio::SeekableAudioStream *stream = Audio::makeRawStream(data, size, 11025, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
|
||||
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundFxHandle, stream, -1, kFreescapeDefaultVolume / 10);
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace Freescape
|
||||
812
engines/freescape/games/eclipse/eclipse.cpp
Normal file
812
engines/freescape/games/eclipse/eclipse.cpp
Normal file
@@ -0,0 +1,812 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "backends/keymapper/action.h"
|
||||
#include "backends/keymapper/keymap.h"
|
||||
#include "backends/keymapper/standard-actions.h"
|
||||
#include "common/translation.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/eclipse/eclipse.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
EclipseEngine::EclipseEngine(OSystem *syst, const ADGameDescription *gd) : FreescapeEngine(syst, gd) {
|
||||
// These sounds can be overriden by the class of each platform
|
||||
_soundIndexStartFalling = -1;
|
||||
_soundIndexEndFalling = -1;
|
||||
|
||||
_soundIndexNoShield = -1;
|
||||
_soundIndexNoEnergy = -1;
|
||||
_soundIndexFallen = -1;
|
||||
_soundIndexTimeout = -1;
|
||||
_soundIndexForceEndGame = -1;
|
||||
_soundIndexCrushed = -1;
|
||||
_soundIndexMissionComplete = -1;
|
||||
|
||||
_maxEnergy = 27;
|
||||
_maxShield = 50;
|
||||
|
||||
_initialEnergy = 16;
|
||||
_initialShield = 50;
|
||||
|
||||
if (isDOS())
|
||||
initDOS();
|
||||
else if (isCPC())
|
||||
initCPC();
|
||||
else if (isC64())
|
||||
initC64();
|
||||
else if (isSpectrum())
|
||||
initZX();
|
||||
else if (isAmiga() || isAtariST())
|
||||
initAmigaAtari();
|
||||
|
||||
_playerHeightNumber = 1;
|
||||
_playerHeightMaxNumber = 1;
|
||||
|
||||
_playerWidth = 8;
|
||||
_playerDepth = 8;
|
||||
_stepUpDistance = 32;
|
||||
|
||||
_playerStepIndex = 2;
|
||||
_playerSteps.clear();
|
||||
_playerSteps.push_back(2);
|
||||
_playerSteps.push_back(30);
|
||||
_playerSteps.push_back(60);
|
||||
|
||||
_angleRotationIndex = 1;
|
||||
_angleRotations.push_back(5);
|
||||
_angleRotations.push_back(10);
|
||||
_angleRotations.push_back(15);
|
||||
|
||||
_endArea = 1;
|
||||
_endEntrance = 33;
|
||||
|
||||
_lastThirtySeconds = 0;
|
||||
_lastFiveSeconds = 0;
|
||||
_lastSecond = -1;
|
||||
_resting = false;
|
||||
}
|
||||
|
||||
void EclipseEngine::initGameState() {
|
||||
FreescapeEngine::initGameState();
|
||||
|
||||
_playerHeightNumber = 1;
|
||||
|
||||
_gameStateVars[k8bitVariableEnergy] = _initialEnergy;
|
||||
_gameStateVars[k8bitVariableShield] = _initialShield;
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
_lastThirtySeconds = seconds / 30;
|
||||
_lastFiveSeconds = seconds / 5;
|
||||
_resting = false;
|
||||
|
||||
// Start playing music, if any, in any supported format
|
||||
playMusic("Total Eclipse Theme");
|
||||
}
|
||||
|
||||
void EclipseEngine::loadAssets() {
|
||||
FreescapeEngine::loadAssets();
|
||||
|
||||
Common::List<int> globalIds = _areaMap[255]->getEntranceIds();
|
||||
for (auto &it : _areaMap) {
|
||||
if (it._value->getAreaID() == 255)
|
||||
continue;
|
||||
|
||||
it._value->addStructure(_areaMap[255]);
|
||||
|
||||
if (isDemo()) {
|
||||
it._value->_name = " NOW TRAINING ";
|
||||
}
|
||||
|
||||
for (auto &id : globalIds) {
|
||||
if (it._value->entranceWithID(id))
|
||||
continue;
|
||||
|
||||
Object *obj = _areaMap[255]->entranceWithID(id);
|
||||
assert(obj);
|
||||
assert(obj->getType() == ObjectType::kEntranceType);
|
||||
// The entrance is not in the current area, so we need to add it
|
||||
it._value->addObjectFromArea(id, _areaMap[255]);
|
||||
}
|
||||
}
|
||||
|
||||
_timeoutMessage = _messagesList[1];
|
||||
_noShieldMessage = _messagesList[0];
|
||||
//_noEnergyMessage = _messagesList[16];
|
||||
_fallenMessage = _messagesList[3];
|
||||
_crushedMessage = _messagesList[2];
|
||||
|
||||
_areaMap[1]->addFloor();
|
||||
if (isSpectrum())
|
||||
_areaMap[1]->_paperColor = 1;
|
||||
|
||||
if (!isDemo() && !isEclipse2()) {
|
||||
_areaMap[51]->addFloor();
|
||||
_areaMap[51]->_paperColor = 1;
|
||||
|
||||
// Workaround for fixing some planar objects from area 9 that have null size
|
||||
Object *obj = nullptr;
|
||||
obj = _areaMap[9]->objectWithID(7);
|
||||
assert(obj);
|
||||
obj->_size = 32 * Math::Vector3d(3, 0, 2);
|
||||
|
||||
obj = _areaMap[9]->objectWithID(8);
|
||||
assert(obj);
|
||||
obj->_size = 32 * Math::Vector3d(3, 0, 2);
|
||||
|
||||
obj = _areaMap[9]->objectWithID(9);
|
||||
assert(obj);
|
||||
obj->_size = 32 * Math::Vector3d(3, 0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
bool EclipseEngine::checkIfGameEnded() {
|
||||
if (_gameStateControl == kFreescapeGameStatePlaying) {
|
||||
if (_hasFallen && _avoidRenderingFrames == 0) {
|
||||
_hasFallen = false;
|
||||
if (isDOS())
|
||||
playSoundFx(4, false);
|
||||
else
|
||||
playSound(_soundIndexStartFalling, false, _soundFxHandle);
|
||||
|
||||
stopMovement();
|
||||
// If shield is less than 11 after a fall, the game ends
|
||||
if (_gameStateVars[k8bitVariableShield] > 15 + 11) {
|
||||
_gameStateVars[k8bitVariableShield] -= 15;
|
||||
return false; // Game can continue
|
||||
}
|
||||
if (!_fallenMessage.empty())
|
||||
insertTemporaryMessage(_fallenMessage, _countdown - 4);
|
||||
_gameStateControl = kFreescapeGameStateEnd;
|
||||
} else if (getGameBit(16)) {
|
||||
_gameStateControl = kFreescapeGameStateEnd;
|
||||
insertTemporaryMessage(_messagesList[4], INT_MIN);
|
||||
}
|
||||
|
||||
FreescapeEngine::checkIfGameEnded();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EclipseEngine::endGame() {
|
||||
FreescapeEngine::endGame();
|
||||
|
||||
if (!_endGamePlayerEndArea)
|
||||
return;
|
||||
|
||||
if (_gameStateControl == kFreescapeGameStateEnd) {
|
||||
removeTimers();
|
||||
if (getGameBit(16)) {
|
||||
if (_countdown > - 3600)
|
||||
_countdown -= 10;
|
||||
else
|
||||
_countdown = -3600;
|
||||
} else {
|
||||
if (_countdown > 0)
|
||||
_countdown -= 10;
|
||||
else
|
||||
_countdown = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (_endGameKeyPressed && (_countdown == 0 || _countdown == -3600)) {
|
||||
if (isSpectrum())
|
||||
playSound(5, true, _soundFxHandle);
|
||||
_gameStateControl = kFreescapeGameStateRestart;
|
||||
}
|
||||
_endGameKeyPressed = false;
|
||||
}
|
||||
|
||||
void EclipseEngine::initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) {
|
||||
FreescapeEngine::initKeymaps(engineKeyMap, infoScreenKeyMap, target);
|
||||
Common::Action *act;
|
||||
|
||||
act = new Common::Action("SAVE", _("Save game"));
|
||||
act->setCustomEngineActionEvent(kActionSave);
|
||||
act->addDefaultInputMapping("s");
|
||||
infoScreenKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("LOAD", _("Load game"));
|
||||
act->setCustomEngineActionEvent(kActionLoad);
|
||||
act->addDefaultInputMapping("l");
|
||||
infoScreenKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("QUIT", _("Quit game"));
|
||||
act->setCustomEngineActionEvent(kActionEscape);
|
||||
if (isSpectrum())
|
||||
act->addDefaultInputMapping("1");
|
||||
else
|
||||
act->addDefaultInputMapping("ESCAPE");
|
||||
infoScreenKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("TOGGLESOUND", _("Toggle Sound"));
|
||||
act->setCustomEngineActionEvent(kActionToggleSound);
|
||||
act->addDefaultInputMapping("t");
|
||||
infoScreenKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("ROTL", _("Rotate Left"));
|
||||
act->setCustomEngineActionEvent(kActionRotateLeft);
|
||||
act->addDefaultInputMapping("q");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("ROTR", _("Rotate Right"));
|
||||
act->setCustomEngineActionEvent(kActionRotateRight);
|
||||
act->addDefaultInputMapping("w");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
// I18N: Illustrates the angle at which you turn left or right.
|
||||
act = new Common::Action("CHNGANGLE", _("Change Angle"));
|
||||
act->setCustomEngineActionEvent(kActionIncreaseAngle);
|
||||
act->addDefaultInputMapping("a");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
// I18N: STEP SIZE: Measures the size of one movement in the direction you are facing (1-250 standard distance units (SDUs))
|
||||
act = new Common::Action("CHNGSTEPSIZE", _("Change Step Size"));
|
||||
act->setCustomEngineActionEvent(kActionChangeStepSize);
|
||||
act->addDefaultInputMapping("s");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("TGGLHEIGHT", _("Toggle Height"));
|
||||
act->setCustomEngineActionEvent(kActionToggleRiseLower);
|
||||
act->addDefaultInputMapping("JOY_B");
|
||||
act->addDefaultInputMapping("h");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("REST", _("Rest"));
|
||||
act->setCustomEngineActionEvent(kActionRest);
|
||||
act->addDefaultInputMapping("JOY_Y");
|
||||
act->addDefaultInputMapping("r");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("FACEFRWARD", _("Face Forward"));
|
||||
act->setCustomEngineActionEvent(kActionFaceForward);
|
||||
act->addDefaultInputMapping("f");
|
||||
engineKeyMap->addAction(act);
|
||||
}
|
||||
|
||||
void EclipseEngine::gotoArea(uint16 areaID, int entranceID) {
|
||||
debugC(1, kFreescapeDebugMove, "Jumping to area: %d, entrance: %d", areaID, entranceID);
|
||||
|
||||
assert(_areaMap.contains(areaID));
|
||||
_currentArea = _areaMap[areaID];
|
||||
_currentArea->show();
|
||||
|
||||
_currentAreaMessages.clear();
|
||||
_currentAreaMessages.push_back(_currentArea->_name);
|
||||
|
||||
if (entranceID > 0)
|
||||
traverseEntrance(entranceID);
|
||||
else if (entranceID == -1)
|
||||
debugC(1, kFreescapeDebugMove, "Loading game, no change in position");
|
||||
else
|
||||
error("Invalid area change!");
|
||||
|
||||
_lastPosition = _position;
|
||||
|
||||
if (areaID == _startArea && entranceID == _startEntrance) {
|
||||
if (_pitch >= 180)
|
||||
_pitch = 360 - _pitch;
|
||||
playSound(_soundIndexStart, false, _soundFxHandle);
|
||||
if (isEclipse2()) {
|
||||
_gameStateControl = kFreescapeGameStateStart;
|
||||
_pitch = -10;
|
||||
}
|
||||
|
||||
} if (areaID == _endArea && entranceID == _endEntrance) {
|
||||
_flyMode = true;
|
||||
if (isDemo())
|
||||
_pitch = 20;
|
||||
else
|
||||
_pitch = 10;
|
||||
} else {
|
||||
playSound(_soundIndexAreaChange, false, _soundFxHandle);
|
||||
}
|
||||
|
||||
_gfx->_keyColor = 0;
|
||||
swapPalette(areaID);
|
||||
_currentArea->_usualBackgroundColor = isCPC() ? 1 : 0;
|
||||
if (isAmiga() || isAtariST())
|
||||
_currentArea->_skyColor = 15;
|
||||
|
||||
resetInput();
|
||||
}
|
||||
|
||||
void EclipseEngine::drawBackground() {
|
||||
clearBackground();
|
||||
_gfx->drawBackground(_currentArea->_skyColor);
|
||||
if (_currentArea && _currentArea->getAreaID() == 1) {
|
||||
if (ABS(_countdown) <= 15 * 60) // Last 15 minutes
|
||||
_gfx->drawBackground(5);
|
||||
if (ABS(_countdown) <= 10) // Last 10 seconds
|
||||
_gfx->drawBackground(1);
|
||||
|
||||
float progress = 0;
|
||||
if (_countdown >= 0 || getGameBit(16))
|
||||
progress = float(_countdown) / _initialCountdown;
|
||||
|
||||
uint8 color1 = 15;
|
||||
uint8 color2 = 10;
|
||||
|
||||
if (isSpectrum() || isCPC() || isC64()) {
|
||||
color1 = 2;
|
||||
color2 = 10;
|
||||
} else if (isAmiga() || isAtariST()) {
|
||||
color1 = 8;
|
||||
color2 = 14;
|
||||
}
|
||||
|
||||
_gfx->drawEclipse(color1, color2, progress);
|
||||
}
|
||||
}
|
||||
|
||||
void EclipseEngine::titleScreen() {
|
||||
if (isDOS())
|
||||
playSoundFx(2, true);
|
||||
FreescapeEngine::titleScreen();
|
||||
}
|
||||
|
||||
|
||||
void EclipseEngine::borderScreen() {
|
||||
if (_border) {
|
||||
drawBorder();
|
||||
if (isDemo() && isCPC()) {
|
||||
drawFullscreenMessageAndWait(_messagesList[23]);
|
||||
drawFullscreenMessageAndWait(_messagesList[24]);
|
||||
drawFullscreenMessageAndWait(_messagesList[25]);
|
||||
} else if (isDemo() && isSpectrum()) {
|
||||
if (_variant & GF_ZX_DEMO_MICROHOBBY) {
|
||||
drawFullscreenMessageAndWait(_messagesList[23]);
|
||||
} else if (_variant & GF_ZX_DEMO_CRASH) {
|
||||
drawFullscreenMessageAndWait(_messagesList[9]);
|
||||
drawFullscreenMessageAndWait(_messagesList[10]);
|
||||
drawFullscreenMessageAndWait(_messagesList[11]);
|
||||
}
|
||||
} else {
|
||||
FreescapeEngine::borderScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EclipseEngine::drawInfoMenu() {
|
||||
PauseToken pauseToken = pauseEngine();
|
||||
if (_savedScreen) {
|
||||
_savedScreen->free();
|
||||
delete _savedScreen;
|
||||
}
|
||||
_savedScreen = _gfx->getScreenshot();
|
||||
uint32 color = 0;
|
||||
switch (_renderMode) {
|
||||
case Common::kRenderCGA:
|
||||
color = 1;
|
||||
break;
|
||||
case Common::kRenderZX:
|
||||
color = 6;
|
||||
break;
|
||||
default:
|
||||
color = 14;
|
||||
}
|
||||
uint8 r, g, b;
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
|
||||
|
||||
Graphics::Surface *surface = new Graphics::Surface();
|
||||
surface->create(_screenW, _screenH, _gfx->_texturePixelFormat);
|
||||
|
||||
surface->fillRect(Common::Rect(88, 48, 231, 103), black);
|
||||
surface->frameRect(Common::Rect(88, 48, 231, 103), front);
|
||||
|
||||
surface->frameRect(Common::Rect(90, 50, 229, 101), front);
|
||||
|
||||
drawStringInSurface("L-LOAD S-SAVE", 105, 56, front, black, surface);
|
||||
if (isSpectrum())
|
||||
drawStringInSurface("1-TERMINATE", 105, 64, front, black, surface);
|
||||
else
|
||||
drawStringInSurface("ESC-TERMINATE", 105, 64, front, black, surface);
|
||||
|
||||
drawStringInSurface("T-TOGGLE", 128, 81, front, black, surface);
|
||||
drawStringInSurface("SOUND ON/OFF", 113, 88, front, black, surface);
|
||||
|
||||
Texture *menuTexture = _gfx->createTexture(surface);
|
||||
Common::Event event;
|
||||
bool cont = true;
|
||||
while (!shouldQuit() && cont) {
|
||||
while (_eventManager->pollEvent(event)) {
|
||||
|
||||
// Events
|
||||
switch (event.type) {
|
||||
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
|
||||
if (event.customType == kActionLoad) {
|
||||
_gfx->setViewport(_fullscreenViewArea);
|
||||
_eventManager->purgeKeyboardEvents();
|
||||
loadGameDialog();
|
||||
_gfx->setViewport(_viewArea);
|
||||
} else if (event.customType == kActionSave) {
|
||||
_gfx->setViewport(_fullscreenViewArea);
|
||||
_eventManager->purgeKeyboardEvents();
|
||||
saveGameDialog();
|
||||
_gfx->setViewport(_viewArea);
|
||||
} else if (isDOS() && event.customType == kActionToggleSound) {
|
||||
playSound(_soundIndexMenu, false, _soundFxHandle);
|
||||
} else if ((isDOS() || isCPC() || isSpectrum()) && event.customType == kActionEscape) {
|
||||
_forceEndGame = true;
|
||||
cont = false;
|
||||
} else
|
||||
cont = false;
|
||||
break;
|
||||
case Common::EVENT_KEYDOWN:
|
||||
cont = false;
|
||||
break;
|
||||
case Common::EVENT_SCREEN_CHANGED:
|
||||
_gfx->computeScreenViewport();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
drawFrame();
|
||||
_gfx->drawTexturedRect2D(_fullscreenViewArea, _fullscreenViewArea, menuTexture);
|
||||
|
||||
_gfx->flipBuffer();
|
||||
g_system->updateScreen();
|
||||
g_system->delayMillis(15); // try to target ~60 FPS
|
||||
}
|
||||
|
||||
_savedScreen->free();
|
||||
delete _savedScreen;
|
||||
_savedScreen = nullptr;
|
||||
surface->free();
|
||||
delete surface;
|
||||
delete menuTexture;
|
||||
pauseToken.clear();
|
||||
}
|
||||
|
||||
void EclipseEngine::pressedKey(const int keycode) {
|
||||
if (keycode == kActionIncreaseAngle) {
|
||||
changeAngle(1, true);
|
||||
} else if (keycode == kActionChangeStepSize) {
|
||||
changeStepSize();
|
||||
} else if (keycode == kActionToggleRiseLower) {
|
||||
if (_playerHeightNumber == 0)
|
||||
rise();
|
||||
else if (_playerHeightNumber == 1)
|
||||
lower();
|
||||
else
|
||||
error("Invalid player height index: %d", _playerHeightNumber);
|
||||
} else if (keycode == kActionRest) {
|
||||
if (_currentArea->getAreaID() == 1) {
|
||||
playSoundFx(3, false);
|
||||
if (_temporaryMessages.empty())
|
||||
insertTemporaryMessage(_messagesList[6], _countdown - 2);
|
||||
} else {
|
||||
_resting = true;
|
||||
if (_temporaryMessages.empty())
|
||||
insertTemporaryMessage(_messagesList[7], _countdown - 2);
|
||||
_countdown = _countdown - 5;
|
||||
}
|
||||
} else if (keycode == kActionFaceForward) {
|
||||
_pitch = 0;
|
||||
updateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
void EclipseEngine::releasedKey(const int keycode) {
|
||||
if (keycode == kActionRiseOrFlyUp)
|
||||
_resting = false;
|
||||
}
|
||||
|
||||
void EclipseEngine::drawAnalogClock(Graphics::Surface *surface, int x, int y, uint32 colorHand1, uint32 colorHand2, uint32 colorBack) {
|
||||
// These calls will cover the pixels of the hardcoded clock image
|
||||
drawAnalogClockHand(surface, x, y, 6 * 6 - 90, 12, colorBack);
|
||||
drawAnalogClockHand(surface, x, y, 7 * 6 - 90, 12, colorBack);
|
||||
drawAnalogClockHand(surface, x, y, 41 * 6 - 90, 11, colorBack);
|
||||
drawAnalogClockHand(surface, x, y, 42 * 6 - 90, 11, colorBack);
|
||||
drawAnalogClockHand(surface, x, y, 0 * 6 - 90, 11, colorBack);
|
||||
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
hours = 7 + 2 - hours; // It's 7 o-clock when the game starts
|
||||
minutes = 59 - minutes;
|
||||
seconds = 59 - seconds;
|
||||
drawAnalogClockHand(surface, x, y, hours * 30 - 90, 11, colorHand1);
|
||||
drawAnalogClockHand(surface, x, y, minutes * 6 - 90, 11, colorHand1);
|
||||
drawAnalogClockHand(surface, x, y, seconds * 6 - 90, 11, colorHand2);
|
||||
}
|
||||
|
||||
void EclipseEngine::drawAnalogClockHand(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, uint32 color) {
|
||||
const double degtorad = (M_PI * 2) / 360;
|
||||
double w = magnitude * cos(degrees * degtorad);
|
||||
double h = magnitude * sin(degrees * degtorad);
|
||||
surface->drawLine(x, y, x+(int)w, y+(int)h, color);
|
||||
if (isC64()) {
|
||||
surface->drawLine(x+1, y, x+1+(int)w, y+(int)h, color);
|
||||
}
|
||||
}
|
||||
|
||||
void EclipseEngine::drawCompass(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, uint32 color) {
|
||||
const double degtorad = (M_PI * 2) / 360;
|
||||
double w = magnitude * cos(-degrees * degtorad);
|
||||
double h = magnitude * sin(-degrees * degtorad);
|
||||
|
||||
int dx = 0;
|
||||
int dy = 0;
|
||||
|
||||
// Adjust dx and dy to make the compass look like a compass
|
||||
if (degrees == 0 || degrees == 360) {
|
||||
dx = 1;
|
||||
dy = 2;
|
||||
} else if (degrees > 0 && degrees < 90) {
|
||||
dx = 2;
|
||||
dy = 1;
|
||||
} else if (degrees == 90) {
|
||||
dx = 2;
|
||||
dy = 1;
|
||||
} else if (degrees > 90 && degrees < 180) {
|
||||
dx = 2;
|
||||
dy = -1;
|
||||
} else if (degrees == 180) {
|
||||
dx = 1;
|
||||
dy = 2;
|
||||
} else if (degrees > 180 && degrees < 270) {
|
||||
dx = -2;
|
||||
dy = -1;
|
||||
} else if (degrees == 270) {
|
||||
dx = 2;
|
||||
dy = 1;
|
||||
} else if (degrees > 270 && degrees < 360) {
|
||||
dx = -2;
|
||||
dy = 1;
|
||||
}
|
||||
|
||||
surface->drawLine(x, y, x+(int)w, y+(int)h, color);
|
||||
surface->drawLine(x - dx, y - dy, x+(int)w, y+(int)h, color);
|
||||
surface->drawLine(x + dx, y + dy, x+(int)w, y+(int)h, color);
|
||||
|
||||
surface->drawLine(x - dx, y - dy, x+(int)-w, y+(int)-h, color);
|
||||
surface->drawLine(x + dx, y + dy, x+(int)-w, y+(int)-h, color);
|
||||
}
|
||||
|
||||
// Copied from BITMAP::circlefill in engines/ags/lib/allegro/surface.cpp
|
||||
void fillCircle(Graphics::Surface *surface, int x, int y, int radius, int color) {
|
||||
int cx = 0;
|
||||
int cy = radius;
|
||||
int df = 1 - radius;
|
||||
int d_e = 3;
|
||||
int d_se = -2 * radius + 5;
|
||||
|
||||
do {
|
||||
surface->hLine(x - cy, y - cx, x + cy, color);
|
||||
|
||||
if (cx)
|
||||
surface->hLine(x - cy, y + cx, x + cy, color);
|
||||
|
||||
if (df < 0) {
|
||||
df += d_e;
|
||||
d_e += 2;
|
||||
d_se += 2;
|
||||
} else {
|
||||
if (cx != cy) {
|
||||
surface->hLine(x - cx, y - cy, x + cx, color);
|
||||
|
||||
if (cy)
|
||||
surface->hLine(x - cx, y + cy, x + cx, color);
|
||||
}
|
||||
|
||||
df += d_se;
|
||||
d_e += 2;
|
||||
d_se += 4;
|
||||
cy--;
|
||||
}
|
||||
|
||||
cx++;
|
||||
|
||||
} while (cx <= cy);
|
||||
}
|
||||
|
||||
void EclipseEngine::drawEclipseIndicator(Graphics::Surface *surface, int x, int y, uint32 color1, uint32 color2) {
|
||||
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
|
||||
|
||||
// These calls will cover the pixels of the hardcoded eclipse image
|
||||
surface->fillRect(Common::Rect(x, y, x + 50, y + 20), black);
|
||||
|
||||
float progress = 0;
|
||||
if (_countdown >= 0)
|
||||
progress = float(_countdown) / _initialCountdown;
|
||||
|
||||
int difference = 14 * progress;
|
||||
|
||||
fillCircle(surface, x + 7, y + 10, 7, color1); // Sun
|
||||
fillCircle(surface, x + 7 + difference, y + 10, 7, color2); // Moon
|
||||
}
|
||||
|
||||
void EclipseEngine::drawIndicator(Graphics::Surface *surface, int xPosition, int yPosition, int separation) {
|
||||
if (_indicators.size() == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (isSpectrum() || isC64()) {
|
||||
if (_gameStateVars[kVariableEclipseAnkhs] <= i)
|
||||
continue;
|
||||
} else if (_gameStateVars[kVariableEclipseAnkhs] > i)
|
||||
continue;
|
||||
surface->copyRectToSurface(*_indicators[0], xPosition + separation * i, yPosition, Common::Rect(_indicators[0]->w, _indicators[0]->h));
|
||||
}
|
||||
}
|
||||
|
||||
void EclipseEngine::drawSensorShoot(Sensor *sensor) {
|
||||
Math::Vector3d target;
|
||||
float distance = 5;
|
||||
int axisToSkip = -1;
|
||||
|
||||
if (sensor->_axis == 0x1 || sensor->_axis == 0x2)
|
||||
axisToSkip = 0;
|
||||
|
||||
if (sensor->_axis == 0x10 || sensor->_axis == 0x20)
|
||||
axisToSkip = 2;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (i == j) {
|
||||
target = sensor->getOrigin();
|
||||
if (i != axisToSkip)
|
||||
target.setValue(i, target.getValue(i) + distance);
|
||||
|
||||
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
|
||||
|
||||
target = sensor->getOrigin();
|
||||
|
||||
if (i != axisToSkip)
|
||||
target.setValue(i, target.getValue(i) - distance);
|
||||
|
||||
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
|
||||
} else {
|
||||
target = sensor->getOrigin();
|
||||
if (i != axisToSkip)
|
||||
target.setValue(i, target.getValue(i) + distance);
|
||||
|
||||
if (j != axisToSkip)
|
||||
target.setValue(j, target.getValue(j) + distance);
|
||||
|
||||
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
|
||||
|
||||
target = sensor->getOrigin();
|
||||
if (i != axisToSkip)
|
||||
target.setValue(i, target.getValue(i) + distance);
|
||||
|
||||
if (j != axisToSkip)
|
||||
target.setValue(j, target.getValue(j) - distance);
|
||||
|
||||
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
|
||||
|
||||
target = sensor->getOrigin();
|
||||
|
||||
if (i != axisToSkip)
|
||||
target.setValue(i, target.getValue(i) - distance);
|
||||
|
||||
if (j != axisToSkip)
|
||||
target.setValue(j, target.getValue(j) - distance);
|
||||
|
||||
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
|
||||
|
||||
target = sensor->getOrigin();
|
||||
if (i != axisToSkip)
|
||||
target.setValue(i, target.getValue(i) - distance);
|
||||
|
||||
if (j != axisToSkip)
|
||||
target.setValue(j, target.getValue(j) + distance);
|
||||
|
||||
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EclipseEngine::drawScoreString(int score, int x, int y, uint32 front, uint32 back, Graphics::Surface *surface) {
|
||||
Common::String scoreStr = Common::String::format("%07d", score);
|
||||
|
||||
if (isDOS() || isCPC() || isSpectrum()) {
|
||||
scoreStr = shiftStr(scoreStr, 'Z' - '0' + 1);
|
||||
if (_renderMode == Common::RenderMode::kRenderEGA || isSpectrum()) {
|
||||
drawStringInSurface(scoreStr, x, y, front, back, surface);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Start in x,y and draw each digit, from left to right, adding a gap every 3 digits
|
||||
int gapSize = isC64() ? 8 : 4;
|
||||
|
||||
for (int i = 0; i < int(scoreStr.size()); i++) {
|
||||
drawStringInSurface(Common::String(scoreStr[i]), x, y, front, back, surface);
|
||||
x += 8;
|
||||
if ((i - scoreStr.size() + 1) % 3 == 1)
|
||||
x += gapSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void EclipseEngine::updateTimeVariables() {
|
||||
if (isEclipse2() && _gameStateControl == kFreescapeGameStateStart) {
|
||||
executeLocalGlobalConditions(false, true, false);
|
||||
_gameStateControl = kFreescapeGameStatePlaying;
|
||||
}
|
||||
|
||||
if (_gameStateControl != kFreescapeGameStatePlaying)
|
||||
return;
|
||||
// This function only executes "on collision" room/global conditions
|
||||
int seconds, minutes, hours;
|
||||
getTimeFromCountdown(seconds, minutes, hours);
|
||||
|
||||
|
||||
if (_lastFiveSeconds != seconds / 5) {
|
||||
_lastFiveSeconds = seconds / 5;
|
||||
executeLocalGlobalConditions(false, false, true);
|
||||
}
|
||||
|
||||
if (_lastThirtySeconds != seconds / 30) {
|
||||
_lastThirtySeconds = seconds / 30;
|
||||
|
||||
if (!_resting && _gameStateVars[k8bitVariableEnergy] > 0) {
|
||||
_gameStateVars[k8bitVariableEnergy] -= 1;
|
||||
}
|
||||
|
||||
if (_gameStateVars[k8bitVariableShield] < _maxShield) {
|
||||
_gameStateVars[k8bitVariableShield] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (isEclipse() && isSpectrum() && _currentArea->getAreaID() == 42) {
|
||||
if (_lastSecond != seconds) { // Swap ink and paper colors every second
|
||||
_lastSecond = seconds;
|
||||
int tmp = _gfx->_inkColor;
|
||||
_gfx->_inkColor = _gfx->_paperColor;
|
||||
_gfx->_paperColor = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EclipseEngine::executePrint(FCLInstruction &instruction) {
|
||||
uint16 index = instruction._source - 1;
|
||||
debugC(1, kFreescapeDebugCode, "Printing message %d", index);
|
||||
if (index > 127) {
|
||||
index = _messagesList.size() - (index - 254) - 2;
|
||||
drawFullscreenMessageAndWait(_messagesList[index]);
|
||||
return;
|
||||
}
|
||||
insertTemporaryMessage(_messagesList[index], _countdown - 2);
|
||||
}
|
||||
|
||||
Common::Error EclipseEngine::saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave) {
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
Common::Error EclipseEngine::loadGameStreamExtended(Common::SeekableReadStream *stream) {
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
108
engines/freescape/games/eclipse/eclipse.h
Normal file
108
engines/freescape/games/eclipse/eclipse.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/sound.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
enum EclipseReleaseFlags {
|
||||
GF_ZX_DEMO_CRASH = (1 << 0),
|
||||
GF_ZX_DEMO_MICROHOBBY = (1 << 1),
|
||||
};
|
||||
|
||||
enum {
|
||||
kVariableEclipseAnkhs = 32,
|
||||
};
|
||||
|
||||
class EclipseEngine : public FreescapeEngine {
|
||||
public:
|
||||
EclipseEngine(OSystem *syst, const ADGameDescription *gd);
|
||||
|
||||
void gotoArea(uint16 areaID, int entranceID) override;
|
||||
|
||||
void borderScreen() override;
|
||||
void titleScreen() override;
|
||||
void drawInfoMenu() override;
|
||||
void drawIndicator(Graphics::Surface *surface, int xPosition, int yPosition, int separation);
|
||||
|
||||
void drawSensorShoot(Sensor *sensor) override;
|
||||
|
||||
void loadAssets() override;
|
||||
void loadAssetsDOSFullGame() override;
|
||||
void pressedKey(const int keycode) override;
|
||||
void releasedKey(const int keycode) override;
|
||||
|
||||
uint32 _initialEnergy;
|
||||
uint32 _initialShield;
|
||||
|
||||
int _soundIndexStartFalling;
|
||||
int _soundIndexEndFalling;
|
||||
|
||||
bool _resting;
|
||||
int _lastThirtySeconds;
|
||||
int _lastFiveSeconds;
|
||||
|
||||
int _lastSecond;
|
||||
void updateTimeVariables() override;
|
||||
|
||||
void initDOS();
|
||||
void initCPC();
|
||||
void initZX();
|
||||
void initC64();
|
||||
void initAmigaAtari();
|
||||
|
||||
void loadAssetsZXFullGame() override;
|
||||
void loadAssetsCPCFullGame() override;
|
||||
void loadAssetsC64FullGame() override;
|
||||
void loadAssetsAtariFullGame() override;
|
||||
void loadAssetsCPCDemo() override;
|
||||
void loadAssetsZXDemo() override;
|
||||
|
||||
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
|
||||
void initGameState() override;
|
||||
void executePrint(FCLInstruction &instruction) override;
|
||||
|
||||
void drawBackground() override;
|
||||
void drawDOSUI(Graphics::Surface *surface) override;
|
||||
void drawCPCUI(Graphics::Surface *surface) override;
|
||||
void drawC64UI(Graphics::Surface *surface) override;
|
||||
void drawZXUI(Graphics::Surface *surface) override;
|
||||
void drawAnalogClock(Graphics::Surface *surface, int x, int y, uint32 colorHand1, uint32 colorHand2, uint32 colorBack);
|
||||
void drawAnalogClockHand(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, uint32 color);
|
||||
void drawCompass(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, uint32 color);
|
||||
void drawEclipseIndicator(Graphics::Surface *surface, int x, int y, uint32 color1, uint32 color2);
|
||||
Common::String getScoreString(int score);
|
||||
void drawScoreString(int score, int x, int y, uint32 front, uint32 back, Graphics::Surface *surface);
|
||||
|
||||
soundFx *load1bPCM(Common::SeekableReadStream *file, int offset);
|
||||
|
||||
bool checkIfGameEnded() override;
|
||||
void endGame() override;
|
||||
void loadSoundsFx(Common::SeekableReadStream *file, int offset, int number) override;
|
||||
void playSoundFx(int index, bool sync) override;
|
||||
|
||||
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
|
||||
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
|
||||
};
|
||||
|
||||
}
|
||||
220
engines/freescape/games/eclipse/zx.cpp
Normal file
220
engines/freescape/games/eclipse/zx.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
/* 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 "common/file.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/eclipse/eclipse.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void EclipseEngine::initZX() {
|
||||
_viewArea = Common::Rect(56, 36, 265, 139);
|
||||
_maxEnergy = 25;
|
||||
_maxShield = 50;
|
||||
|
||||
_soundIndexShoot = 5;
|
||||
_soundIndexCollide = -1; // Scripted
|
||||
_soundIndexStepDown = 12;
|
||||
_soundIndexStepUp = 12;
|
||||
_soundIndexMenu = -1;
|
||||
_soundIndexStart = 7;
|
||||
_soundIndexAreaChange = 7;
|
||||
|
||||
_soundIndexStartFalling = 6;
|
||||
_soundIndexEndFalling = 5;
|
||||
|
||||
_soundIndexNoShield = 8;
|
||||
_soundIndexNoEnergy = -1;
|
||||
_soundIndexFallen = 8;
|
||||
_soundIndexTimeout = 8;
|
||||
_soundIndexForceEndGame = 8;
|
||||
_soundIndexCrushed = 8;
|
||||
_soundIndexMissionComplete = 16;
|
||||
}
|
||||
|
||||
void EclipseEngine::loadAssetsZXFullGame() {
|
||||
Common::File file;
|
||||
|
||||
file.open("totaleclipse.zx.title");
|
||||
if (file.isOpen()) {
|
||||
_title = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find totaleclipse.zx.title");
|
||||
|
||||
file.close();
|
||||
file.open("totaleclipse.zx.border");
|
||||
if (file.isOpen()) {
|
||||
_border = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find totaleclipse.zx.border");
|
||||
file.close();
|
||||
|
||||
file.open("totaleclipse.zx.data");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open totaleclipse.zx.data");
|
||||
|
||||
if (isEclipse2()) {
|
||||
loadMessagesFixedSize(&file, 0x2ac, 16, 30);
|
||||
loadFonts(&file, 0x61c3);
|
||||
loadSpeakerFxZX(&file, 0x8c6, 0x91a);
|
||||
load8bitBinary(&file, 0x63bb, 4);
|
||||
} else {
|
||||
loadMessagesFixedSize(&file, 0x2ac, 16, 23);
|
||||
loadFonts(&file, 0x6163);
|
||||
loadSpeakerFxZX(&file, 0x816, 0x86a);
|
||||
load8bitBinary(&file, 0x635b, 4);
|
||||
|
||||
// These paper colors are also invalid, but to signal the use of a special effect (only in zx release)
|
||||
_areaMap[42]->_paperColor = 0;
|
||||
_areaMap[42]->_underFireBackgroundColor = 0;
|
||||
}
|
||||
|
||||
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void EclipseEngine::loadAssetsZXDemo() {
|
||||
Common::File file;
|
||||
|
||||
file.open("totaleclipse.zx.title");
|
||||
if (file.isOpen()) {
|
||||
_title = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find totaleclipse.zx.title");
|
||||
|
||||
file.close();
|
||||
file.open("totaleclipse.zx.border");
|
||||
if (file.isOpen()) {
|
||||
_border = loadAndConvertScrImage(&file);
|
||||
} else
|
||||
error("Unable to find totaleclipse.zx.border");
|
||||
file.close();
|
||||
|
||||
file.open("totaleclipse.zx.data");
|
||||
if (!file.isOpen())
|
||||
error("Failed to open totaleclipse.zx.data");
|
||||
|
||||
if (_variant & GF_ZX_DEMO_MICROHOBBY) {
|
||||
loadSpeakerFxZX(&file, 0x798, 0x7ec);
|
||||
loadMessagesFixedSize(&file, 0x2ac, 16, 23);
|
||||
loadMessagesFixedSize(&file, 0x56e6, 264, 1);
|
||||
loadFonts(&file, 0x5f7b);
|
||||
load8bitBinary(&file, 0x6173, 4);
|
||||
} else if (_variant & GF_ZX_DEMO_CRASH) {
|
||||
loadSpeakerFxZX(&file, 0x65c, 0x6b0);
|
||||
loadMessagesFixedSize(&file, 0x364, 16, 9);
|
||||
loadMessagesFixedSize(&file, 0x5901, 264, 5);
|
||||
loadFonts(&file, 0x6589);
|
||||
load8bitBinary(&file, 0x6781, 4);
|
||||
} else
|
||||
error("Unknown ZX Spectrum demo variant");
|
||||
|
||||
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
|
||||
|
||||
for (auto &it : _indicators)
|
||||
it->convertToInPlace(_gfx->_texturePixelFormat);
|
||||
}
|
||||
|
||||
void EclipseEngine::drawZXUI(Graphics::Surface *surface) {
|
||||
uint32 color = _currentArea->_underFireBackgroundColor;
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
color = _currentArea->_usualBackgroundColor;
|
||||
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
|
||||
color = (*_gfx->_colorRemaps)[color];
|
||||
}
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(7, r, g, b);
|
||||
uint32 gray = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(5, r, g, b);
|
||||
uint32 blue = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
_gfx->readFromPalette(2, r, g, b);
|
||||
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
|
||||
int score = _gameStateVars[k8bitVariableScore];
|
||||
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
|
||||
int energy = _gameStateVars[k8bitVariableEnergy];
|
||||
shield = shield < 0 ? 0 : shield;
|
||||
|
||||
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0);
|
||||
|
||||
Common::String message;
|
||||
int deadline;
|
||||
getLatestMessages(message, deadline);
|
||||
if (deadline <= _countdown) {
|
||||
drawStringInSurface(message, 102, 141, back, yellow, surface);
|
||||
_temporaryMessages.push_back(message);
|
||||
_temporaryMessageDeadlines.push_back(deadline);
|
||||
} else if (!_currentAreaMessages.empty())
|
||||
drawStringInSurface(_currentArea->_name, 102, 141, back, yellow, surface);
|
||||
|
||||
drawScoreString(score, 135, 11, back, gray, surface);
|
||||
|
||||
Common::String shieldStr = Common::String::format("%d", shield);
|
||||
|
||||
int x = 171;
|
||||
if (shield < 10)
|
||||
x = 179;
|
||||
else if (shield < 100)
|
||||
x = 175;
|
||||
|
||||
if (energy < 0)
|
||||
energy = 0;
|
||||
|
||||
drawStringInSurface(shieldStr, x, 161, back, red, surface);
|
||||
|
||||
Common::Rect jarBackground(120, 162, 144, 192 - 4);
|
||||
surface->fillRect(jarBackground, back);
|
||||
|
||||
Common::Rect jarWater(120, 192 - energy - 4, 144, 192 - 4);
|
||||
surface->fillRect(jarWater, blue);
|
||||
|
||||
drawStringInSurface(shiftStr("0", 'Z' - '$' + 1 - _angleRotationIndex), 79, 141, back, yellow, surface);
|
||||
drawStringInSurface(shiftStr("3", 'Z' - '$' + 1 - _playerStepIndex), 63, 141, back, yellow, surface);
|
||||
drawStringInSurface(shiftStr("7", 'Z' - '$' + 1 - _playerHeightNumber), 240, 141, back, yellow, surface);
|
||||
|
||||
if (_shootingFrames > 0) {
|
||||
drawStringInSurface(shiftStr("4", 'Z' - '$' + 1), 232, 141, back, yellow, surface);
|
||||
drawStringInSurface(shiftStr("<", 'Z' - '$' + 1) , 240, 141, back, yellow, surface);
|
||||
}
|
||||
drawAnalogClock(surface, 89, 172, back, back, gray);
|
||||
|
||||
surface->fillRect(Common::Rect(227, 168, 235, 187), gray);
|
||||
drawCompass(surface, 231, 177, _yaw, 10, back);
|
||||
|
||||
drawIndicator(surface, 65, 7, 8);
|
||||
drawEclipseIndicator(surface, 215, 3, front, gray);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
265
engines/freescape/games/palettes.cpp
Normal file
265
engines/freescape/games/palettes.cpp
Normal file
@@ -0,0 +1,265 @@
|
||||
/* 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/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
byte kEGADefaultPalette[16][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0xaa},
|
||||
{0x00, 0xaa, 0x00},
|
||||
{0x00, 0xaa, 0xaa},
|
||||
{0xaa, 0x00, 0x00},
|
||||
{0xaa, 0x00, 0xaa},
|
||||
{0xaa, 0x55, 0x00},
|
||||
{0xaa, 0xaa, 0xaa},
|
||||
{0x55, 0x55, 0x55},
|
||||
{0x55, 0x55, 0xff},
|
||||
{0x55, 0xff, 0x55},
|
||||
{0x55, 0xff, 0xff},
|
||||
{0xff, 0x55, 0x55},
|
||||
{0xff, 0x55, 0xff},
|
||||
{0xff, 0xff, 0x55},
|
||||
{0xff, 0xff, 0xff}
|
||||
};
|
||||
|
||||
byte kCGAPalettePinkBlue[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0xaa, 0xaa},
|
||||
{0xaa, 0x00, 0xaa},
|
||||
{0xaa, 0xaa, 0xaa},
|
||||
};
|
||||
|
||||
byte kCGAPaletteRedGreen[4][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0xaa, 0x00},
|
||||
{0xaa, 0x00, 0x00},
|
||||
{0xaa, 0x55, 0x00},
|
||||
};
|
||||
|
||||
byte kHerculesPaletteGreen[2][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0xff, 0x00},
|
||||
};
|
||||
|
||||
byte kC64Palette[16][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF},
|
||||
{0x68, 0x37, 0x2B},
|
||||
{0x70, 0xA4, 0xB2},
|
||||
{0x6F, 0x3D, 0x86},
|
||||
{0x58, 0x8D, 0x43},
|
||||
{0x35, 0x28, 0x79},
|
||||
{0xB8, 0xC7, 0x6F},
|
||||
{0x6F, 0x4F, 0x25},
|
||||
{0x43, 0x39, 0x00},
|
||||
{0x9A, 0x67, 0x59},
|
||||
{0x44, 0x44, 0x44},
|
||||
{0x6C, 0x6C, 0x6C},
|
||||
{0x9A, 0xD2, 0x84},
|
||||
{0x6C, 0x5E, 0xB5},
|
||||
{0x95, 0x95, 0x95}
|
||||
};
|
||||
|
||||
byte kDrillerZXPalette[9][3] = {
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0xd8},
|
||||
{0xd8, 0x00, 0x00},
|
||||
{0xd8, 0x00, 0xd8},
|
||||
{0x00, 0xd8, 0x00},
|
||||
{0x00, 0xd8, 0xd8},
|
||||
{0xd8, 0xd8, 0x00},
|
||||
{0xd8, 0xd8, 0xd8},
|
||||
{0x00, 0x00, 0x00},
|
||||
};
|
||||
|
||||
byte kDrillerCPCPalette[32][3] = {
|
||||
{0x80, 0x80, 0x80}, // 0: special case?
|
||||
{0x00, 0x00, 0x00}, // 1: used in dark only?
|
||||
{0x00, 0x80, 0xff}, // 2
|
||||
{0xff, 0xff, 0x80}, // 3
|
||||
{0x00, 0x00, 0x80}, // 4
|
||||
{0xff, 0x00, 0x80}, // 5
|
||||
{0x00, 0x80, 0x80}, // 6
|
||||
{0xff, 0x80, 0x80}, // 7
|
||||
{0x80, 0x00, 0xff}, // 8
|
||||
{0x00, 0x80, 0x00}, // 9
|
||||
{0xff, 0xff, 0x00}, // 10
|
||||
{0xff, 0xff, 0xff}, // 11
|
||||
{0xff, 0x00, 0x00}, // 12
|
||||
{0x11, 0x22, 0x33},
|
||||
{0xff, 0x80, 0x00}, // 14
|
||||
{0xff, 0x80, 0xff}, // 15
|
||||
{0x11, 0x22, 0x33},
|
||||
{0x00, 0xff, 0x80}, // 17
|
||||
{0x00, 0xff, 0x00}, // 18
|
||||
{0x80, 0xff, 0xff}, // 19
|
||||
{0x80, 0x80, 0x80}, // 20
|
||||
{0x00, 0x00, 0xff}, // 21
|
||||
{0x00, 0x80, 0x00}, // 22
|
||||
{0x00, 0x80, 0xff}, // 23
|
||||
{0x80, 0x00, 0x80}, // 24
|
||||
{0x80, 0xff, 0x80}, // 25
|
||||
{0x80, 0xff, 0x00}, // 26
|
||||
{0x00, 0xff, 0xff}, // 27
|
||||
{0x80, 0x00, 0x00}, // 28
|
||||
{0x80, 0x00, 0xff}, // 29
|
||||
{0x80, 0x80, 0x00}, // 30
|
||||
{0x80, 0x80, 0xff}, // 31
|
||||
};
|
||||
|
||||
void FreescapeEngine::loadColorPalette() {
|
||||
if (_renderMode == Common::kRenderEGA) {
|
||||
_gfx->_palette = (byte *)&kEGADefaultPalette;
|
||||
} else if (_renderMode == Common::kRenderC64) {
|
||||
_gfx->_palette = (byte *)&kC64Palette;
|
||||
} else if (_renderMode == Common::kRenderZX) {
|
||||
_gfx->_palette = (byte *)kDrillerZXPalette;
|
||||
} else if (_renderMode == Common::kRenderCPC) {
|
||||
_gfx->_palette = (byte *)kDrillerCPCPalette;
|
||||
} else if (_renderMode == Common::kRenderHercG) {
|
||||
_gfx->_palette = (byte *)&kHerculesPaletteGreen;
|
||||
} else if (_renderMode == Common::kRenderCGA) {
|
||||
// palette depends on the area
|
||||
} else if (_renderMode == Common::kRenderAmiga || _renderMode == Common::kRenderAtariST) {
|
||||
// palette depends on the area
|
||||
} else
|
||||
error("Invalid render mode, no palette selected");
|
||||
|
||||
_gfx->setColorMap(&_colorMap);
|
||||
}
|
||||
|
||||
byte *FreescapeEngine::loadPalette(Common::SeekableReadStream *file) {
|
||||
int r, g, b;
|
||||
auto palette = new byte[16][3];
|
||||
for (int c = 0; c < 16; c++) {
|
||||
int v = file->readUint16BE();
|
||||
r = (v & 0xf00) >> 8;
|
||||
r = r << 4 | r;
|
||||
palette[c][0] = r & 0xff;
|
||||
g = (v & 0xf0) >> 4;
|
||||
g = g << 4 | g;
|
||||
palette[c][1] = g & 0xff;
|
||||
b = v & 0xf;
|
||||
b = b << 4 | b;
|
||||
palette[c][2] = b & 0xff;
|
||||
debugC(1, kFreescapeDebugParser, "Color %d: (%04x) %02x %02x %02x", c, v, palette[c][0], palette[c][1], palette[c][2]);
|
||||
}
|
||||
return (byte *)palette;
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadPalettes(Common::SeekableReadStream *file, int offset) {
|
||||
file->seek(offset);
|
||||
int r, g, b;
|
||||
uint numberOfAreas = _areaMap.size();
|
||||
|
||||
// This loop will load all the available palettes, which are more
|
||||
// than the current areas. This indicates that more areas
|
||||
// were originally planned, but they are not in the final game
|
||||
if (isDriller())
|
||||
numberOfAreas += 2;
|
||||
else if (isDark())
|
||||
numberOfAreas += 5;
|
||||
else if (isCastle())
|
||||
numberOfAreas += 20;
|
||||
|
||||
for (uint i = 0; i < numberOfAreas; i++) {
|
||||
int label = readField(file, 8);
|
||||
if (label == 255)
|
||||
break;
|
||||
auto palette = new byte[16][3];
|
||||
debugC(1, kFreescapeDebugParser, "Loading palette for area: %d at %" PRIx64, label, file->pos());
|
||||
for (int c = 0; c < 16; c++) {
|
||||
int v = file->readUint16BE();
|
||||
r = (v & 0xf00) >> 8;
|
||||
r = r << 4 | r;
|
||||
palette[c][0] = r & 0xff;
|
||||
g = (v & 0xf0) >> 4;
|
||||
g = g << 4 | g;
|
||||
palette[c][1] = g & 0xff;
|
||||
b = v & 0xf;
|
||||
b = b << 4 | b;
|
||||
palette[c][2] = b & 0xff;
|
||||
debugC(1, kFreescapeDebugParser, "Color %d: (%04x) %02x %02x %02x", c, v, palette[c][0], palette[c][1], palette[c][2]);
|
||||
}
|
||||
assert(!_paletteByArea.contains(label));
|
||||
_paletteByArea[label] = (byte *)palette;
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::swapPalette(uint16 levelID) {
|
||||
if (isAmiga() || isAtariST()) {
|
||||
// The following palette was not available in the demo, so we select another one
|
||||
if (isDriller() && isDemo() && levelID == 32)
|
||||
levelID = 31;
|
||||
|
||||
_gfx->_palette = _paletteByArea[levelID];
|
||||
} else if (isSpectrum() || isCPC() || isC64()) {
|
||||
_gfx->_inkColor = _areaMap[levelID]->_inkColor;
|
||||
_gfx->_paperColor = _areaMap[levelID]->_paperColor;
|
||||
_gfx->_underFireBackgroundColor = _areaMap[levelID]->_underFireBackgroundColor;
|
||||
|
||||
if (isC64()) {
|
||||
_gfx->_inkColor %= 16;
|
||||
_gfx->_paperColor %= 16;
|
||||
_gfx->_underFireBackgroundColor %= 16;
|
||||
return; // C64 does not have to process the border
|
||||
}
|
||||
|
||||
if (!_border)
|
||||
return;
|
||||
|
||||
byte *palette = (byte *)malloc(sizeof(byte) * 4 * 3);
|
||||
for (int c = 0; c < 4; c++) {
|
||||
byte r, g, b;
|
||||
_gfx->selectColorFromFourColorPalette(c, r, g, b);
|
||||
palette[3 * c + 0] = r;
|
||||
palette[3 * c + 1] = g;
|
||||
palette[3 * c + 2] = b;
|
||||
}
|
||||
_border->setPalette(palette, 0, 4);
|
||||
free(palette);
|
||||
processBorder();
|
||||
} else if (isDOS() && _renderMode == Common::kRenderCGA) {
|
||||
_gfx->_palette = findCGAPalette(levelID);
|
||||
if (!_border)
|
||||
return;
|
||||
_border->setPalette(_gfx->_palette, 0, 4);
|
||||
processBorder();
|
||||
} else if (isDOS() && _renderMode == Common::kRenderEGA) {
|
||||
if (!_border)
|
||||
return;
|
||||
|
||||
_border->setPalette(_gfx->_palette, 0, 4);
|
||||
processBorder();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
byte *FreescapeEngine::findCGAPalette(uint16 levelID) {
|
||||
if (levelID % 2 == 0)
|
||||
return (byte *)&kCGAPalettePinkBlue;
|
||||
else
|
||||
return (byte *)&kCGAPaletteRedGreen;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
1284
engines/freescape/gfx.cpp
Normal file
1284
engines/freescape/gfx.cpp
Normal file
File diff suppressed because it is too large
Load Diff
311
engines/freescape/gfx.h
Normal file
311
engines/freescape/gfx.h
Normal file
@@ -0,0 +1,311 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_GFX_H
|
||||
#define FREESCAPE_GFX_H
|
||||
|
||||
#include "common/hashmap.h"
|
||||
#include "common/rendermode.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
#include "graphics/pixelformat.h"
|
||||
#include "graphics/managed_surface.h"
|
||||
#include "graphics/renderer.h"
|
||||
#include "math/frustum.h"
|
||||
#include "math/vector3d.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
#define kVertexArraySize 128
|
||||
#define kCoordsArraySize 4
|
||||
|
||||
typedef Common::Array<byte *> ColorMap;
|
||||
typedef Common::HashMap<int, int> ColorReMap;
|
||||
|
||||
class Renderer;
|
||||
|
||||
const Graphics::PixelFormat getRGBAPixelFormat();
|
||||
|
||||
class Texture {
|
||||
public:
|
||||
Texture(){ _width = 0; _height = 0; };
|
||||
virtual ~Texture(){};
|
||||
|
||||
uint _width;
|
||||
uint _height;
|
||||
Graphics::PixelFormat _format;
|
||||
|
||||
virtual void update(const Graphics::Surface *surface) = 0;
|
||||
virtual void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) = 0;
|
||||
};
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
|
||||
virtual ~Renderer();
|
||||
|
||||
Graphics::PixelFormat _texturePixelFormat;
|
||||
bool _isAccelerated;
|
||||
bool _authenticGraphics;
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void setViewport(const Common::Rect &rect) = 0;
|
||||
|
||||
/**
|
||||
* Swap the buffers, making the drawn screen visible
|
||||
*/
|
||||
virtual void flipBuffer() {}
|
||||
virtual void useColor(uint8 r, uint8 g, uint8 b) = 0;
|
||||
virtual void depthTesting(bool enabled) {};
|
||||
virtual void polygonOffset(bool enabled) = 0;
|
||||
|
||||
virtual Texture *createTexture(const Graphics::Surface *surface, bool is3D = false) = 0;
|
||||
Graphics::Surface *convertImageFormatIfNecessary(Graphics::ManagedSurface *surface);
|
||||
|
||||
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 sensor, const Math::Vector3d player, const Common::Rect &viewPort) = 0;
|
||||
virtual void renderPlayerShootBall(byte color, const Common::Point &position, int frame, const Common::Rect &viewPort) = 0;
|
||||
virtual void renderPlayerShootRay(byte color, const Common::Point &position, const Common::Rect &viewPort) = 0;
|
||||
|
||||
virtual void renderCrossair(const Common::Point &crossairPosition) = 0;
|
||||
|
||||
virtual void renderCube(const Math::Vector3d &position, const Math::Vector3d &size, Common::Array<uint8> *colours, Common::Array<uint8> *ecolours, float offset = 0.0);
|
||||
virtual void renderRectangle(const Math::Vector3d &position, const Math::Vector3d &size, Common::Array<uint8> *colours, Common::Array<uint8> *ecolours, float offset = 0.0);
|
||||
virtual void renderPolygon(const Math::Vector3d &origin, const Math::Vector3d &size, const Common::Array<float> *ordinates, Common::Array<uint8> *colours, Common::Array<uint8> *ecolours, float offset = 0.0);
|
||||
virtual void renderPyramid(const Math::Vector3d &origin, const Math::Vector3d &size, const Common::Array<float> *ordinates, Common::Array<uint8> *colours, Common::Array<uint8> *ecolours, int type);
|
||||
virtual void renderFace(const Common::Array<Math::Vector3d> &vertices) = 0;
|
||||
|
||||
void setColorRemaps(ColorReMap *colorRemaps);
|
||||
virtual void clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport = false) = 0;
|
||||
virtual void drawFloor(uint8 color) = 0;
|
||||
virtual void drawBackground(uint8 color);
|
||||
|
||||
void drawEclipse(uint8 color1, uint8 color2, float difference);
|
||||
virtual void drawSkybox(Texture *texture, Math::Vector3d camera) {};
|
||||
virtual void drawThunder(Texture *texture, Math::Vector3d camera, float size) {};
|
||||
virtual void drawCelestialBody(Math::Vector3d position, float radius, uint8 color) {};
|
||||
|
||||
Common::Rect viewport() const;
|
||||
virtual Common::Point nativeResolution() { return Common::Point(_screenW, _screenH); }
|
||||
|
||||
// palette
|
||||
void readFromPalette(uint8 index, uint8 &r, uint8 &g, uint8 &b);
|
||||
void setPaletteValue(uint8 index, uint8 r, uint8 g, uint8 b);
|
||||
uint8 indexFromColor(uint8 r, uint8 g, uint8 b);
|
||||
uint8 mapEGAColor(uint8 index);
|
||||
|
||||
bool getRGBAt(uint8 index, uint8 ecolor, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
|
||||
bool getRGBAtC64(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
|
||||
bool getRGBAtCGA(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
|
||||
bool getRGBAtCPC(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
|
||||
bool getRGBAtEGA(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2);
|
||||
bool getRGBAtZX(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
|
||||
bool getRGBAtHercules(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
|
||||
void extractCPCIndexes(uint8 cm1, uint8 cm2, uint8 &i1, uint8 &i2);
|
||||
void extractC64Indexes(uint8 cm1, uint8 cm2, uint8 &i1, uint8 &i2);
|
||||
|
||||
void selectColorFromFourColorPalette(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1);
|
||||
|
||||
// Stipple
|
||||
virtual void setStippleData(byte *data) {};
|
||||
virtual void useStipple(bool enabled) {};
|
||||
void scaleStipplePattern(byte originalPattern[128], byte newPattern[128]);
|
||||
|
||||
byte _defaultStippleArray[128] = {
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
|
||||
};
|
||||
|
||||
byte *_variableStippleArray;
|
||||
|
||||
float _skyNormals[16][3] = {
|
||||
{ 0.0, 0.0, 1.0 }, //front //0
|
||||
{ 0.0, 0.0, 1.0 }, //1
|
||||
{ 0.0, 0.0, 1.0 }, //2
|
||||
{ 0.0, 0.0, 1.0 }, //3
|
||||
{ 0.0, 0.0, -1.0 }, //back //0
|
||||
{ 0.0, 0.0, -1.0 }, //1
|
||||
{ 0.0, 0.0, -1.0 }, //2
|
||||
{ 0.0, 0.0, -1.0 }, //3
|
||||
{ -1.0, 0.0, 0.0 }, //left
|
||||
{ -1.0, 0.0, 0.0 },
|
||||
{ -1.0, 0.0, 0.0 },
|
||||
{ -1.0, 0.0, 0.0 },
|
||||
{ 1.0, 0.0, 0.0 }, //right
|
||||
{ 1.0, 0.0, 0.0 },
|
||||
{ 1.0, 0.0, 0.0 },
|
||||
{ 1.0, 0.0, 0.0 }
|
||||
};
|
||||
|
||||
float _skyUvs1008[16][2] = {
|
||||
{ 0.0f, 0.0f }, //1
|
||||
{ 0.0f, 2.0f }, //2
|
||||
{ 0.4f, 2.0f }, //3
|
||||
{ 0.4f, 0.0f }, //front //4
|
||||
|
||||
{ 0.0f, 2.0f }, //back //1
|
||||
{ 0.4f, 2.0f }, //2
|
||||
{ 0.4f, 0.0f }, //3
|
||||
{ 0.0f, 0.0f }, //4
|
||||
|
||||
{ 0.0f, 0.0f }, //left //1
|
||||
{ 0.4f, 0.0f }, //2
|
||||
{ 0.4f, 2.0f }, //3
|
||||
{ 0.0f, 2.0f }, //4
|
||||
|
||||
{ 0.4f, 0.0f }, //right //1
|
||||
{ 0.0f, 0.0f }, //2
|
||||
{ 0.0f, 2.0f }, //3
|
||||
{ 0.4f, 2.0f }, //4
|
||||
};
|
||||
|
||||
float _skyUvs128[16][2] = {
|
||||
{ 0.0f, 0.0f }, //1
|
||||
{ 0.0f, 2.0f }, //2
|
||||
{ 2.5f, 2.0f }, //3
|
||||
{ 2.5f, 0.0f }, //front //4
|
||||
|
||||
{ 0.0f, 2.0f }, //back //1
|
||||
{ 2.5f, 2.0f }, //2
|
||||
{ 2.5f, 0.0f }, //3
|
||||
{ 0.0f, 0.0f }, //4
|
||||
|
||||
{ 0.0f, 0.0f }, //left //1
|
||||
{ 2.5f, 0.0f }, //2
|
||||
{ 2.5f, 2.0f }, //3
|
||||
{ 0.0f, 2.0f }, //4
|
||||
|
||||
{ 2.5f, 0.0f }, //right //1
|
||||
{ 0.0f, 0.0f }, //2
|
||||
{ 0.0f, 2.0f }, //3
|
||||
{ 2.5f, 2.0f }, //4
|
||||
};
|
||||
|
||||
float _skyVertices[16][3] = {
|
||||
{ -81280.0, 8128.0, 81280.0 }, //1 // Vertex #0 front
|
||||
{ -81280.0, -8128.0, 81280.0 }, //2 // Vertex #1
|
||||
{ 81280.0, -8128.0, 81280.0 }, //3 // Vertex #2
|
||||
{ 81280.0, 8128.0, 81280.0 }, //4 // Vertex #3
|
||||
|
||||
{ 81280.0f, -8128.0f, -81280.0f }, // 1
|
||||
{ -81280.0f, -8128.0f, -81280.0f }, // 2
|
||||
{ -81280.0f, 8128.0f, -81280.0f }, // 3
|
||||
{ 81280.0f, 8128.0f, -81280.0f }, // 4
|
||||
|
||||
{ -81280.0f, 8128.0f, 81280.0f }, //left //1
|
||||
{ -81280.0f, 8128.0f, -81280.0f }, //2
|
||||
{ -81280.0f, -8128.0f, -81280.0f }, //3
|
||||
{ -81280.0f, -8128.0f, 81280.0f }, //4
|
||||
|
||||
{ 81280.0f, 8128.0f, -81280.0f }, //right //1
|
||||
{ 81280.0f, 8128.0f, 81280.0f }, //2
|
||||
{ 81280.0f, -8128.0f, 81280.0f },//3
|
||||
{ 81280.0f, -8128.0f, -81280.0f },//4
|
||||
};
|
||||
|
||||
unsigned int _skyIndices[24] = {
|
||||
0, 1, 2, // front
|
||||
0, 2, 3,
|
||||
|
||||
4, 5, 6, // back
|
||||
4, 6, 7,
|
||||
|
||||
8, 9, 10, // left
|
||||
8, 10, 11,
|
||||
|
||||
12, 13, 14, // right
|
||||
12, 14, 15,
|
||||
};
|
||||
|
||||
byte *_palette;
|
||||
void setColorMap(ColorMap *colorMap_);
|
||||
ColorMap *_colorMap;
|
||||
ColorReMap *_colorRemaps;
|
||||
void clearColorPairArray();
|
||||
void fillColorPairArray();
|
||||
byte _colorPair[16];
|
||||
int _keyColor;
|
||||
int _inkColor;
|
||||
int _paperColor;
|
||||
int _underFireBackgroundColor;
|
||||
Common::Point _shakeOffset;
|
||||
byte _stipples[16][128];
|
||||
|
||||
int _scale;
|
||||
|
||||
/**
|
||||
* Select the window where to render
|
||||
*
|
||||
* This also sets the viewport
|
||||
*/
|
||||
|
||||
virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle = 0.0f) = 0;
|
||||
virtual void updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) = 0;
|
||||
|
||||
Math::Matrix4 getMvpMatrix() const { return _mvpMatrix; }
|
||||
virtual Graphics::Surface *getScreenshot() = 0;
|
||||
void flipVertical(Graphics::Surface *s);
|
||||
|
||||
int _screenW;
|
||||
int _screenH;
|
||||
Common::RenderMode _renderMode;
|
||||
|
||||
bool computeScreenViewport();
|
||||
|
||||
protected:
|
||||
Common::Rect _screenViewport;
|
||||
Common::Rect _viewport;
|
||||
Common::Rect _unscaledViewport;
|
||||
|
||||
Math::Matrix4 _projectionMatrix;
|
||||
Math::Matrix4 _modelViewMatrix;
|
||||
Math::Matrix4 _mvpMatrix;
|
||||
|
||||
Math::Frustum _frustum;
|
||||
|
||||
Math::Matrix4 makeProjectionMatrix(float fov, float nearClipPlane, float farClipPlane) const;
|
||||
};
|
||||
|
||||
Graphics::RendererType determinateRenderType();
|
||||
Renderer *CreateGfxOpenGL(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
|
||||
Renderer *CreateGfxOpenGLShader(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
|
||||
Renderer *CreateGfxTinyGL(int screenW, int screenH, Common::RenderMode renderMode);
|
||||
Renderer *createRenderer(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_GFX_H
|
||||
646
engines/freescape/gfx_opengl.cpp
Normal file
646
engines/freescape/gfx_opengl.cpp
Normal file
@@ -0,0 +1,646 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "common/system.h"
|
||||
#include "math/glmath.h"
|
||||
|
||||
#include "freescape/objects/object.h"
|
||||
#include "freescape/gfx_opengl.h"
|
||||
#include "freescape/gfx_opengl_texture.h"
|
||||
|
||||
#ifdef USE_OPENGL_GAME
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
Renderer *CreateGfxOpenGL(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics) {
|
||||
return new OpenGLRenderer(screenW, screenH, renderMode, authenticGraphics);
|
||||
}
|
||||
|
||||
OpenGLRenderer::OpenGLRenderer(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics) : Renderer(screenW, screenH, renderMode, authenticGraphics) {
|
||||
_verts = (Vertex *)malloc(sizeof(Vertex) * kVertexArraySize);
|
||||
_coords = (Coord *)malloc(sizeof(Coord) * kCoordsArraySize);
|
||||
_texturePixelFormat = getRGBAPixelFormat();
|
||||
_isAccelerated = true;
|
||||
_variableStippleArray = nullptr;
|
||||
}
|
||||
|
||||
OpenGLRenderer::~OpenGLRenderer() {
|
||||
free(_verts);
|
||||
free(_coords);
|
||||
}
|
||||
|
||||
Texture *OpenGLRenderer::createTexture(const Graphics::Surface *surface, bool is3D) {
|
||||
return new OpenGLTexture(surface);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::freeTexture(Texture *texture) {
|
||||
delete texture;
|
||||
}
|
||||
|
||||
Common::Point OpenGLRenderer::nativeResolution() {
|
||||
GLint vect[4];
|
||||
glGetIntegerv(GL_VIEWPORT, vect);
|
||||
return Common::Point(vect[2], vect[3]);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::init() {
|
||||
|
||||
computeScreenViewport();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
setViewport(_viewport);
|
||||
glEnable(GL_DEPTH_CLAMP);
|
||||
|
||||
scaleStipplePattern(_defaultStippleArray, _stipples[15]);
|
||||
memcpy(_defaultStippleArray, _stipples[15], 128);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::setViewport(const Common::Rect &rect) {
|
||||
_viewport = Common::Rect(
|
||||
_screenViewport.width() * rect.width() / _screenW,
|
||||
_screenViewport.height() * rect.height() / _screenH
|
||||
);
|
||||
|
||||
_viewport.translate(
|
||||
_screenViewport.left + _screenViewport.width() * rect.left / _screenW,
|
||||
_screenViewport.top + _screenViewport.height() * rect.top / _screenH
|
||||
);
|
||||
|
||||
_unscaledViewport = rect;
|
||||
glViewport(_viewport.left, g_system->getHeight() - _viewport.bottom, _viewport.width(), _viewport.height());
|
||||
glScissor(_viewport.left, g_system->getHeight() - _viewport.bottom, _viewport.width(), _viewport.height());
|
||||
}
|
||||
|
||||
void OpenGLRenderer::drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) {
|
||||
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
|
||||
|
||||
const float tLeft = textureRect.left / (float)glTexture->_internalWidth;
|
||||
const float tWidth = textureRect.width() / (float)glTexture->_internalWidth;
|
||||
const float tTop = textureRect.top / (float)glTexture->_internalHeight;
|
||||
const float tHeight = textureRect.height() / (float)glTexture->_internalHeight;
|
||||
|
||||
float sLeft = screenRect.left;
|
||||
float sTop = screenRect.top;
|
||||
float sRight = sLeft + screenRect.width();
|
||||
float sBottom = sTop + screenRect.height();
|
||||
|
||||
SWAP(sTop, sBottom);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, _screenW, 0, _screenH, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
copyToVertexArray(0, Math::Vector3d(sLeft + 0, sBottom, 1.0f));
|
||||
copyToVertexArray(1, Math::Vector3d(sRight, sBottom, 1.0f));
|
||||
copyToVertexArray(2, Math::Vector3d(sLeft + 0, sTop + 0, 1.0f));
|
||||
copyToVertexArray(3, Math::Vector3d(sRight, sTop + 0, 1.0));
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
|
||||
copyToCoordArray(0, Math::Vector2d(tLeft, tTop + tHeight));
|
||||
copyToCoordArray(1, Math::Vector2d(tLeft + tWidth, tTop + tHeight));
|
||||
copyToCoordArray(2, Math::Vector2d(tLeft, tTop));
|
||||
copyToCoordArray(3, Math::Vector2d(tLeft + tWidth, tTop));
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, _coords);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, glTexture->_id);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // Bind the default (empty) texture to avoid darker colors!
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void OpenGLRenderer::drawSkybox(Texture *texture, Math::Vector3d camera) {
|
||||
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, glTexture->_id);
|
||||
glVertexPointer(3, GL_FLOAT, 0, _skyVertices);
|
||||
glNormalPointer(GL_FLOAT, 0, _skyNormals);
|
||||
if (texture->_width == 1008)
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, _skyUvs1008);
|
||||
else if (texture->_width == 128)
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, _skyUvs128);
|
||||
else
|
||||
error("Unsupported skybox texture width %d", texture->_width);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
|
||||
glPolygonMode(GL_BACK, GL_FILL);
|
||||
|
||||
glPushMatrix();
|
||||
{
|
||||
glTranslatef(camera.x(), camera.y(), camera.z());
|
||||
glDrawArrays(GL_QUADS, 0, 16);
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void OpenGLRenderer::drawThunder(Texture *texture, const Math::Vector3d position, const float size) {
|
||||
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
|
||||
glPushMatrix();
|
||||
{
|
||||
glTranslatef(position.x(), position.y(), position.z());
|
||||
|
||||
GLfloat m[16];
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, m);
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
m[i * 4 + j] = (i == j) ? 1.0f : 0.0f;
|
||||
glLoadMatrixf(m);
|
||||
|
||||
glRotatef(-90, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// === Texturing setup ===
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, glTexture->_id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
|
||||
// === Blending (thunder should glow) ===
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
|
||||
// === Draw the billboarded quad ===
|
||||
float half = size * 0.5f;
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex3f(-half, -half, 0.0f);
|
||||
glTexCoord2f(0.0f, 0.72f); glVertex3f( half, -half, 0.0f);
|
||||
glTexCoord2f(1.0f, 0.72f); glVertex3f( half, half, 0.0f);
|
||||
glTexCoord2f(1.0f, 0.0f); glVertex3f(-half, half, 0.0f);
|
||||
glEnd();
|
||||
|
||||
// === Cleanup ===
|
||||
glDisable(GL_BLEND);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void OpenGLRenderer::updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
// Calculate the xmax and ymax values based on FOV and aspect ratio
|
||||
float xmaxValue = nearClipPlane * tan(Math::deg2rad(fov) / 2);
|
||||
float ymaxValue = xmaxValue / aspectRatio;
|
||||
|
||||
// Corrected glFrustum call
|
||||
glFrustum(-xmaxValue, xmaxValue, -ymaxValue, ymaxValue, nearClipPlane, farClipPlane);
|
||||
glScalef(-1.0f, 1.0f, 1.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
void OpenGLRenderer::positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle) {
|
||||
Math::Vector3d up_vec(0, 1, 0);
|
||||
|
||||
Math::Matrix4 lookMatrix = Math::makeLookAtMatrix(pos, interest, up_vec);
|
||||
glMultMatrixf(lookMatrix.getData());
|
||||
glRotatef(rollAngle, 0.0f, 0.0f, 1.0f);
|
||||
glTranslatef(-pos.x(), -pos.y(), -pos.z());
|
||||
|
||||
// Apply a 2D shake effect on the projection matrix.
|
||||
// This avoids moving the camera in the 3D world, which could cause clipping issues.
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
GLfloat projMatrix[16];
|
||||
glGetFloatv(GL_PROJECTION_MATRIX, projMatrix);
|
||||
glLoadIdentity();
|
||||
glTranslatef(_shakeOffset.x * 0.05f, _shakeOffset.y * 0.05f, 0.0f);
|
||||
glMultMatrixf(projMatrix);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d target, const Common::Rect &viewArea) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
glColor4ub(255, 255, 255, 255);
|
||||
|
||||
glLineWidth(20);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, sensor);
|
||||
copyToVertexArray(1, target);
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glLineWidth(1);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::renderCrossair(const Common::Point &crossairPosition) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, _screenW, _screenH, 0, 0, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
useColor(255, 255, 255);
|
||||
|
||||
glLineWidth(MAX(2, g_system->getWidth() / 640)); // 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(crossairPosition.x - 3, crossairPosition.y, 0));
|
||||
copyToVertexArray(1, Math::Vector3d(crossairPosition.x - 1, crossairPosition.y, 0));
|
||||
|
||||
copyToVertexArray(2, Math::Vector3d(crossairPosition.x + 1, crossairPosition.y, 0));
|
||||
copyToVertexArray(3, Math::Vector3d(crossairPosition.x + 3, crossairPosition.y, 0));
|
||||
|
||||
copyToVertexArray(4, Math::Vector3d(crossairPosition.x, crossairPosition.y - 3, 0));
|
||||
copyToVertexArray(5, Math::Vector3d(crossairPosition.x, crossairPosition.y - 1, 0));
|
||||
|
||||
copyToVertexArray(6, Math::Vector3d(crossairPosition.x, crossairPosition.y + 1, 0));
|
||||
copyToVertexArray(7, Math::Vector3d(crossairPosition.x, crossairPosition.y + 3, 0));
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glDrawArrays(GL_LINES, 0, 8);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glLineWidth(1);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::renderPlayerShootRay(byte color, const Common::Point &position, const Common::Rect &viewArea) {
|
||||
uint8 r, g, b;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, _screenW, _screenH, 0, 0, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
if (_renderMode == Common::kRenderCGA || _renderMode == Common::kRenderZX) {
|
||||
r = g = b = 255;
|
||||
} else {
|
||||
if (_renderMode == Common::kRenderHercG) {
|
||||
// Hercules Green
|
||||
r = b = 0;
|
||||
g = 255;
|
||||
} else if (_renderMode == Common::kRenderHercA) {
|
||||
// Hercules Amber
|
||||
r = 255;
|
||||
g = 191;
|
||||
b = 0;
|
||||
} else
|
||||
r = g = b = 255;
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
}
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glColor4ub(r, g, b, 255);
|
||||
|
||||
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, 0));
|
||||
copyToVertexArray(1, Math::Vector3d(position.x, position.y, 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.height() + viewArea.top, 0));
|
||||
copyToVertexArray(5, Math::Vector3d(position.x, position.y, 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);
|
||||
glDrawArrays(GL_LINES, 0, 8);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glLineWidth(1);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::drawCelestialBody(Math::Vector3d position, float radius, byte color) {
|
||||
uint8 r1, g1, b1, r2, g2, b2;
|
||||
byte *stipple = nullptr;
|
||||
getRGBAt(color, 0, r1, g1, b1, r2, g2, b2, stipple);
|
||||
|
||||
int triangleAmount = 20;
|
||||
float twicePi = (float)(2.0 * M_PI);
|
||||
|
||||
// Quick billboard effect inspired from this code:
|
||||
// https://www.lighthouse3d.com/opengl/billboarding/index.php?billCheat
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
GLfloat m[16];
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, m);
|
||||
for (int i = 1; i < 4; i++)
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (i == 2)
|
||||
continue;
|
||||
if (i == j)
|
||||
m[i * 4 + j] = 1.0;
|
||||
else
|
||||
m[i * 4 + j] = 0.0;
|
||||
}
|
||||
|
||||
glLoadMatrixf(m);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
setStippleData(stipple);
|
||||
useColor(r1, g1, b1);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, position);
|
||||
float adj = 1.25; // Perspective correction
|
||||
|
||||
for (int i = 0; i <= triangleAmount; i++) {
|
||||
copyToVertexArray(i + 1,
|
||||
Math::Vector3d(position.x(), position.y() + (radius * cos(i * twicePi / triangleAmount)),
|
||||
position.z() + (adj * radius * sin(i * twicePi / triangleAmount)))
|
||||
);
|
||||
}
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, triangleAmount + 2);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if (r1 != r2 || g1 != g2 || b1 != b2) {
|
||||
useStipple(true);
|
||||
useColor(r2, g2, b2);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, position);
|
||||
|
||||
for (int i = 0; i <= triangleAmount; i++) {
|
||||
copyToVertexArray(i + 1,
|
||||
Math::Vector3d(position.x(), position.y() + (radius * cos(i * twicePi / triangleAmount)),
|
||||
position.z() + (adj * radius * sin(i * twicePi / triangleAmount)))
|
||||
);
|
||||
}
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, triangleAmount + 2);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
useStipple(false);
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void OpenGLRenderer::renderPlayerShootBall(byte color, const Common::Point &position, int frame, const Common::Rect &viewArea) {
|
||||
uint8 r, g, b;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, _screenW, _screenH, 0, 0, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
if (_renderMode == Common::kRenderCGA || _renderMode == Common::kRenderZX) {
|
||||
r = g = b = 255;
|
||||
} else {
|
||||
if (_renderMode == Common::kRenderHercG) {
|
||||
// Hercules Green
|
||||
r = b = 0;
|
||||
g = 255;
|
||||
} else if (_renderMode == Common::kRenderHercA) {
|
||||
// Hercules Amber
|
||||
r = 255;
|
||||
g = 191;
|
||||
b = 0;
|
||||
} else
|
||||
r = g = b = 255;
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
}
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glColor4ub(r, g, b, 255);
|
||||
int triangleAmount = 20;
|
||||
float twicePi = (float)(2.0 * M_PI);
|
||||
float coef = (9 - frame) / 9.0;
|
||||
float radius = (1 - coef) * 4.0;
|
||||
|
||||
Common::Point initial_position(viewArea.left + viewArea.width() / 2 + 2, viewArea.height() + viewArea.top);
|
||||
Common::Point ball_position = coef * position + (1 - coef) * initial_position;
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, Math::Vector3d(ball_position.x, ball_position.y, 0));
|
||||
|
||||
for (int i = 0; i <= triangleAmount; i++) {
|
||||
float x = ball_position.x + (radius * cos(i * twicePi / triangleAmount));
|
||||
float y = ball_position.y + (radius * sin(i * twicePi / triangleAmount));
|
||||
copyToVertexArray(i + 1, Math::Vector3d(x, y, 0));
|
||||
}
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, triangleAmount + 2);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
void OpenGLRenderer::renderFace(const Common::Array<Math::Vector3d> &vertices) {
|
||||
assert(vertices.size() >= 2);
|
||||
const Math::Vector3d &v0 = vertices[0];
|
||||
|
||||
if (vertices.size() == 2) {
|
||||
const Math::Vector3d &v1 = vertices[1];
|
||||
if (v0 == v1)
|
||||
return;
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, v0);
|
||||
copyToVertexArray(1, v1);
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glLineWidth(MAX(1, g_system->getWidth() / 640));
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
glLineWidth(1);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
return;
|
||||
}
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
uint vi = 0;
|
||||
for (uint i = 1; i < vertices.size() - 1; i++) { // no underflow since vertices.size() > 2
|
||||
const Math::Vector3d &v1 = vertices[i];
|
||||
const Math::Vector3d &v2 = vertices[i + 1];
|
||||
vi = 3 * (i - 1); // no underflow since i >= 1
|
||||
copyToVertexArray(vi + 0, v0);
|
||||
copyToVertexArray(vi + 1, v1);
|
||||
copyToVertexArray(vi + 2, v2);
|
||||
}
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glDrawArrays(GL_TRIANGLES, 0, vi + 3);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::depthTesting(bool enabled) {
|
||||
if (enabled) {
|
||||
// If we re-enable depth testing, we need to clear the depth buffer
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
} else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLRenderer::polygonOffset(bool enabled) {
|
||||
if (enabled) {
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(-1.0f, 1.0f);
|
||||
} else {
|
||||
glPolygonOffset(0, 0);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLRenderer::setStippleData(byte *data) {
|
||||
if (!data)
|
||||
data = _defaultStippleArray;
|
||||
|
||||
_variableStippleArray = data;
|
||||
//for (int i = 0; i < 128; i++)
|
||||
// _variableStippleArray[i] = data[(i / 16) % 4];
|
||||
}
|
||||
|
||||
void OpenGLRenderer::useStipple(bool enabled) {
|
||||
if (enabled) {
|
||||
GLfloat factor = 0;
|
||||
glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &factor);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(factor - 0.5f, -1.0f);
|
||||
glEnable(GL_POLYGON_STIPPLE);
|
||||
if (_renderMode == Common::kRenderZX ||
|
||||
_renderMode == Common::kRenderCPC ||
|
||||
_renderMode == Common::kRenderCGA ||
|
||||
_renderMode == Common::kRenderHercG)
|
||||
glPolygonStipple(_variableStippleArray);
|
||||
else
|
||||
glPolygonStipple(_defaultStippleArray);
|
||||
} else {
|
||||
glPolygonOffset(0, 0);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glDisable(GL_POLYGON_STIPPLE);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLRenderer::useColor(uint8 r, uint8 g, uint8 b) {
|
||||
glColor4ub(r, g, b, 255);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport) {
|
||||
if (ignoreViewport)
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glClearColor(r / 255., g / 255., b / 255., 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
if (ignoreViewport)
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::drawFloor(uint8 color) {
|
||||
uint8 r1, g1, b1, r2, g2, b2;
|
||||
byte *stipple;
|
||||
assert(getRGBAt(color, 0, r1, g1, b1, r2, g2, b2, stipple)); // TODO: move check inside this function
|
||||
glColor4ub(r1, g1, b1, 255);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, Math::Vector3d(-100000.0, 0.0, -100000.0));
|
||||
copyToVertexArray(1, Math::Vector3d(100000.0, 0.0, -100000.0));
|
||||
copyToVertexArray(2, Math::Vector3d(100000.0, 0.0, 100000.0));
|
||||
copyToVertexArray(3, Math::Vector3d(-100000.0, 0.0, 100000.0));
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::flipBuffer() {}
|
||||
|
||||
Graphics::Surface *OpenGLRenderer::getScreenshot() {
|
||||
Common::Rect screen = viewport();
|
||||
Graphics::Surface *s = new Graphics::Surface();
|
||||
s->create(screen.width(), screen.height(), getRGBAPixelFormat());
|
||||
glReadPixels(screen.left, screen.top, screen.width(), screen.height(), GL_RGBA, GL_UNSIGNED_BYTE, s->getPixels());
|
||||
flipVertical(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif
|
||||
106
engines/freescape/gfx_opengl.h
Normal file
106
engines/freescape/gfx_opengl.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_GFX_OPENGL_H
|
||||
#define FREESCAPE_GFX_OPENGL_H
|
||||
|
||||
#include "graphics/opengl/system_headers.h"
|
||||
#include "math/vector3d.h"
|
||||
#include "math/vector2d.h"
|
||||
|
||||
#include "freescape/gfx.h"
|
||||
|
||||
#ifdef USE_OPENGL_GAME
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class OpenGLRenderer : public Renderer {
|
||||
public:
|
||||
OpenGLRenderer(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
|
||||
virtual ~OpenGLRenderer();
|
||||
|
||||
struct Vertex {
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
GLfloat z;
|
||||
};
|
||||
|
||||
void copyToVertexArray(uint idx, const Math::Vector3d &src) {
|
||||
assert(idx < kVertexArraySize);
|
||||
_verts[idx].x = src.x();
|
||||
_verts[idx].y = src.y();
|
||||
_verts[idx].z = src.z();
|
||||
}
|
||||
|
||||
Vertex *_verts;
|
||||
|
||||
struct Coord {
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
};
|
||||
|
||||
Coord *_coords;
|
||||
|
||||
void copyToCoordArray(uint idx, const Math::Vector2d &src) {
|
||||
assert(idx < kCoordsArraySize);
|
||||
_coords[idx].x = src.getValue(0);
|
||||
_coords[idx].y = src.getValue(1);
|
||||
}
|
||||
|
||||
virtual void init() override;
|
||||
virtual void clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport = false) override;
|
||||
virtual void setViewport(const Common::Rect &rect) override;
|
||||
virtual Common::Point nativeResolution() override;
|
||||
virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle = 0.0) override;
|
||||
virtual void updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) override;
|
||||
|
||||
virtual void useColor(uint8 r, uint8 g, uint8 b) override;
|
||||
virtual void polygonOffset(bool enabled) override;
|
||||
virtual void setStippleData(byte *data) override;
|
||||
virtual void useStipple(bool enabled) override;
|
||||
virtual void depthTesting(bool enabled) override;
|
||||
|
||||
|
||||
Texture *createTexture(const Graphics::Surface *surface, bool is3D = false) override;
|
||||
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 sensor, const Math::Vector3d player, const Common::Rect &viewPort) override;
|
||||
virtual void renderPlayerShootBall(byte color, const Common::Point &position, int frame, const Common::Rect &viewPort) override;
|
||||
virtual void renderPlayerShootRay(byte color, const Common::Point &position, const Common::Rect &viewPort) override;
|
||||
virtual void renderCrossair(const Common::Point &crossairPosition) override;
|
||||
|
||||
virtual void renderFace(const Common::Array<Math::Vector3d> &vertices) override;
|
||||
|
||||
virtual void flipBuffer() override;
|
||||
virtual void drawFloor(uint8 color) override;
|
||||
void drawCelestialBody(Math::Vector3d position, float radius, uint8 color) override;
|
||||
void drawSkybox(Texture *texture, Math::Vector3d camera) override;
|
||||
void drawThunder(Texture *texture, Math::Vector3d camera, float size) override;
|
||||
|
||||
virtual Graphics::Surface *getScreenshot() override;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif
|
||||
|
||||
#endif // FREESCAPE_GFX_OPENGL_H
|
||||
641
engines/freescape/gfx_opengl_shaders.cpp
Normal file
641
engines/freescape/gfx_opengl_shaders.cpp
Normal file
@@ -0,0 +1,641 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "common/system.h"
|
||||
#include "math/glmath.h"
|
||||
|
||||
#include "freescape/objects/object.h"
|
||||
#include "freescape/gfx_opengl_shaders.h"
|
||||
#include "freescape/gfx_opengl_texture.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
static const GLfloat bitmapVertices[] = {
|
||||
// XS YT
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
0.0, 1.0,
|
||||
1.0, 1.0,
|
||||
};
|
||||
|
||||
Renderer *CreateGfxOpenGLShader(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics) {
|
||||
return new OpenGLShaderRenderer(screenW, screenH, renderMode, authenticGraphics);
|
||||
}
|
||||
|
||||
OpenGLShaderRenderer::OpenGLShaderRenderer(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics) : Renderer(screenW, screenH, renderMode, authenticGraphics) {
|
||||
_verts = nullptr;
|
||||
_triangleShader = nullptr;
|
||||
_triangleVBO = 0;
|
||||
|
||||
_bitmapShader = nullptr;
|
||||
_bitmapVBO = 0;
|
||||
|
||||
_cubemapShader = nullptr;
|
||||
_cubemapVertVBO = 0;
|
||||
_cubemapTexCoordVBO = 0;
|
||||
_cubemapEBO = 0;
|
||||
|
||||
_texturePixelFormat = getRGBAPixelFormat();
|
||||
_isAccelerated = true;
|
||||
}
|
||||
|
||||
OpenGLShaderRenderer::~OpenGLShaderRenderer() {
|
||||
OpenGL::Shader::freeBuffer(_triangleVBO);
|
||||
delete _triangleShader;
|
||||
OpenGL::Shader::freeBuffer(_bitmapVBO);
|
||||
delete _bitmapShader;
|
||||
OpenGL::Shader::freeBuffer(_cubemapVertVBO);
|
||||
OpenGL::Shader::freeBuffer(_cubemapTexCoordVBO);
|
||||
OpenGL::Shader::freeBuffer(_cubemapEBO);
|
||||
delete _cubemapShader;
|
||||
free(_verts);
|
||||
}
|
||||
|
||||
Texture *OpenGLShaderRenderer::createTexture(const Graphics::Surface *surface, bool is3D) {
|
||||
return new OpenGLTexture(surface);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::freeTexture(Texture *texture) {
|
||||
delete texture;
|
||||
}
|
||||
|
||||
Common::Point OpenGLShaderRenderer::nativeResolution() {
|
||||
GLint vect[4];
|
||||
glGetIntegerv(GL_VIEWPORT, vect);
|
||||
return Common::Point(vect[2], vect[3]);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::init() {
|
||||
computeScreenViewport();
|
||||
|
||||
_verts = (Vertex *)malloc(sizeof(Vertex) * kVertexArraySize);
|
||||
|
||||
static const char *triangleAttributes[] = { "position", nullptr };
|
||||
_triangleShader = OpenGL::Shader::fromFiles("freescape_triangle", triangleAttributes);
|
||||
_triangleVBO = OpenGL::Shader::createBuffer(GL_ARRAY_BUFFER, sizeof(Vertex) * kVertexArraySize, _verts, GL_DYNAMIC_DRAW);
|
||||
// TODO: Check if 3 * sizeof(float) == sizeof(Vertex)
|
||||
_triangleShader->enableVertexAttribute("position", _triangleVBO, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
|
||||
|
||||
static const char *bitmapAttributes[] = { "position", "texcoord", nullptr };
|
||||
_bitmapShader = OpenGL::Shader::fromFiles("freescape_bitmap", bitmapAttributes);
|
||||
_bitmapVBO = OpenGL::Shader::createBuffer(GL_ARRAY_BUFFER, sizeof(bitmapVertices), bitmapVertices);
|
||||
_bitmapShader->enableVertexAttribute("position", _bitmapVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
|
||||
_bitmapShader->enableVertexAttribute("texcoord", _bitmapVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
|
||||
|
||||
static const char *cubemapAttributes[] = { "position", "texcoord", nullptr };
|
||||
_cubemapShader = OpenGL::Shader::fromFiles("freescape_cubemap", cubemapAttributes);
|
||||
_cubemapVertVBO = OpenGL::Shader::createBuffer(GL_ARRAY_BUFFER, sizeof(_skyVertices), _skyVertices);
|
||||
_cubemapTexCoordVBO = OpenGL::Shader::createBuffer(GL_ARRAY_BUFFER, sizeof(_skyUvs1008), _skyUvs1008);
|
||||
_cubemapEBO = OpenGL::Shader::createBuffer(GL_ELEMENT_ARRAY_BUFFER, sizeof(_skyIndices), _skyIndices);
|
||||
|
||||
_cubemapShader->enableVertexAttribute("position", _cubemapVertVBO, 3, GL_FLOAT, GL_TRUE, 3 * sizeof(float), 0);
|
||||
_cubemapShader->enableVertexAttribute("texcoord", _cubemapTexCoordVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
|
||||
|
||||
// populate default stipple data for shader rendering
|
||||
for (int i = 0; i < 128; i++)
|
||||
_defaultShaderStippleArray[i] = _defaultStippleArray[i];
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
setViewport(_viewport);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::setViewport(const Common::Rect &rect) {
|
||||
_viewport = Common::Rect(
|
||||
_screenViewport.width() * rect.width() / _screenW,
|
||||
_screenViewport.height() * rect.height() / _screenH
|
||||
);
|
||||
|
||||
_viewport.translate(
|
||||
_screenViewport.left + _screenViewport.width() * rect.left / _screenW,
|
||||
_screenViewport.top + _screenViewport.height() * rect.top / _screenH
|
||||
);
|
||||
|
||||
_unscaledViewport = rect;
|
||||
glViewport(_viewport.left, g_system->getHeight() - _viewport.bottom, _viewport.width(), _viewport.height());
|
||||
glScissor(_viewport.left, g_system->getHeight() - _viewport.bottom, _viewport.width(), _viewport.height());
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) {
|
||||
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
_bitmapShader->use();
|
||||
_bitmapShader->setUniform("flipY", glTexture->_upsideDown);
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, glTexture->_id);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDepthMask(GL_TRUE);
|
||||
_bitmapShader->unbind();
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::drawSkybox(Texture *texture, Math::Vector3d camera) {
|
||||
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
|
||||
|
||||
Math::Matrix4 proj = _projectionMatrix;
|
||||
Math::Matrix4 model = _modelViewMatrix;
|
||||
// remove translation
|
||||
model(3, 0) = 0.0f;
|
||||
model(3, 1) = 0.0f;
|
||||
model(3, 2) = 0.0f;
|
||||
|
||||
proj.transpose();
|
||||
model.transpose();
|
||||
|
||||
Math::Matrix4 skyboxMVP = proj * model;
|
||||
skyboxMVP.transpose();
|
||||
|
||||
_cubemapShader->use();
|
||||
_cubemapShader->setUniform("mvpMatrix", skyboxMVP);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _cubemapTexCoordVBO);
|
||||
if (texture->_width == 1008)
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_skyUvs1008), _skyUvs1008, GL_DYNAMIC_DRAW);
|
||||
else if (texture->_width == 128)
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_skyUvs128), _skyUvs128, GL_DYNAMIC_DRAW);
|
||||
else
|
||||
error("Unsupported skybox texture width %d", texture->_width);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, glTexture->_id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_INT, 0);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
_cubemapShader->unbind();
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) {
|
||||
float xmaxValue = nearClipPlane * tan(Math::deg2rad(fov) / 2);
|
||||
float ymaxValue = xmaxValue / aspectRatio;
|
||||
_projectionMatrix = Math::makeFrustumMatrix(xmaxValue, -xmaxValue, -ymaxValue, ymaxValue, nearClipPlane, farClipPlane);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle) {
|
||||
Math::Vector3d up_vec(0, 1, 0);
|
||||
|
||||
Math::Matrix4 lookMatrix = Math::makeLookAtMatrix(pos, interest, up_vec);
|
||||
Math::Matrix4 viewMatrix;
|
||||
viewMatrix.translate(-pos);
|
||||
viewMatrix.transpose();
|
||||
|
||||
_modelViewMatrix = viewMatrix * lookMatrix;
|
||||
|
||||
Math::Matrix4 proj = _projectionMatrix;
|
||||
Math::Matrix4 model = _modelViewMatrix;
|
||||
proj.transpose();
|
||||
model.transpose();
|
||||
_mvpMatrix = proj * model;
|
||||
_mvpMatrix.transpose();
|
||||
}
|
||||
void OpenGLShaderRenderer::renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d target, const Common::Rect &viewArea) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
useColor(255, 255, 255);
|
||||
|
||||
glLineWidth(20);
|
||||
copyToVertexArray(0, sensor);
|
||||
copyToVertexArray(1, target);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _triangleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, 8 * 3 * sizeof(float), _verts, GL_DYNAMIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
|
||||
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
glLineWidth(1);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
// TODO: move inside the shader?
|
||||
float remap(float f, float s) {
|
||||
return 2. * f / s - 1;
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::renderPlayerShootBall(byte color, const Common::Point &_position, int frame, const Common::Rect &viewArea) {
|
||||
uint8 r, g, b;
|
||||
|
||||
Math::Matrix4 identity;
|
||||
identity(0, 0) = 1.0;
|
||||
identity(1, 1) = 1.0;
|
||||
identity(2, 2) = 1.0;
|
||||
identity(3, 3) = 1.0;
|
||||
|
||||
_triangleShader->use();
|
||||
_triangleShader->setUniform("useStipple", false);
|
||||
_triangleShader->setUniform("mvpMatrix", identity);
|
||||
|
||||
if (_renderMode == Common::kRenderCGA || _renderMode == Common::kRenderZX) {
|
||||
r = g = b = 255;
|
||||
} else {
|
||||
if (_renderMode == Common::kRenderHercG) {
|
||||
// Hercules Green
|
||||
r = b = 0;
|
||||
g = 255;
|
||||
} else if (_renderMode == Common::kRenderHercA) {
|
||||
// Hercules Amber
|
||||
r = 255;
|
||||
g = 191;
|
||||
b = 0;
|
||||
} else
|
||||
r = g = b = 255;
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
}
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
useColor(r, g, b);
|
||||
|
||||
int triangleAmount = 20;
|
||||
float twicePi = (float)(2.0 * M_PI);
|
||||
float coef = (9 - frame) / 9.0;
|
||||
float radius = (1 - coef) * 4.0;
|
||||
|
||||
Common::Point position(_position.x, _screenH - _position.y);
|
||||
|
||||
Common::Point initial_position(viewArea.left + viewArea.width() / 2 + 2, _screenH - (viewArea.height() + viewArea.top));
|
||||
Common::Point ball_position = coef * position + (1 - coef) * initial_position;
|
||||
|
||||
copyToVertexArray(0, Math::Vector3d(remap(ball_position.x, _screenW), remap(ball_position.y, _screenH), 0));
|
||||
|
||||
for (int i = 0; i <= triangleAmount; i++) {
|
||||
float x = remap(ball_position.x + (radius * cos(i * twicePi / triangleAmount)), _screenW);
|
||||
float y = remap(ball_position.y + (radius * sin(i * twicePi / triangleAmount)), _screenH);
|
||||
copyToVertexArray(i + 1, Math::Vector3d(x, y, 0));
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _triangleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, (triangleAmount + 2) * 3 * sizeof(float), _verts, GL_DYNAMIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, (triangleAmount + 2));
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::renderPlayerShootRay(byte color, const Common::Point &position, const Common::Rect &viewArea) {
|
||||
uint8 r, g, b;
|
||||
|
||||
Math::Matrix4 identity;
|
||||
identity(0, 0) = 1.0;
|
||||
identity(1, 1) = 1.0;
|
||||
identity(2, 2) = 1.0;
|
||||
identity(3, 3) = 1.0;
|
||||
|
||||
_triangleShader->use();
|
||||
_triangleShader->setUniform("useStipple", false);
|
||||
_triangleShader->setUniform("mvpMatrix", identity);
|
||||
|
||||
if (_renderMode == Common::kRenderCGA || _renderMode == Common::kRenderZX) {
|
||||
r = g = b = 255;
|
||||
} else {
|
||||
if (_renderMode == Common::kRenderHercG) {
|
||||
// Hercules Green
|
||||
r = b = 0;
|
||||
g = 255;
|
||||
} else if (_renderMode == Common::kRenderHercA) {
|
||||
// Hercules Amber
|
||||
r = 255;
|
||||
g = 191;
|
||||
b = 0;
|
||||
} else
|
||||
r = g = b = 255;
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
}
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
useColor(r, g, b);
|
||||
|
||||
glLineWidth(5); // It will not work in every OpenGL implementation since the
|
||||
// spec doesn't require support for line widths other than 1
|
||||
copyToVertexArray(0, Math::Vector3d(remap(viewArea.left, _screenW), remap(viewArea.height() - viewArea.top, _screenH), 0));
|
||||
copyToVertexArray(1, Math::Vector3d(remap(position.x, _screenW), remap(_screenH - position.y, _screenH), 0));
|
||||
|
||||
copyToVertexArray(2, Math::Vector3d(remap(viewArea.left, _screenW), remap(viewArea.height() - viewArea.top + 3, _screenH), 0));
|
||||
copyToVertexArray(3, Math::Vector3d(remap(position.x, _screenW), remap(_screenH - position.y, _screenH), 0));
|
||||
|
||||
copyToVertexArray(4, Math::Vector3d(remap(viewArea.right, _screenW), remap(_screenH - viewArea.bottom, _screenH), 0));
|
||||
copyToVertexArray(5, Math::Vector3d(remap(position.x, _screenW), remap(_screenH - position.y, _screenH), 0));
|
||||
|
||||
copyToVertexArray(6, Math::Vector3d(remap(viewArea.right, _screenW), remap(_screenH - viewArea.bottom + 3, _screenH), 0));
|
||||
copyToVertexArray(7, Math::Vector3d(remap(position.x, _screenW), remap(_screenH - position.y, _screenH), 0));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _triangleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, 8 * 3 * sizeof(float), _verts, GL_DYNAMIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
|
||||
glDrawArrays(GL_LINES, 0, 8);
|
||||
|
||||
glLineWidth(1);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::drawCelestialBody(const Math::Vector3d position, float radius, byte color) {
|
||||
// === Safety checks ===
|
||||
if (!_triangleShader || radius <= 0.0f)
|
||||
return;
|
||||
|
||||
// === Decode color from palette ===
|
||||
uint8 r1, g1, b1, r2, g2, b2;
|
||||
byte *stipple = nullptr;
|
||||
getRGBAt(color, 0, r1, g1, b1, r2, g2, b2, stipple);
|
||||
useColor(r1, g1, b1);
|
||||
|
||||
// === Build circular vertex fan ===
|
||||
const int triangleAmount = 20;
|
||||
const float twicePi = 2.0f * static_cast<float>(M_PI);
|
||||
const float adj = 1.25f;
|
||||
|
||||
Common::Array<float> verts;
|
||||
|
||||
// Center vertex
|
||||
verts.push_back(static_cast<float>(position.x()));
|
||||
verts.push_back(static_cast<float>(position.y()));
|
||||
verts.push_back(static_cast<float>(position.z()));
|
||||
|
||||
// Circle vertices in YZ plane (same as legacy code)
|
||||
for (int i = 0; i <= triangleAmount; i++) {
|
||||
float x = static_cast<float>(position.x());
|
||||
float y = static_cast<float>(position.y()) + radius * cosf(i * twicePi / triangleAmount);
|
||||
float z = static_cast<float>(position.z()) + adj * radius * sinf(i * twicePi / triangleAmount);
|
||||
verts.push_back(x);
|
||||
verts.push_back(y);
|
||||
verts.push_back(z);
|
||||
}
|
||||
|
||||
// === Apply billboard effect to MVP matrix ===
|
||||
// Replicate the legacy code's matrix modification
|
||||
Math::Matrix4 billboardMVP = _mvpMatrix;
|
||||
|
||||
// Zero out rotation for rows 1, 3 (skip row 2), set diagonal to 1.0
|
||||
// This matches: for (int i = 1; i < 4; i++) for (int j = 0; j < 4; j++)
|
||||
for (int i = 1; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (i == 2)
|
||||
continue;
|
||||
if (i == j)
|
||||
billboardMVP(i, j) = 2.5f;
|
||||
else
|
||||
billboardMVP(i, j) = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// === Bind VBO ===
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _triangleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, verts.size() * sizeof(float), verts.data(), GL_DYNAMIC_DRAW);
|
||||
|
||||
// === Set vertex attribute 0 (position) ===
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
|
||||
|
||||
// === Shader uniforms ===
|
||||
_triangleShader->use();
|
||||
_triangleShader->setUniform("mvpMatrix", billboardMVP);
|
||||
_triangleShader->setUniform("useStipple", false);
|
||||
|
||||
// === Render settings ===
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
// === Draw vertex fan ===
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, verts.size() / 3);
|
||||
|
||||
if (r1 != r2 || g1 != g2 || b1 != b2) {
|
||||
useStipple(true);
|
||||
useColor(r2, g2, b2);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, verts.size() / 3);
|
||||
useStipple(false);
|
||||
}
|
||||
|
||||
// === Restore state ===
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
// === Cleanup binding ===
|
||||
glDisableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
_triangleShader->unbind();
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::renderCrossair(const Common::Point &crossairPosition) {
|
||||
Math::Matrix4 identity;
|
||||
identity(0, 0) = 1.0;
|
||||
identity(1, 1) = 1.0;
|
||||
identity(2, 2) = 1.0;
|
||||
identity(3, 3) = 1.0;
|
||||
|
||||
_triangleShader->use();
|
||||
_triangleShader->setUniform("useStipple", false);
|
||||
_triangleShader->setUniform("mvpMatrix", identity);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
useColor(255, 255, 255);
|
||||
|
||||
glLineWidth(MAX(2, g_system->getWidth() / 640)); // It will not work in every OpenGL implementation since the
|
||||
// spec doesn't require support for line widths other than 1
|
||||
|
||||
copyToVertexArray(0, Math::Vector3d(remap(crossairPosition.x - 3, _screenW), remap(_screenH - crossairPosition.y, _screenH), 0));
|
||||
copyToVertexArray(1, Math::Vector3d(remap(crossairPosition.x - 1, _screenW), remap(_screenH - crossairPosition.y, _screenH), 0));
|
||||
|
||||
copyToVertexArray(2, Math::Vector3d(remap(crossairPosition.x + 1, _screenW), remap(_screenH - crossairPosition.y, _screenH), 0));
|
||||
copyToVertexArray(3, Math::Vector3d(remap(crossairPosition.x + 3, _screenW), remap(_screenH - crossairPosition.y, _screenH), 0));
|
||||
|
||||
copyToVertexArray(4, Math::Vector3d(remap(crossairPosition.x, _screenW), remap(_screenH - crossairPosition.y - 3, _screenH), 0));
|
||||
copyToVertexArray(5, Math::Vector3d(remap(crossairPosition.x, _screenW), remap(_screenH - crossairPosition.y - 1, _screenH), 0));
|
||||
|
||||
copyToVertexArray(6, Math::Vector3d(remap(crossairPosition.x, _screenW), remap(_screenH - crossairPosition.y + 1, _screenH), 0));
|
||||
copyToVertexArray(7, Math::Vector3d(remap(crossairPosition.x, _screenW), remap(_screenH - crossairPosition.y + 3, _screenH), 0));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _triangleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, 8 * 3 * sizeof(float), _verts, GL_DYNAMIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
|
||||
glDrawArrays(GL_LINES, 0, 8);
|
||||
|
||||
glLineWidth(1);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::renderFace(const Common::Array<Math::Vector3d> &vertices) {
|
||||
assert(vertices.size() >= 2);
|
||||
const Math::Vector3d &v0 = vertices[0];
|
||||
|
||||
_triangleShader->use();
|
||||
_triangleShader->setUniform("mvpMatrix", _mvpMatrix);
|
||||
|
||||
if (vertices.size() == 2) {
|
||||
const Math::Vector3d &v1 = vertices[1];
|
||||
if (v0 == v1)
|
||||
return;
|
||||
|
||||
copyToVertexArray(0, v0);
|
||||
copyToVertexArray(1, v1);
|
||||
|
||||
glLineWidth(MAX(1, g_system->getWidth() / 640));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _triangleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, 2 * 3 * sizeof(float), _verts, GL_DYNAMIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
|
||||
glLineWidth(1);
|
||||
return;
|
||||
}
|
||||
|
||||
uint vi = 0;
|
||||
for (uint i = 1; i < vertices.size() - 1; i++) { // no underflow since vertices.size() > 2
|
||||
const Math::Vector3d &v1 = vertices[i];
|
||||
const Math::Vector3d &v2 = vertices[i + 1];
|
||||
vi = 3 * (i - 1); // no underflow since i >= 1
|
||||
copyToVertexArray(vi + 0, v0);
|
||||
copyToVertexArray(vi + 1, v1);
|
||||
copyToVertexArray(vi + 2, v2);
|
||||
}
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _triangleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, (vi + 3) * 3 * sizeof(float), _verts, GL_DYNAMIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, vi + 3);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::depthTesting(bool enabled) {
|
||||
if (enabled) {
|
||||
// If we re-enable depth testing, we need to clear the depth buffer
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
} else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::polygonOffset(bool enabled) {
|
||||
if (enabled) {
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(-10.0f, 1.0f);
|
||||
} else {
|
||||
glPolygonOffset(0, 0);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::setStippleData(byte *data) {
|
||||
if (!data)
|
||||
data = _defaultStippleArray;
|
||||
|
||||
for (int i = 0; i < 128; i++)
|
||||
_variableStippleArray[i] = data[i];
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::useStipple(bool enabled) {
|
||||
_triangleShader->use();
|
||||
_triangleShader->setUniform("useStipple", enabled);
|
||||
|
||||
if (enabled) {
|
||||
GLfloat factor = 0;
|
||||
glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &factor);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(factor - 0.5f, -1.0f);
|
||||
if (_renderMode == Common::kRenderZX ||
|
||||
_renderMode == Common::kRenderCPC ||
|
||||
_renderMode == Common::kRenderCGA ||
|
||||
_renderMode == Common::kRenderHercG)
|
||||
_triangleShader->setUniform("stipple", 128, _variableStippleArray);
|
||||
else
|
||||
_triangleShader->setUniform("stipple", 128, _defaultShaderStippleArray);
|
||||
} else {
|
||||
glPolygonOffset(0, 0);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::useColor(uint8 r, uint8 g, uint8 b) {
|
||||
Math::Vector3d color(r / 256.0, g / 256.0, b / 256.0);
|
||||
_triangleShader->use();
|
||||
_triangleShader->setUniform("color", color);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport) {
|
||||
if (ignoreViewport)
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glClearColor(r / 255., g / 255., b / 255., 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
if (ignoreViewport)
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::drawFloor(uint8 color) {
|
||||
/*uint8 r1, g1, b1, r2, g2, b2;
|
||||
byte *stipple;
|
||||
assert(getRGBAt(color, r1, g1, b1, r2, g2, b2, stipple)); // TODO: move check inside this function
|
||||
glColor4ub(r1, g1, b1, 255);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, Math::Vector3d(-100000.0, 0.0, -100000.0));
|
||||
copyToVertexArray(1, Math::Vector3d(100000.0, 0.0, -100000.0));
|
||||
copyToVertexArray(2, Math::Vector3d(100000.0, 0.0, 100000.0));
|
||||
copyToVertexArray(3, Math::Vector3d(-100000.0, 0.0, 100000.0));
|
||||
glVertexPointer(3, GL_FLOAT, 0, _verts);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);*/
|
||||
}
|
||||
|
||||
void OpenGLShaderRenderer::flipBuffer() {}
|
||||
|
||||
Graphics::Surface *OpenGLShaderRenderer::getScreenshot() {
|
||||
Common::Rect screen = viewport();
|
||||
Graphics::Surface *s = new Graphics::Surface();
|
||||
s->create(screen.width(), screen.height(), getRGBAPixelFormat());
|
||||
glReadPixels(screen.left, screen.top, screen.width(), screen.height(), GL_RGBA, GL_UNSIGNED_BYTE, s->getPixels());
|
||||
flipVertical(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
111
engines/freescape/gfx_opengl_shaders.h
Normal file
111
engines/freescape/gfx_opengl_shaders.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_GFX_OPENGL_SHADERS_H
|
||||
#define FREESCAPE_GFX_OPENGL_SHADERS_H
|
||||
|
||||
#include "graphics/opengl/shader.h"
|
||||
#include "graphics/opengl/system_headers.h"
|
||||
#include "math/vector3d.h"
|
||||
#include "math/vector2d.h"
|
||||
|
||||
#include "freescape/gfx.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class OpenGLShaderRenderer : public Renderer {
|
||||
public:
|
||||
OpenGLShaderRenderer(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
|
||||
virtual ~OpenGLShaderRenderer();
|
||||
|
||||
Math::Matrix4 _projectionMatrix;
|
||||
Math::Matrix4 _modelViewMatrix;
|
||||
Math::Matrix4 _mvpMatrix;
|
||||
|
||||
struct Vertex {
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
GLfloat z;
|
||||
};
|
||||
|
||||
void copyToVertexArray(uint idx, const Math::Vector3d &src) {
|
||||
assert(idx < kVertexArraySize);
|
||||
_verts[idx].x = src.x();
|
||||
_verts[idx].y = src.y();
|
||||
_verts[idx].z = src.z();
|
||||
}
|
||||
|
||||
Vertex *_verts;
|
||||
|
||||
struct Coord {
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
};
|
||||
|
||||
OpenGL::Shader *_triangleShader;
|
||||
OpenGL::Shader *_bitmapShader;
|
||||
OpenGL::Shader *_cubemapShader;
|
||||
GLuint _triangleVBO;
|
||||
GLuint _bitmapVBO;
|
||||
GLuint _cubemapVertVBO;
|
||||
GLuint _cubemapTexCoordVBO;
|
||||
GLuint _cubemapEBO;
|
||||
|
||||
int _defaultShaderStippleArray[128];
|
||||
int _variableStippleArray[128];
|
||||
|
||||
virtual void init() override;
|
||||
virtual void clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport = false) override;
|
||||
virtual void setViewport(const Common::Rect &rect) override;
|
||||
virtual Common::Point nativeResolution() override;
|
||||
virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle = 0.0f) override;
|
||||
virtual void updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) override;
|
||||
|
||||
virtual void useColor(uint8 r, uint8 g, uint8 b) override;
|
||||
virtual void polygonOffset(bool enabled) override;
|
||||
virtual void depthTesting(bool enabled) override;
|
||||
|
||||
virtual void setStippleData(byte *data) override;
|
||||
virtual void useStipple(bool enabled) override;
|
||||
|
||||
Texture *createTexture(const Graphics::Surface *surface, bool is3D = false) override;
|
||||
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 sensor, const Math::Vector3d player, const Common::Rect &viewPort) override;
|
||||
virtual void renderPlayerShootBall(byte color, const Common::Point &position, int frame, const Common::Rect &viewPort) override;
|
||||
virtual void renderPlayerShootRay(byte color, const Common::Point &position, const Common::Rect &viewPort) override;
|
||||
void drawCelestialBody(Math::Vector3d position, float radius, uint8 color) override;
|
||||
void drawSkybox(Texture *texture, Math::Vector3d camera) override;
|
||||
|
||||
virtual void renderCrossair(const Common::Point &crossairPosition) override;
|
||||
|
||||
virtual void renderFace(const Common::Array<Math::Vector3d> &vertices) override;
|
||||
|
||||
virtual void flipBuffer() override;
|
||||
virtual void drawFloor(uint8 color) override;
|
||||
|
||||
virtual Graphics::Surface *getScreenshot() override;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_GFX_OPENGL_SHADERS_H
|
||||
114
engines/freescape/gfx_opengl_texture.cpp
Normal file
114
engines/freescape/gfx_opengl_texture.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
|
||||
|
||||
#include "freescape/gfx_opengl_texture.h"
|
||||
|
||||
#include "graphics/opengl/context.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
// From Bit Twiddling Hacks
|
||||
static uint32 upperPowerOfTwo(uint32 v) {
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
}
|
||||
|
||||
OpenGLTexture::OpenGLTexture() :
|
||||
_internalFormat(0),
|
||||
_sourceFormat(0),
|
||||
_internalWidth(0),
|
||||
_internalHeight(0),
|
||||
_upsideDown(false) {
|
||||
glGenTextures(1, &_id);
|
||||
}
|
||||
|
||||
OpenGLTexture::OpenGLTexture(const Graphics::Surface *surface) {
|
||||
_width = surface->w;
|
||||
_height = surface->h;
|
||||
_format = surface->format;
|
||||
_upsideDown = false;
|
||||
|
||||
// Pad the textures if non power of two support is unavailable
|
||||
if (OpenGLContext.NPOTSupported) {
|
||||
_internalHeight = _height;
|
||||
_internalWidth = _width;
|
||||
} else {
|
||||
_internalHeight = upperPowerOfTwo(_height);
|
||||
_internalWidth = upperPowerOfTwo(_width);
|
||||
}
|
||||
|
||||
if (_format.bytesPerPixel == 4) {
|
||||
assert(surface->format == getRGBAPixelFormat());
|
||||
_format = surface->format;
|
||||
_internalFormat = GL_RGBA;
|
||||
_sourceFormat = GL_UNSIGNED_BYTE;
|
||||
} else if (_format.bytesPerPixel == 2) {
|
||||
_internalFormat = GL_RGB;
|
||||
_sourceFormat = GL_UNSIGNED_SHORT_5_6_5;
|
||||
} else
|
||||
error("Unknown pixel format");
|
||||
|
||||
glGenTextures(1, &_id);
|
||||
glBindTexture(GL_TEXTURE_2D, _id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, _internalFormat, _internalWidth, _internalHeight, 0, _internalFormat, _sourceFormat, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
// TODO: If non power of two textures are unavailable this clamping
|
||||
// has no effect on the padded sides (resulting in white lines on the edges)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
update(surface);
|
||||
}
|
||||
|
||||
OpenGLTexture::~OpenGLTexture() {
|
||||
glDeleteTextures(1, &_id);
|
||||
}
|
||||
|
||||
void OpenGLTexture::update(const Graphics::Surface *surface) {
|
||||
updatePartial(surface, Common::Rect(surface->w, surface->h));
|
||||
}
|
||||
|
||||
void OpenGLTexture::updateTexture(const Graphics::Surface *surface, const Common::Rect &rect) {
|
||||
assert(surface->format == _format);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, _id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, _internalFormat, surface->w, surface->h, 0, _internalFormat, _sourceFormat, const_cast<void *>(surface->getPixels()));
|
||||
}
|
||||
|
||||
void OpenGLTexture::updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) {
|
||||
updateTexture(surface, rect);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif
|
||||
56
engines/freescape/gfx_opengl_texture.h
Normal file
56
engines/freescape/gfx_opengl_texture.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_GFX_OPENGL_TEXTURE_H
|
||||
#define FREESCAPE_GFX_OPENGL_TEXTURE_H
|
||||
|
||||
#include "graphics/opengl/system_headers.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "freescape/gfx.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class OpenGLTexture : public Texture {
|
||||
public:
|
||||
OpenGLTexture(const Graphics::Surface *surface);
|
||||
OpenGLTexture();
|
||||
virtual ~OpenGLTexture();
|
||||
|
||||
void update(const Graphics::Surface *surface) override;
|
||||
void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) override;
|
||||
|
||||
void copyFromFramebuffer(const Common::Rect &screen);
|
||||
|
||||
GLuint _id;
|
||||
GLuint _internalFormat;
|
||||
GLuint _sourceFormat;
|
||||
uint32 _internalWidth;
|
||||
uint32 _internalHeight;
|
||||
bool _upsideDown;
|
||||
|
||||
private:
|
||||
void updateTexture(const Graphics::Surface *surface, const Common::Rect &rect);
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_GFX_OPENGL_TEXTURE_H
|
||||
574
engines/freescape/gfx_tinygl.cpp
Normal file
574
engines/freescape/gfx_tinygl.cpp
Normal file
@@ -0,0 +1,574 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "common/system.h"
|
||||
#include "graphics/tinygl/tinygl.h"
|
||||
#include "math/glmath.h"
|
||||
|
||||
#include "freescape/objects/object.h"
|
||||
#include "freescape/gfx_tinygl.h"
|
||||
#include "freescape/gfx_tinygl_texture.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
Renderer *CreateGfxTinyGL(int screenW, int screenH, Common::RenderMode renderMode) {
|
||||
return new TinyGLRenderer(screenW, screenH, renderMode);
|
||||
}
|
||||
|
||||
TinyGLRenderer::TinyGLRenderer(int screenW, int screenH, Common::RenderMode renderMode) : Renderer(screenW, screenH, renderMode, true) {
|
||||
_verts = (Vertex *)malloc(sizeof(Vertex) * kVertexArraySize);
|
||||
_texCoord = (Coord *)malloc(sizeof(Coord) * kVertexArraySize);
|
||||
// TODO: Select this based on the screen format
|
||||
_texturePixelFormat = getRGBAPixelFormat();
|
||||
_variableStippleArray = nullptr;
|
||||
}
|
||||
|
||||
TinyGLRenderer::~TinyGLRenderer() {
|
||||
TinyGL::destroyContext();
|
||||
free(_verts);
|
||||
free(_texCoord);
|
||||
}
|
||||
|
||||
Texture *TinyGLRenderer::createTexture(const Graphics::Surface *surface, bool is3D) {
|
||||
if (is3D)
|
||||
return new TinyGL3DTexture(surface);
|
||||
else
|
||||
return new TinyGL2DTexture(surface);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::freeTexture(Texture *texture) {
|
||||
//TinyGLTexture *glTexture = static_cast<TinyGLTexture *>(texture);
|
||||
delete texture;
|
||||
}
|
||||
|
||||
void TinyGLRenderer::init() {
|
||||
// debug("Initializing Software 3D Renderer");
|
||||
|
||||
computeScreenViewport();
|
||||
|
||||
TinyGL::createContext(_screenW, _screenH, g_system->getScreenFormat(), 512, true, ConfMan.getBool("dirtyrects"));
|
||||
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglLoadIdentity();
|
||||
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglLoadIdentity();
|
||||
|
||||
tglDisable(TGL_LIGHTING);
|
||||
tglDisable(TGL_TEXTURE_2D);
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
_stippleEnabled = false;
|
||||
}
|
||||
|
||||
void TinyGLRenderer::setViewport(const Common::Rect &rect) {
|
||||
_viewport = rect;
|
||||
tglViewport(rect.left, g_system->getHeight() - rect.bottom, rect.width(), rect.height());
|
||||
tglScissor(rect.left, g_system->getHeight() - rect.bottom, rect.width(), rect.height());
|
||||
}
|
||||
|
||||
void TinyGLRenderer::drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) {
|
||||
const float sLeft = screenRect.left;
|
||||
const float sTop = screenRect.top;
|
||||
const float sWidth = screenRect.width();
|
||||
const float sHeight = screenRect.height();
|
||||
|
||||
// HACK: tglBlit is not affected by the viewport, so we offset the draw coordinates here
|
||||
int viewPort[4];
|
||||
tglGetIntegerv(TGL_VIEWPORT, viewPort);
|
||||
|
||||
TinyGL::BlitTransform transform(sLeft + viewPort[0], sTop + viewPort[1]);
|
||||
transform.sourceRectangle(textureRect.left, textureRect.top, sWidth, sHeight);
|
||||
tglBlit(((TinyGL2DTexture *)texture)->getBlitTexture(), transform);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::drawSkybox(Texture *texture, Math::Vector3d camera) {
|
||||
TinyGL3DTexture *glTexture = static_cast<TinyGL3DTexture *>(texture);
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
tglEnable(TGL_TEXTURE_2D);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_S, TGL_REPEAT);
|
||||
|
||||
tglBindTexture(TGL_TEXTURE_2D, glTexture->_id);
|
||||
tglColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _skyVertices);
|
||||
tglNormalPointer(TGL_FLOAT, 0, _skyNormals);
|
||||
if (texture->_width == 1008)
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 0, _skyUvs1008);
|
||||
else if (texture->_width == 128)
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 0, _skyUvs128);
|
||||
else
|
||||
error("Unsupported skybox texture width %d", glTexture->_width);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglEnableClientState(TGL_NORMAL_ARRAY);
|
||||
|
||||
tglPolygonMode(TGL_BACK, TGL_FILL);
|
||||
|
||||
tglPushMatrix();
|
||||
{
|
||||
tglTranslatef(camera.x(), camera.y(), camera.z());
|
||||
tglDrawArrays(TGL_QUADS, 0, 16);
|
||||
}
|
||||
tglPopMatrix();
|
||||
|
||||
tglDisableClientState(TGL_NORMAL_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
tglDisable(TGL_TEXTURE_2D);
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
tglFlush();
|
||||
}
|
||||
|
||||
void TinyGLRenderer::drawThunder(Texture *texture, Math::Vector3d position, float size) {
|
||||
TinyGL3DTexture *glTexture = static_cast<TinyGL3DTexture *>(texture);
|
||||
tglPushMatrix();
|
||||
{
|
||||
tglTranslatef(position.x(), position.y(), position.z());
|
||||
|
||||
TGLfloat m[16];
|
||||
tglGetFloatv(TGL_MODELVIEW_MATRIX, m);
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
m[i * 4 + j] = (i == j) ? 1.0f : 0.0f;
|
||||
tglLoadMatrixf(m);
|
||||
|
||||
tglRotatef(-90, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// === Texturing setup ===
|
||||
tglEnable(TGL_TEXTURE_2D);
|
||||
tglBindTexture(TGL_TEXTURE_2D, glTexture->_id);
|
||||
//tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_S, TGL_CLAMP_TO_BORDER);
|
||||
//tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_T, TGL_CLAMP_TO_BORDER);
|
||||
|
||||
// === Blending (thunder should glow) ===
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_ONE, TGL_ONE);
|
||||
|
||||
// === Draw the billboarded quad ===
|
||||
float half = size * 0.5f;
|
||||
tglBegin(TGL_QUADS);
|
||||
tglTexCoord2f(0.0f, 0.0f); tglVertex3f(-half, -half, 0.0f);
|
||||
tglTexCoord2f(0.0f, 0.72f); tglVertex3f( half, -half, 0.0f);
|
||||
tglTexCoord2f(1.0f, 0.72f); tglVertex3f( half, half, 0.0f);
|
||||
tglTexCoord2f(1.0f, 0.0f); tglVertex3f(-half, half, 0.0f);
|
||||
tglEnd();
|
||||
|
||||
// === Cleanup ===
|
||||
tglDisable(TGL_BLEND);
|
||||
tglBindTexture(TGL_TEXTURE_2D, 0);
|
||||
tglDisable(TGL_TEXTURE_2D);
|
||||
}
|
||||
tglPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
void TinyGLRenderer::updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) {
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglLoadIdentity();
|
||||
|
||||
float xmaxValue = nearClipPlane * tan(Math::deg2rad(fov) / 2);
|
||||
float ymaxValue = xmaxValue / aspectRatio;
|
||||
|
||||
// Corrected glFrustum call
|
||||
tglFrustum(-xmaxValue, xmaxValue, -ymaxValue, ymaxValue, nearClipPlane, farClipPlane);
|
||||
tglScalef(-1.0f, 1.0f, 1.0f);
|
||||
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglLoadIdentity();
|
||||
}
|
||||
|
||||
void TinyGLRenderer::positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle) {
|
||||
Math::Vector3d up_vec(0, 1, 0);
|
||||
|
||||
Math::Matrix4 lookMatrix = Math::makeLookAtMatrix(pos, interest, up_vec);
|
||||
tglMultMatrixf(lookMatrix.getData());
|
||||
tglRotatef(rollAngle, 0.0f, 0.0f, 1.0f);
|
||||
tglTranslatef(-pos.x(), -pos.y(), -pos.z());
|
||||
}
|
||||
|
||||
void TinyGLRenderer::renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect &viewArea) {
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_ONE_MINUS_DST_COLOR, TGL_ZERO);
|
||||
tglColor4ub(255, 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);
|
||||
tglDisable(TGL_BLEND);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::renderPlayerShootBall(byte color, const Common::Point &position, int frame, const Common::Rect &viewArea) {
|
||||
uint8 r, g, b;
|
||||
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglLoadIdentity();
|
||||
tglOrtho(0, _screenW, _screenH, 0, 0, 1);
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglLoadIdentity();
|
||||
if (_renderMode == Common::kRenderCGA || _renderMode == Common::kRenderZX) {
|
||||
r = g = b = 255;
|
||||
} else {
|
||||
if (_renderMode == Common::kRenderHercG) {
|
||||
// Hercules Green
|
||||
r = b = 0;
|
||||
g = 255;
|
||||
} else if (_renderMode == Common::kRenderHercA) {
|
||||
// Hercules Amber
|
||||
r = 255;
|
||||
g = 191;
|
||||
b = 0;
|
||||
} else
|
||||
r = g = b = 255;
|
||||
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_ONE_MINUS_DST_COLOR, TGL_ZERO);
|
||||
}
|
||||
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_FALSE);
|
||||
|
||||
tglColor4ub(r, g, b, 255);
|
||||
int triangleAmount = 20;
|
||||
float twicePi = (float)(2.0 * M_PI);
|
||||
float coef = (9 - frame) / 9.0;
|
||||
float radius = (1 - coef) * 4.0;
|
||||
|
||||
Common::Point initial_position(viewArea.left + viewArea.width() / 2 + 2, viewArea.height() + viewArea.top);
|
||||
Common::Point ball_position = coef * position + (1 - coef) * initial_position;
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, Math::Vector3d(ball_position.x, ball_position.y, 0));
|
||||
|
||||
for(int i = 0; i <= triangleAmount; i++) {
|
||||
float x = ball_position.x + (radius * cos(i * twicePi / triangleAmount));
|
||||
float y = ball_position.y + (radius * sin(i * twicePi / triangleAmount));
|
||||
copyToVertexArray(i + 1, Math::Vector3d(x, y, 0));
|
||||
}
|
||||
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _verts);
|
||||
tglDrawArrays(TGL_TRIANGLE_FAN, 0, triangleAmount + 2);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
tglDisable(TGL_BLEND);
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
void TinyGLRenderer::renderPlayerShootRay(byte color, const Common::Point &position, const Common::Rect &viewArea) {
|
||||
uint8 r, g, b;
|
||||
readFromPalette(color, r, g, b); // TODO: should use opposite color
|
||||
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglLoadIdentity();
|
||||
tglOrthof(0, _screenW, _screenH, 0, 0, 1);
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglLoadIdentity();
|
||||
|
||||
if (_renderMode == Common::kRenderCGA || _renderMode == Common::kRenderZX) {
|
||||
r = g = b = 255;
|
||||
} else {
|
||||
if (_renderMode == Common::kRenderHercG) {
|
||||
// Hercules Green
|
||||
r = b = 0;
|
||||
g = 255;
|
||||
} else if (_renderMode == Common::kRenderHercA) {
|
||||
// Hercules Amber
|
||||
r = 255;
|
||||
g = 191;
|
||||
b = 0;
|
||||
} else
|
||||
r = g = b = 255;
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_ONE_MINUS_DST_COLOR, TGL_ZERO);
|
||||
}
|
||||
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_FALSE);
|
||||
|
||||
tglColor4ub(r, g, b, 255);
|
||||
|
||||
int viewPort[4];
|
||||
tglGetIntegerv(TGL_VIEWPORT, viewPort);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
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 + 3, 0));
|
||||
copyToVertexArray(3, Math::Vector3d(position.x, position.y, 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.height() + viewArea.top + 3, 0));
|
||||
copyToVertexArray(7, Math::Vector3d(position.x, position.y, 0));
|
||||
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _verts);
|
||||
tglDrawArrays(TGL_LINES, 0, 8);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
tglDisable(TGL_BLEND);
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_TRUE);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::renderCrossair(const Common::Point &crossairPosition) {
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglLoadIdentity();
|
||||
tglOrtho(0, _screenW, _screenH, 0, 0, 1);
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglLoadIdentity();
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_ONE_MINUS_DST_COLOR, TGL_ZERO);
|
||||
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_FALSE);
|
||||
|
||||
useColor(255, 255, 255);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, Math::Vector3d(crossairPosition.x - 3, crossairPosition.y, 0));
|
||||
copyToVertexArray(1, Math::Vector3d(crossairPosition.x - 1, crossairPosition.y, 0));
|
||||
|
||||
copyToVertexArray(2, Math::Vector3d(crossairPosition.x + 2, crossairPosition.y, 0));
|
||||
copyToVertexArray(3, Math::Vector3d(crossairPosition.x + 4, crossairPosition.y, 0));
|
||||
|
||||
copyToVertexArray(4, Math::Vector3d(crossairPosition.x, crossairPosition.y - 3, 0));
|
||||
copyToVertexArray(5, Math::Vector3d(crossairPosition.x, crossairPosition.y - 1, 0));
|
||||
|
||||
copyToVertexArray(6, Math::Vector3d(crossairPosition.x, crossairPosition.y + 2, 0));
|
||||
copyToVertexArray(7, Math::Vector3d(crossairPosition.x, crossairPosition.y + 4, 0));
|
||||
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _verts);
|
||||
tglDrawArrays(TGL_LINES, 0, 8);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
tglDisable(TGL_BLEND);
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_TRUE);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::setStippleData(byte *data) {
|
||||
if (!data) {
|
||||
_variableStippleArray = nullptr;
|
||||
return;
|
||||
}
|
||||
_variableStippleArray = data;
|
||||
}
|
||||
|
||||
void TinyGLRenderer::useStipple(bool enabled) {
|
||||
_stippleEnabled = enabled;
|
||||
|
||||
if (enabled) {
|
||||
if (!_variableStippleArray)
|
||||
_variableStippleArray = _defaultStippleArray;
|
||||
tglEnable(TGL_POLYGON_STIPPLE);
|
||||
tglEnable(TGL_TWO_COLOR_STIPPLE);
|
||||
tglPolygonStipple(_variableStippleArray);
|
||||
} else {
|
||||
tglDisable(TGL_POLYGON_STIPPLE);
|
||||
tglDisable(TGL_TWO_COLOR_STIPPLE);
|
||||
_variableStippleArray = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TinyGLRenderer::renderFace(const Common::Array<Math::Vector3d> &vertices) {
|
||||
if (_variableStippleArray && !_stippleEnabled)
|
||||
return;
|
||||
|
||||
assert(vertices.size() >= 2);
|
||||
const Math::Vector3d &v0 = vertices[0];
|
||||
|
||||
if (vertices.size() == 2) {
|
||||
const Math::Vector3d &v1 = vertices[1];
|
||||
if (v0 == v1)
|
||||
return;
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, v0);
|
||||
copyToVertexArray(1, v1);
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _verts);
|
||||
tglDrawArrays(TGL_LINES, 0, 2);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
return;
|
||||
}
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
uint vi = 0;
|
||||
for (uint i = 1; i < vertices.size() - 1; i++) { // no underflow since vertices.size() > 2
|
||||
const Math::Vector3d &v1 = vertices[i];
|
||||
const Math::Vector3d &v2 = vertices[i + 1];
|
||||
vi = 3 * (i - 1); // no underflow since i >= 1
|
||||
copyToVertexArray(vi + 0, v0);
|
||||
copyToVertexArray(vi + 1, v1);
|
||||
copyToVertexArray(vi + 2, v2);
|
||||
}
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _verts);
|
||||
|
||||
tglDrawArrays(TGL_TRIANGLES, 0, vi + 3);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::drawCelestialBody(Math::Vector3d position, float radius, byte color) {
|
||||
uint8 r1, g1, b1, r2, g2, b2;
|
||||
byte *stipple = nullptr;
|
||||
getRGBAt(color, 0, r1, g1, b1, r2, g2, b2, stipple);
|
||||
|
||||
int triangleAmount = 20;
|
||||
float twicePi = (float)(2.0 * M_PI);
|
||||
|
||||
// Quick billboard effect inspired from this code:
|
||||
// https://www.lighthouse3d.com/opengl/billboarding/index.php?billCheat
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglPushMatrix();
|
||||
TGLfloat m[16];
|
||||
tglGetFloatv(TGL_MODELVIEW_MATRIX, m);
|
||||
for(int i = 1; i < 4; i++)
|
||||
for(int j = 0; j < 4; j++ ) {
|
||||
if (i == 2)
|
||||
continue;
|
||||
if (i == j)
|
||||
m[i*4 + j] = 1.0;
|
||||
else
|
||||
m[i*4 + j] = 0.0;
|
||||
}
|
||||
|
||||
tglLoadMatrixf(m);
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_FALSE);
|
||||
|
||||
setStippleData(stipple);
|
||||
useColor(r1, g1, b1);
|
||||
if (r1 != r2 || g1 != g2 || b1 != b2) {
|
||||
useStipple(true);
|
||||
tglStippleColor(r2, g2, b2);
|
||||
}
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, position);
|
||||
float adj = 1.25; // Perspective correction
|
||||
|
||||
for (int i = 0; i <= triangleAmount; i++) {
|
||||
copyToVertexArray(i + 1,
|
||||
Math::Vector3d(position.x(), position.y() + (radius * cos(i * twicePi / triangleAmount)),
|
||||
position.z() + (adj * radius * sin(i * twicePi / triangleAmount)))
|
||||
);
|
||||
}
|
||||
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _verts);
|
||||
tglDrawArrays(TGL_TRIANGLE_FAN, 0, triangleAmount + 2);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
|
||||
useStipple(false);
|
||||
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_TRUE);
|
||||
tglPopMatrix();
|
||||
}
|
||||
|
||||
void TinyGLRenderer::depthTesting(bool enabled) {
|
||||
if (enabled) {
|
||||
tglClear(TGL_DEPTH_BUFFER_BIT);
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
} else {
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
void TinyGLRenderer::polygonOffset(bool enabled) {
|
||||
if (enabled) {
|
||||
tglEnable(TGL_POLYGON_OFFSET_FILL);
|
||||
tglPolygonOffset(-1.0f, 1.0f);
|
||||
} else {
|
||||
tglPolygonOffset(0, 0);
|
||||
tglDisable(TGL_POLYGON_OFFSET_FILL);
|
||||
}
|
||||
}
|
||||
|
||||
void TinyGLRenderer::useColor(uint8 r, uint8 g, uint8 b) {
|
||||
if (_stippleEnabled) {
|
||||
tglStippleColor(r, g, b);
|
||||
} else {
|
||||
tglColor4ub(r, g, b, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void TinyGLRenderer::clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport) {
|
||||
if (ignoreViewport)
|
||||
tglDisable(TGL_SCISSOR_TEST);
|
||||
tglClearColor(r / 255., g / 255., b / 255., 1.0);
|
||||
tglClear(TGL_COLOR_BUFFER_BIT | TGL_DEPTH_BUFFER_BIT | TGL_STENCIL_BUFFER_BIT);
|
||||
if (ignoreViewport)
|
||||
tglEnable(TGL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::drawFloor(uint8 color) {
|
||||
uint8 r1, g1, b1, r2, g2, b2;
|
||||
byte *stipple = nullptr;
|
||||
assert(getRGBAt(color, 0, r1, g1, b1, r2, g2, b2, stipple)); // TODO: move check inside this function
|
||||
tglColor4ub(r1, g1, b1, 255);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
copyToVertexArray(0, Math::Vector3d(-100000.0, 0.0, -100000.0));
|
||||
copyToVertexArray(1, Math::Vector3d(100000.0, 0.0, -100000.0));
|
||||
copyToVertexArray(2, Math::Vector3d(100000.0, 0.0, 100000.0));
|
||||
copyToVertexArray(3, Math::Vector3d(-100000.0, 0.0, 100000.0));
|
||||
tglVertexPointer(3, TGL_FLOAT, 0, _verts);
|
||||
tglDrawArrays(TGL_QUADS, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::flipBuffer() {
|
||||
Common::List<Common::Rect> dirtyAreas;
|
||||
TinyGL::presentBuffer(dirtyAreas);
|
||||
|
||||
Graphics::Surface glBuffer;
|
||||
TinyGL::getSurfaceRef(glBuffer);
|
||||
|
||||
if (!dirtyAreas.empty()) {
|
||||
for (auto &it : dirtyAreas) {
|
||||
g_system->copyRectToScreen(glBuffer.getBasePtr(it.left, it.top), glBuffer.pitch,
|
||||
it.left, it.top, it.width(), it.height());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Graphics::Surface *TinyGLRenderer::getScreenshot() {
|
||||
Graphics::Surface glBuffer;
|
||||
TinyGL::getSurfaceRef(glBuffer);
|
||||
|
||||
Graphics::Surface *s = new Graphics::Surface();
|
||||
s->create(_screenW, _screenH, getRGBAPixelFormat());
|
||||
s->convertFrom(glBuffer, getRGBAPixelFormat());
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
125
engines/freescape/gfx_tinygl.h
Normal file
125
engines/freescape/gfx_tinygl.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_GFX_TINYGL_H
|
||||
#define FREESCAPE_GFX_TINYGL_H
|
||||
|
||||
#include "math/vector3d.h"
|
||||
#include "common/hashmap.h"
|
||||
|
||||
#include "freescape/gfx.h"
|
||||
#include "freescape/gfx_tinygl_texture.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class TinyGLRenderer : public Renderer {
|
||||
public:
|
||||
TinyGLRenderer(int screenW, int screenH, Common::RenderMode renderMode);
|
||||
virtual ~TinyGLRenderer();
|
||||
|
||||
struct Vertex {
|
||||
TGLfloat x;
|
||||
TGLfloat y;
|
||||
TGLfloat z;
|
||||
};
|
||||
|
||||
Vertex *_verts;
|
||||
void copyToVertexArray(uint idx, const Math::Vector3d &src) {
|
||||
assert(idx < kVertexArraySize);
|
||||
_verts[idx].x = src.x();
|
||||
_verts[idx].y = src.y();
|
||||
_verts[idx].z = src.z();
|
||||
}
|
||||
|
||||
struct Coord {
|
||||
TGLfloat x;
|
||||
TGLfloat y;
|
||||
};
|
||||
|
||||
Coord *_texCoord;
|
||||
|
||||
void copyToTexCoordArray(uint idx, float x, float y) {
|
||||
assert(idx < kVertexArraySize);
|
||||
_texCoord[idx].x = x;
|
||||
_texCoord[idx].y = y;
|
||||
}
|
||||
|
||||
bool _stippleEnabled;
|
||||
TinyGL3DTexture *_stippleTexture;
|
||||
Common::HashMap<uint64, TinyGL3DTexture *> _stippleTextureCache;
|
||||
uint32 _lastColorSet0;
|
||||
uint32 _lastColorSet1;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport = false) override;
|
||||
virtual void setViewport(const Common::Rect &rect) override;
|
||||
virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle = 0.0f) override;
|
||||
virtual void updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) override;
|
||||
|
||||
virtual void useColor(uint8 r, uint8 g, uint8 b) override;
|
||||
virtual void polygonOffset(bool enabled) override;
|
||||
virtual void depthTesting(bool enabled) override;
|
||||
virtual void setStippleData(byte *data) override;
|
||||
virtual void useStipple(bool enabled) override;
|
||||
|
||||
Texture *createTexture(const Graphics::Surface *surface, bool is3D = false) override;
|
||||
void freeTexture(Texture *texture) override;
|
||||
virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) override;
|
||||
void drawSkybox(Texture *texture, Math::Vector3d camera) override;
|
||||
void drawThunder(Texture *texture, Math::Vector3d camera, float size) override;
|
||||
|
||||
virtual void renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect &viewPort) override;
|
||||
virtual void renderPlayerShootBall(byte color, const Common::Point &position, int frame, const Common::Rect &viewPort) override;
|
||||
virtual void renderPlayerShootRay(byte color, const Common::Point &position, const Common::Rect &viewPort) override;
|
||||
virtual void renderCrossair(const Common::Point &crossairPosition) override;
|
||||
|
||||
virtual void renderFace(const Common::Array<Math::Vector3d> &vertices) override;
|
||||
|
||||
void drawCelestialBody(Math::Vector3d position, float radius, byte color) override;
|
||||
|
||||
virtual void flipBuffer() override;
|
||||
virtual void drawFloor(uint8 color) override;
|
||||
virtual Graphics::Surface *getScreenshot() override;
|
||||
|
||||
byte _defaultStippleArray[128] = {
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_GFX_TINYGL_H
|
||||
180
engines/freescape/gfx_tinygl_texture.cpp
Normal file
180
engines/freescape/gfx_tinygl_texture.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
/* 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 "graphics/tinygl/zblit.h"
|
||||
|
||||
#include "freescape/gfx_tinygl_texture.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
TinyGL2DTexture::TinyGL2DTexture(const Graphics::Surface *surface) {
|
||||
_width = surface->w;
|
||||
_height = surface->h;
|
||||
_format = surface->format;
|
||||
_internalFormat = 0;
|
||||
_sourceFormat = 0;
|
||||
|
||||
_blitImage = tglGenBlitImage();
|
||||
|
||||
update(surface);
|
||||
}
|
||||
|
||||
TinyGL2DTexture::~TinyGL2DTexture() {
|
||||
tglDeleteBlitImage(_blitImage);
|
||||
}
|
||||
|
||||
void TinyGL2DTexture::update(const Graphics::Surface *surface) {
|
||||
uint32 keyColor = surface->format.RGBToColor(0xA0, 0xA0, 0xA0);
|
||||
tglUploadBlitImage(_blitImage, *surface, keyColor, true);
|
||||
}
|
||||
|
||||
void TinyGL2DTexture::updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) {
|
||||
// FIXME: TinyGL does not support partial texture update
|
||||
update(surface);
|
||||
}
|
||||
|
||||
TinyGL::BlitImage *TinyGL2DTexture::getBlitTexture() const {
|
||||
return _blitImage;
|
||||
}
|
||||
|
||||
TinyGL3DTexture::TinyGL3DTexture(byte *stipple, uint32 c1, uint32 c2) {
|
||||
Graphics::Surface *surface = new Graphics::Surface();
|
||||
int width = 32;
|
||||
int height = 32;
|
||||
|
||||
surface->create(width, height, getRGBAPixelFormat());
|
||||
surface->fillRect(Common::Rect(0, 0, width, height), surface->format.RGBToColor(0, 0, 0xFF));
|
||||
|
||||
const int stippleWidth = 32;
|
||||
const int stippleHeight = 32;
|
||||
|
||||
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
|
||||
// Match OpenGL's stipple bit layout
|
||||
int stippleX = x % stippleWidth; // Bit position in the row
|
||||
int stippleY = y % stippleHeight; // Row index
|
||||
|
||||
int byteIndex = stippleY * 4 + (stippleX / 8); // 4 bytes per row
|
||||
int bitIndex = stippleX % 8;
|
||||
|
||||
byte bitmask = 1 << (7 - bitIndex);
|
||||
bool isForeground = stipple[byteIndex] & bitmask;
|
||||
//debug("stippleX=%d stippleY=%d byteIndex=%d bitIndex=%d stipple[byteIndex]: %x color: %s", stippleX, stippleY, byteIndex, bitIndex, stipple[byteIndex], isForeground ? "X" : " ");
|
||||
surface->setPixel(stippleX, stippleY, isForeground ? c1 : c2);
|
||||
}
|
||||
}
|
||||
//assert(0);
|
||||
Graphics::Surface *texture = new Graphics::Surface();
|
||||
texture->create(320, 200, getRGBAPixelFormat());
|
||||
texture->fillRect(Common::Rect(0, 0, 320, 200), texture->format.RGBToColor(0, 0, 0xFF));
|
||||
//texture->copyRectToSurface(*surface, 0, 0, Common::Rect(0, 0, 32, 32));
|
||||
|
||||
// Replicate the stipple pattern to fill the entire texture
|
||||
for (int x = 0; x < 320; x += width) {
|
||||
for (int y = 0; y < 200; y += height) {
|
||||
if (x + width >= 320 || y + height >= 200) {
|
||||
texture->copyRectToSurface(*surface, x, y, Common::Rect(0, 0, MIN(width, 320 - x), MIN(height, 200 - y)));
|
||||
} else
|
||||
texture->copyRectToSurface(*surface, x, y, Common::Rect(0, 0, width, height));
|
||||
}
|
||||
}
|
||||
|
||||
// This surface is no longer needed
|
||||
surface->free();
|
||||
delete surface;
|
||||
|
||||
_width = texture->w;
|
||||
_height = texture->h;
|
||||
_format = texture->format;
|
||||
_upsideDown = false;
|
||||
|
||||
if (_format.bytesPerPixel == 4) {
|
||||
assert(texture->format == getRGBAPixelFormat());
|
||||
_format = texture->format;
|
||||
_internalFormat = TGL_RGBA;
|
||||
_sourceFormat = TGL_UNSIGNED_BYTE;
|
||||
} else if (_format.bytesPerPixel == 2) {
|
||||
_internalFormat = TGL_RGB;
|
||||
_sourceFormat = TGL_UNSIGNED_SHORT_5_6_5;
|
||||
} else
|
||||
error("Unknown pixel format");
|
||||
|
||||
tglGenTextures(1, &_id);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _id);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, _internalFormat, _width, _height, 0, _internalFormat, _sourceFormat, nullptr);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
|
||||
update(texture);
|
||||
|
||||
texture->free();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TinyGL3DTexture::TinyGL3DTexture(const Graphics::Surface *surface) {
|
||||
_width = surface->w;
|
||||
_height = surface->h;
|
||||
_format = surface->format;
|
||||
_upsideDown = false;
|
||||
|
||||
if (_format.bytesPerPixel == 4) {
|
||||
assert(surface->format == getRGBAPixelFormat());
|
||||
_format = surface->format;
|
||||
_internalFormat = TGL_RGBA;
|
||||
_sourceFormat = TGL_UNSIGNED_BYTE;
|
||||
} else if (_format.bytesPerPixel == 2) {
|
||||
_internalFormat = TGL_RGB;
|
||||
_sourceFormat = TGL_UNSIGNED_SHORT_5_6_5;
|
||||
} else
|
||||
error("Unknown pixel format");
|
||||
|
||||
|
||||
tglGenTextures(1, &_id);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _id);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, _internalFormat, _width, _height, 0, _internalFormat, _sourceFormat, nullptr);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
|
||||
// NOTE: TinyGL doesn't have issues with white lines so doesn't need use TGL_CLAMP_TO_EDGE
|
||||
//tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_S, TGL_CLAMP_TO_EDGE);
|
||||
//tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_WRAP_T, TGL_CLAMP_TO_EDGE);
|
||||
update(surface);
|
||||
}
|
||||
|
||||
TinyGL3DTexture::~TinyGL3DTexture() {
|
||||
tglDeleteTextures(1, &_id);
|
||||
}
|
||||
|
||||
void TinyGL3DTexture::update(const Graphics::Surface *surface) {
|
||||
assert(surface->format == _format);
|
||||
|
||||
tglBindTexture(TGL_TEXTURE_2D, _id);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, _internalFormat, surface->w, surface->h, 0, _internalFormat, _sourceFormat, const_cast<void *>(surface->getPixels()));
|
||||
}
|
||||
|
||||
void TinyGL3DTexture::updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) {
|
||||
// FIXME: TinyGL does not support partial texture update
|
||||
update(surface);
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
68
engines/freescape/gfx_tinygl_texture.h
Normal file
68
engines/freescape/gfx_tinygl_texture.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_GFX_TINYGL_TEXTURE_H
|
||||
#define FREESCAPE_GFX_TINYGL_TEXTURE_H
|
||||
|
||||
#include "graphics/tinygl/zgl.h"
|
||||
|
||||
#include "freescape/gfx.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class TinyGL2DTexture : public Texture {
|
||||
public:
|
||||
TinyGL2DTexture(const Graphics::Surface *surface);
|
||||
virtual ~TinyGL2DTexture();
|
||||
|
||||
TinyGL::BlitImage *getBlitTexture() const;
|
||||
|
||||
void update(const Graphics::Surface *surface) override;
|
||||
void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) override;
|
||||
|
||||
TGLuint _internalFormat;
|
||||
TGLuint _sourceFormat;
|
||||
|
||||
private:
|
||||
TinyGL::BlitImage *_blitImage;
|
||||
};
|
||||
|
||||
|
||||
class TinyGL3DTexture : public Texture {
|
||||
public:
|
||||
TinyGL3DTexture(const Graphics::Surface *surface);
|
||||
TinyGL3DTexture(byte *stipple, uint32 color1, uint32 color2);
|
||||
virtual ~TinyGL3DTexture();
|
||||
|
||||
void update(const Graphics::Surface *surface) override;
|
||||
void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) override;
|
||||
|
||||
TGLuint _id;
|
||||
TGLuint _internalFormat;
|
||||
TGLuint _sourceFormat;
|
||||
uint32 _internalWidth;
|
||||
uint32 _internalHeight;
|
||||
bool _upsideDown;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_GFX_TINYGL_TEXTURE_H
|
||||
486
engines/freescape/language/8bitDetokeniser.cpp
Normal file
486
engines/freescape/language/8bitDetokeniser.cpp
Normal file
@@ -0,0 +1,486 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
// which was implemented based on John Elliott's reverse engineering of Driller (2001)
|
||||
// https://web.archive.org/web/20200116141513/http://www.seasip.demon.co.uk/ZX/Driller/
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
uint8 k8bitVariableShield = 63;
|
||||
|
||||
Common::String detokenise8bitCondition(Common::Array<uint16> &tokenisedCondition, FCLInstructionVector &instructions, bool isAmigaAtari) {
|
||||
Common::String detokenisedStream;
|
||||
Common::Array<uint8>::size_type bytePointer = 0;
|
||||
Common::Array<uint8>::size_type sizeOfTokenisedContent = tokenisedCondition.size();
|
||||
|
||||
if (sizeOfTokenisedContent == 0)
|
||||
error("No tokenised content");
|
||||
|
||||
// on the 8bit platforms, all instructions have a conditional flag;
|
||||
// we'll want to convert them into runs of "if shot? then", "if collided? then" or "if timer? then",
|
||||
// and we'll want to start that from the top
|
||||
FCLInstructionVector *conditionalInstructions = new FCLInstructionVector();
|
||||
FCLInstruction currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
|
||||
// this lookup table tells us how many argument bytes to read per opcode
|
||||
uint8 argumentsRequiredByOpcode[49] =
|
||||
{0, 3, 1, 1, 1, 1, 2, 2,
|
||||
2, 1, 1, 2, 1, 1, 2, 1,
|
||||
1, 2, 2, 1, 2, 0, 0, 0,
|
||||
1, 1, 0, 1, 1, 1, 1, 1,
|
||||
2, 2, 1, 1, 1, 1, 0, 0,
|
||||
0, 1, 0, 0, 0, 0, 2, 2,
|
||||
1};
|
||||
|
||||
if (sizeOfTokenisedContent > 0)
|
||||
detokenisedStream += Common::String::format("CONDITION FLAG: %x\n", tokenisedCondition[0]);
|
||||
uint16 newConditional = 0;
|
||||
uint16 oldConditional = 0;
|
||||
|
||||
while (bytePointer < sizeOfTokenisedContent) {
|
||||
// get the conditional type of the next operation
|
||||
uint8 conditionalByte = tokenisedCondition[bytePointer] & 0xc0;
|
||||
//detokenisedStream += Common::String::format("CONDITION FLAG: %x\n", conditionalByte);
|
||||
newConditional = 0;
|
||||
|
||||
if (conditionalByte == 0x40)
|
||||
newConditional = kConditionalTimeout;
|
||||
else if (conditionalByte == 0x80)
|
||||
newConditional = kConditionalShot;
|
||||
else if (conditionalByte == 0xc0)
|
||||
newConditional = kConditionalActivated;
|
||||
else
|
||||
newConditional = kConditionalCollided;
|
||||
|
||||
// if the conditional type has changed then end the old conditional,
|
||||
// if we were in one, and begin a new one
|
||||
if (bytePointer == 0 || newConditional != oldConditional) {
|
||||
oldConditional = newConditional;
|
||||
FCLInstruction branch;
|
||||
branch = FCLInstruction(Token::CONDITIONAL);
|
||||
|
||||
if (bytePointer > 0) {
|
||||
detokenisedStream += "ENDIF\n";
|
||||
assert(conditionalInstructions->size() > 0);
|
||||
// Allocate the next vector of instructions
|
||||
conditionalInstructions = new FCLInstructionVector();
|
||||
}
|
||||
|
||||
branch.setBranches(conditionalInstructions, nullptr);
|
||||
branch.setSource(oldConditional); // conditional flag
|
||||
instructions.push_back(branch);
|
||||
|
||||
detokenisedStream += "IF ";
|
||||
|
||||
if (oldConditional & kConditionalShot)
|
||||
detokenisedStream += "SHOT? ";
|
||||
else if (oldConditional & kConditionalTimeout)
|
||||
detokenisedStream += "TIMER? ";
|
||||
else if (oldConditional & kConditionalCollided)
|
||||
detokenisedStream += "COLLIDED? ";
|
||||
else if (oldConditional & kConditionalActivated)
|
||||
detokenisedStream += "ACTIVATED? ";
|
||||
else
|
||||
error("Invalid conditional: %x", oldConditional);
|
||||
|
||||
detokenisedStream += "THEN\n";
|
||||
}
|
||||
|
||||
// get the actual operation
|
||||
uint16 opcode = tokenisedCondition[bytePointer] & 0x3f;
|
||||
bytePointer++;
|
||||
|
||||
// figure out how many argument bytes we're going to need,
|
||||
// check we have enough bytes left to read
|
||||
if (opcode > 48) {
|
||||
debugC(1, kFreescapeDebugParser, "%s", detokenisedStream.c_str());
|
||||
error("ERROR: failed to read opcode: %x", opcode);
|
||||
break;
|
||||
}
|
||||
|
||||
uint8 numberOfArguments = argumentsRequiredByOpcode[opcode];
|
||||
if (bytePointer + numberOfArguments > sizeOfTokenisedContent)
|
||||
break;
|
||||
|
||||
// generate the string
|
||||
switch (opcode) {
|
||||
default:
|
||||
detokenisedStream += "<UNKNOWN 8 bit: ";
|
||||
detokenisedStream += Common::String::format("%x", (int)opcode);
|
||||
detokenisedStream += " > ";
|
||||
debugC(1, kFreescapeDebugParser, "%s", detokenisedStream.c_str());
|
||||
error("ERROR: failed to read opcode: %x", opcode);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
detokenisedStream += "NOP ";
|
||||
currentInstruction = FCLInstruction(Token::NOP);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
break; // NOP
|
||||
case 1: // add three-byte value to score
|
||||
{
|
||||
int32 additionValue =
|
||||
tokenisedCondition[bytePointer] |
|
||||
(tokenisedCondition[bytePointer + 1] << 8) |
|
||||
(tokenisedCondition[bytePointer + 2] << 16);
|
||||
detokenisedStream += "ADDVAR";
|
||||
detokenisedStream += Common::String::format("(%d, v%d)", additionValue, k8bitVariableScore);
|
||||
currentInstruction = FCLInstruction(Token::ADDVAR);
|
||||
currentInstruction.setSource(k8bitVariableScore);
|
||||
currentInstruction.setDestination(additionValue);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer += 3;
|
||||
numberOfArguments = 0;
|
||||
} break;
|
||||
case 2: // add one-byte value to energy
|
||||
detokenisedStream += "ADDVAR ";
|
||||
detokenisedStream += Common::String::format("(%d, v%d)", (int8)tokenisedCondition[bytePointer], k8bitVariableEnergy);
|
||||
currentInstruction = FCLInstruction(Token::ADDVAR);
|
||||
currentInstruction.setSource(k8bitVariableEnergy);
|
||||
currentInstruction.setDestination((int8)tokenisedCondition[bytePointer]);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer++;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
case 19: // add one-byte value to shield
|
||||
detokenisedStream += "ADDVAR ";
|
||||
detokenisedStream += Common::String::format("(%d, v%d)", (int8)tokenisedCondition[bytePointer], k8bitVariableShield);
|
||||
currentInstruction = FCLInstruction(Token::ADDVAR);
|
||||
currentInstruction.setSource(k8bitVariableShield);
|
||||
currentInstruction.setDestination((int8)tokenisedCondition[bytePointer]);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer++;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
case 3:
|
||||
detokenisedStream += "TOGVIS (";
|
||||
currentInstruction = FCLInstruction(Token::TOGVIS);
|
||||
currentInstruction.setSource(0);
|
||||
currentInstruction.setDestination(0);
|
||||
break; // these all come in unary and binary versions,
|
||||
case 7:
|
||||
case 4:
|
||||
detokenisedStream += "VIS (";
|
||||
currentInstruction = FCLInstruction(Token::VIS);
|
||||
currentInstruction.setSource(0);
|
||||
currentInstruction.setDestination(0);
|
||||
break; // hence each getting two case statement entries
|
||||
case 8:
|
||||
case 5:
|
||||
detokenisedStream += "INVIS (";
|
||||
currentInstruction = FCLInstruction(Token::INVIS);
|
||||
currentInstruction.setSource(0);
|
||||
currentInstruction.setDestination(0);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
detokenisedStream += "ADDVAR (1, v";
|
||||
detokenisedStream += Common::String::format("%d)", tokenisedCondition[bytePointer]);
|
||||
currentInstruction = FCLInstruction(Token::ADDVAR);
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
currentInstruction.setDestination(1);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer++;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
case 10:
|
||||
detokenisedStream += "SUBVAR (1, v";
|
||||
detokenisedStream += Common::String::format("%d)", tokenisedCondition[bytePointer]);
|
||||
currentInstruction = FCLInstruction(Token::SUBVAR);
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
currentInstruction.setDestination(1);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer++;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 11: // end condition if a variable doesn't have a particular value
|
||||
detokenisedStream += "IF VAR!=? ";
|
||||
detokenisedStream += Common::String::format("(v%d, %d)", (int)tokenisedCondition[bytePointer], (int)tokenisedCondition[bytePointer + 1]);
|
||||
detokenisedStream += " THEN END ENDIF";
|
||||
currentInstruction = FCLInstruction(Token::VARNOTEQ);
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
currentInstruction.setDestination(tokenisedCondition[bytePointer + 1]);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer += 2;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
case 14: // end condition if a bit doesn't have a particular value
|
||||
detokenisedStream += "IF BIT!=? ";
|
||||
detokenisedStream += Common::String::format("(%d, %d)", (int)tokenisedCondition[bytePointer], (int)tokenisedCondition[bytePointer + 1]);
|
||||
detokenisedStream += " THEN END ENDIF";
|
||||
currentInstruction = FCLInstruction(Token::BITNOTEQ);
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
currentInstruction.setDestination(tokenisedCondition[bytePointer + 1]);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer += 2;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
case 30: // end condition if an object is invisible
|
||||
detokenisedStream += "IF INVIS? ";
|
||||
detokenisedStream += Common::String::format("(%d)", (int)tokenisedCondition[bytePointer]);
|
||||
detokenisedStream += " THEN END ENDIF";
|
||||
currentInstruction = FCLInstruction(Token::INVISQ);
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
currentInstruction.setDestination(true); // invisible
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer++;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
case 31: // end condition if an object is visible
|
||||
detokenisedStream += "IF VIS? ";
|
||||
detokenisedStream += Common::String::format("(%d)", (int)tokenisedCondition[bytePointer]);
|
||||
detokenisedStream += " THEN END ENDIF";
|
||||
currentInstruction = FCLInstruction(Token::INVISQ);
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
currentInstruction.setDestination(false); // visible
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer++;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 32: // end condition if an object is visible in another area
|
||||
detokenisedStream += "IF RINVIS? ";
|
||||
detokenisedStream += Common::String::format("(%d, %d)", (int)tokenisedCondition[bytePointer], (int)tokenisedCondition[bytePointer + 1]);
|
||||
detokenisedStream += " THEN END ENDIF";
|
||||
currentInstruction = FCLInstruction(Token::INVISQ);
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
currentInstruction.setAdditional(tokenisedCondition[bytePointer + 1]);
|
||||
currentInstruction.setDestination(true); // invisible
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer += 2;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 33: // end condition if an object is invisible in another area
|
||||
detokenisedStream += "IF RVIS? ";
|
||||
detokenisedStream += Common::String::format("(%d, %d)", (int)tokenisedCondition[bytePointer], (int)tokenisedCondition[bytePointer + 1]);
|
||||
detokenisedStream += " THEN END ENDIF";
|
||||
currentInstruction = FCLInstruction(Token::INVISQ);
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
currentInstruction.setAdditional(tokenisedCondition[bytePointer + 1]);
|
||||
currentInstruction.setDestination(false); // visible
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer += 2;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 34: // show a message on screen
|
||||
detokenisedStream += "PRINT (";
|
||||
currentInstruction = FCLInstruction(Token::PRINT);
|
||||
break;
|
||||
|
||||
case 35:
|
||||
detokenisedStream += "SCREEN (";
|
||||
currentInstruction = FCLInstruction(Token::SCREEN);
|
||||
break;
|
||||
|
||||
case 36: // Only used in Dark Side to keep track of cristals and letters collected
|
||||
detokenisedStream += "SETFLAGS (";
|
||||
currentInstruction = FCLInstruction(Token::SETFLAGS);
|
||||
break;
|
||||
|
||||
case 37:
|
||||
detokenisedStream += "STARTANIM (";
|
||||
currentInstruction = FCLInstruction(Token::STARTANIM);
|
||||
break;
|
||||
|
||||
case 41: // Not sure about this one
|
||||
detokenisedStream += "LOOP (";
|
||||
currentInstruction = FCLInstruction(Token::LOOP);
|
||||
break;
|
||||
|
||||
case 42: // Not sure about this one
|
||||
detokenisedStream += "AGAIN";
|
||||
currentInstruction = FCLInstruction(Token::AGAIN);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 12:
|
||||
detokenisedStream += "SETBIT (";
|
||||
currentInstruction = FCLInstruction(Token::SETBIT);
|
||||
break;
|
||||
case 13:
|
||||
detokenisedStream += "CLRBIT (";
|
||||
currentInstruction = FCLInstruction(Token::CLEARBIT);
|
||||
break;
|
||||
|
||||
case 15:
|
||||
detokenisedStream += "SOUND (";
|
||||
currentInstruction = FCLInstruction(Token::SOUND);
|
||||
currentInstruction.setAdditional(false);
|
||||
break;
|
||||
case 17:
|
||||
case 16:
|
||||
detokenisedStream += "DESTROY (";
|
||||
currentInstruction = FCLInstruction(Token::DESTROY);
|
||||
break;
|
||||
case 18:
|
||||
detokenisedStream += "GOTO (";
|
||||
currentInstruction = FCLInstruction(Token::GOTO);
|
||||
break;
|
||||
|
||||
case 21:
|
||||
detokenisedStream += "SWAPJET";
|
||||
currentInstruction = FCLInstruction(Token::SWAPJET);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer++;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
/*
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
UNUSED
|
||||
*/
|
||||
|
||||
case 26:
|
||||
detokenisedStream += "REDRAW";
|
||||
currentInstruction = FCLInstruction(Token::REDRAW);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
break;
|
||||
case 27:
|
||||
detokenisedStream += "DELAY (";
|
||||
currentInstruction = FCLInstruction(Token::DELAY);
|
||||
break;
|
||||
case 28:
|
||||
detokenisedStream += "SYNCSND (";
|
||||
currentInstruction = FCLInstruction(Token::SOUND);
|
||||
currentInstruction.setAdditional(true);
|
||||
break;
|
||||
case 29:
|
||||
detokenisedStream += "TOGGLEBIT (";
|
||||
currentInstruction = FCLInstruction(Token::TOGGLEBIT);
|
||||
break;
|
||||
|
||||
case 25:
|
||||
// this should toggle border colour or the room palette
|
||||
detokenisedStream += "SPFX (";
|
||||
currentInstruction = FCLInstruction(Token::SPFX);
|
||||
if (isAmigaAtari) {
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer] >> 8);
|
||||
currentInstruction.setDestination(tokenisedCondition[bytePointer] & 0xff);
|
||||
} else {
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer] >> 4);
|
||||
currentInstruction.setDestination(tokenisedCondition[bytePointer] & 0xf);
|
||||
}
|
||||
detokenisedStream += Common::String::format("%d, %d)", currentInstruction._source, currentInstruction._destination);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
bytePointer++;
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 20:
|
||||
detokenisedStream += "SETVAR (v";
|
||||
currentInstruction = FCLInstruction(Token::SETVAR);
|
||||
break;
|
||||
|
||||
case 44:
|
||||
detokenisedStream += "ELSE ";
|
||||
currentInstruction = FCLInstruction(Token::ELSE);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 45:
|
||||
detokenisedStream += "ENDIF ";
|
||||
currentInstruction = FCLInstruction(Token::ENDIF);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
numberOfArguments = 0;
|
||||
break;
|
||||
|
||||
case 46:
|
||||
detokenisedStream += "IFGTE (v";
|
||||
currentInstruction = FCLInstruction(Token::IFGTEQ);
|
||||
break;
|
||||
|
||||
case 47:
|
||||
detokenisedStream += "IFLTE (v";
|
||||
currentInstruction = FCLInstruction(Token::IFLTEQ);
|
||||
break;
|
||||
|
||||
case 48:
|
||||
detokenisedStream += "EXECUTE (";
|
||||
currentInstruction = FCLInstruction(Token::EXECUTE);
|
||||
break;
|
||||
}
|
||||
|
||||
// if there are any regular arguments to add, do so
|
||||
if (numberOfArguments) {
|
||||
for (uint8 argumentNumber = 0; argumentNumber < numberOfArguments; argumentNumber++) {
|
||||
if (argumentNumber == 0)
|
||||
currentInstruction.setSource(tokenisedCondition[bytePointer]);
|
||||
else if (argumentNumber == 1)
|
||||
currentInstruction.setDestination(tokenisedCondition[bytePointer]);
|
||||
else
|
||||
error("Unexpected number of arguments!");
|
||||
|
||||
detokenisedStream += Common::String::format("%d", (int)tokenisedCondition[bytePointer]);
|
||||
bytePointer++;
|
||||
|
||||
if (argumentNumber < numberOfArguments - 1)
|
||||
detokenisedStream += ", ";
|
||||
}
|
||||
|
||||
detokenisedStream += ")";
|
||||
assert(currentInstruction.getType() != Token::UNKNOWN);
|
||||
conditionalInstructions->push_back(currentInstruction);
|
||||
currentInstruction = FCLInstruction(Token::UNKNOWN);
|
||||
}
|
||||
|
||||
// throw in a newline
|
||||
detokenisedStream += "\n";
|
||||
}
|
||||
|
||||
// This fails in Castle Master
|
||||
//assert(conditionalInstructions->size() > 0);
|
||||
|
||||
return detokenisedStream;
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
58
engines/freescape/language/8bitDetokeniser.h
Normal file
58
engines/freescape/language/8bitDetokeniser.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_8BITDETOKENIZER_H
|
||||
#define FREESCAPE_8BITDETOKENIZER_H
|
||||
|
||||
#include "freescape/language/instruction.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
enum {
|
||||
k8bitGameBitTravelRock = 30
|
||||
};
|
||||
|
||||
enum {
|
||||
k8bitVariableCrawling = 30,
|
||||
k8bitVariableSpiritsDestroyed = 28,
|
||||
k8bitVariableEnergy = 62,
|
||||
k8bitVariableScore = 61,
|
||||
k8bitVariableShieldDrillerTank = 60,
|
||||
k8bitVariableEnergyDrillerTank = 59,
|
||||
k8bitVariableShieldDrillerJet = 58,
|
||||
k8bitVariableEnergyDrillerJet = 57,
|
||||
k8bitMaxVariable = 64
|
||||
};
|
||||
|
||||
enum {
|
||||
kConditionalShot = 1 << 0,
|
||||
kConditionalTimeout = 1 << 1,
|
||||
kConditionalCollided = 1 << 2,
|
||||
kConditionalActivated = 1 << 3,
|
||||
};
|
||||
|
||||
extern uint8 k8bitVariableShield;
|
||||
|
||||
Common::String detokenise8bitCondition(Common::Array<uint16> &tokenisedCondition, FCLInstructionVector &instructions, bool enableActivated);
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_8BITDETOKENIZER_H
|
||||
829
engines/freescape/language/instruction.cpp
Normal file
829
engines/freescape/language/instruction.cpp
Normal file
@@ -0,0 +1,829 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
#include "freescape/sweepAABB.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
FCLInstructionVector *duplicateCondition(FCLInstructionVector *condition) {
|
||||
if (!condition)
|
||||
return nullptr;
|
||||
|
||||
FCLInstructionVector *copy = new FCLInstructionVector();
|
||||
for (uint i = 0; i < condition->size(); i++) {
|
||||
copy->push_back((*condition)[i].duplicate());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
FCLInstruction FCLInstruction::duplicate() {
|
||||
FCLInstruction copy(_type);
|
||||
copy.setSource(_source);
|
||||
copy.setDestination(_destination);
|
||||
copy.setAdditional(_additional);
|
||||
|
||||
copy._thenInstructions = duplicateCondition(_thenInstructions);
|
||||
copy._elseInstructions = duplicateCondition(_elseInstructions);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
FCLInstruction::FCLInstruction(Token::Type type_) {
|
||||
_source = 0;
|
||||
_destination = 0;
|
||||
_additional = 0;
|
||||
_type = type_;
|
||||
_thenInstructions = nullptr;
|
||||
_elseInstructions = nullptr;
|
||||
}
|
||||
|
||||
FCLInstruction::FCLInstruction() {
|
||||
_source = 0;
|
||||
_destination = 0;
|
||||
_additional = 0;
|
||||
_type = Token::UNKNOWN;
|
||||
_thenInstructions = nullptr;
|
||||
_elseInstructions = nullptr;
|
||||
}
|
||||
|
||||
void FCLInstruction::setSource(int32 source_) {
|
||||
_source = source_;
|
||||
}
|
||||
|
||||
void FCLInstruction::setAdditional(int32 additional_) {
|
||||
_additional = additional_;
|
||||
}
|
||||
|
||||
void FCLInstruction::setDestination(int32 destination_) {
|
||||
_destination = destination_;
|
||||
}
|
||||
|
||||
void FCLInstruction::setBranches(FCLInstructionVector *thenBranch, FCLInstructionVector *elseBranch) {
|
||||
_thenInstructions = thenBranch;
|
||||
_elseInstructions = elseBranch;
|
||||
}
|
||||
|
||||
Token::Type FCLInstruction::getType() const {
|
||||
return _type;
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeEntranceConditions(Entrance *entrance) {
|
||||
if (!entrance->_conditionSource.empty()) {
|
||||
_firstSound = true;
|
||||
_syncSound = false;
|
||||
|
||||
debugC(1, kFreescapeDebugCode, "Executing entrance condition with collision flag: %s", entrance->_conditionSource.c_str());
|
||||
executeCode(entrance->_condition, false, true, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
bool FreescapeEngine::executeObjectConditions(GeometricObject *obj, bool shot, bool collided, bool activated) {
|
||||
bool executed = false;
|
||||
assert(obj != nullptr);
|
||||
if (!obj->_conditionSource.empty()) {
|
||||
_firstSound = true;
|
||||
_syncSound = false;
|
||||
_objExecutingCodeSize = collided ? obj->getSize() : Math::Vector3d();
|
||||
if (collided) {
|
||||
if (!isCastle())
|
||||
clearGameBit(31); // We collided with something that has code
|
||||
debugC(1, kFreescapeDebugCode, "Executing with collision flag: %s", obj->_conditionSource.c_str());
|
||||
} else if (shot)
|
||||
debugC(1, kFreescapeDebugCode, "Executing with shot flag: %s", obj->_conditionSource.c_str());
|
||||
else if (activated) {
|
||||
if (isCastle()) // TODO: add a 3DCK check here
|
||||
clearTemporalMessages();
|
||||
debugC(1, kFreescapeDebugCode, "Executing with activated flag: %s", obj->_conditionSource.c_str());
|
||||
} else
|
||||
error("Neither shot or collided flag is set!");
|
||||
executed = executeCode(obj->_condition, shot, collided, false, activated); // TODO: check this last parameter
|
||||
}
|
||||
if (activated && !executed)
|
||||
if (!_noEffectMessage.empty())
|
||||
insertTemporaryMessage(_noEffectMessage, _countdown - 2);
|
||||
|
||||
return executed;
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeLocalGlobalConditions(bool shot, bool collided, bool timer) {
|
||||
debugC(1, kFreescapeDebugCode, "Executing room conditions");
|
||||
Common::Array<FCLInstructionVector> conditions = _currentArea->_conditions;
|
||||
Common::Array<Common::String> conditionSources = _currentArea->_conditionSources;
|
||||
|
||||
for (uint i = 0; i < conditions.size(); i++) {
|
||||
debugC(1, kFreescapeDebugCode, "%s", conditionSources[i].c_str());
|
||||
executeCode(conditions[i], shot, collided, timer, false);
|
||||
}
|
||||
|
||||
_executingGlobalCode = true;
|
||||
debugC(1, kFreescapeDebugCode, "Executing global conditions (%d)", _conditions.size());
|
||||
for (uint i = 0; i < _conditions.size(); i++) {
|
||||
debugC(1, kFreescapeDebugCode, "%s", _conditionSources[i].c_str());
|
||||
executeCode(_conditions[i], shot, collided, timer, false);
|
||||
}
|
||||
_executingGlobalCode = false;
|
||||
}
|
||||
|
||||
bool FreescapeEngine::executeCode(FCLInstructionVector &code, bool shot, bool collided, bool timer, bool activated) {
|
||||
int ip = 0;
|
||||
bool skip = false;
|
||||
int skipDepth = 0;
|
||||
int conditionalDepth = 0;
|
||||
bool executed = false;
|
||||
int loopIterations = 0;
|
||||
int loopHead = -1;
|
||||
int codeSize = code.size();
|
||||
|
||||
if (codeSize == 0) {
|
||||
assert(isCastle()); // Only seems to happen in Castle Master (magister room)
|
||||
debugC(1, kFreescapeDebugCode, "Code is empty!");
|
||||
return false;
|
||||
}
|
||||
|
||||
while (ip <= codeSize - 1) {
|
||||
FCLInstruction &instruction = code[ip];
|
||||
debugC(1, kFreescapeDebugCode, "Executing ip: %d with type %d in code with size: %d. Skip flag is: %d", ip, instruction.getType(), codeSize, skip);
|
||||
|
||||
if (instruction.isConditional()) {
|
||||
conditionalDepth++;
|
||||
debugC(1, kFreescapeDebugCode, "Conditional depth increased to: %d", conditionalDepth);
|
||||
} else if (instruction.getType() == Token::ENDIF) {
|
||||
conditionalDepth--;
|
||||
debugC(1, kFreescapeDebugCode, "Conditional depth decreased to: %d", conditionalDepth);
|
||||
}
|
||||
|
||||
if (skip) {
|
||||
if (instruction.getType() == Token::ELSE) {
|
||||
debugC(1, kFreescapeDebugCode, "Else found, skip depth: %d, conditional depth: %d", skipDepth, conditionalDepth);
|
||||
if (skipDepth == conditionalDepth - 1) {
|
||||
skip = false;
|
||||
}
|
||||
} else if (instruction.getType() == Token::ENDIF) {
|
||||
debugC(1, kFreescapeDebugCode, "Endif found, skip depth: %d, conditional depth: %d", skipDepth, conditionalDepth);
|
||||
if (skipDepth == conditionalDepth) {
|
||||
skip = false;
|
||||
}
|
||||
}
|
||||
debugC(1, kFreescapeDebugCode, "Instruction skipped!");
|
||||
ip++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (instruction.getType() != Token::CONDITIONAL && !instruction.isConditional())
|
||||
executed = true;
|
||||
|
||||
switch (instruction.getType()) {
|
||||
default:
|
||||
error("Instruction %x at ip: %d not implemented!", instruction.getType(), ip);
|
||||
break;
|
||||
case Token::NOP:
|
||||
debugC(1, kFreescapeDebugCode, "Executing NOP at ip: %d", ip);
|
||||
break;
|
||||
|
||||
case Token::LOOP:
|
||||
loopHead = ip;
|
||||
loopIterations = instruction._source;
|
||||
debugC(1, kFreescapeDebugCode, "Starting loop with %d iterations at ip: %d", loopIterations, ip);
|
||||
break;
|
||||
|
||||
case Token::AGAIN:
|
||||
if (loopIterations > 1) {
|
||||
loopIterations--;
|
||||
ip = loopHead;
|
||||
debugC(1, kFreescapeDebugCode, "Looping again, %d iterations left, jumping to ip: %d", loopIterations, ip);
|
||||
} else if (loopIterations == 1) {
|
||||
loopIterations--;
|
||||
debugC(1, kFreescapeDebugCode, "Loop finished");
|
||||
} else {
|
||||
error("AGAIN found without a matching LOOP!");
|
||||
}
|
||||
break;
|
||||
|
||||
case Token::CONDITIONAL:
|
||||
if (checkConditional(instruction, shot, collided, timer, activated))
|
||||
executed = executeCode(*instruction._thenInstructions, shot, collided, timer, activated);
|
||||
// else branch is always empty
|
||||
assert(instruction._elseInstructions == nullptr);
|
||||
break;
|
||||
|
||||
case Token::VARNOTEQ:
|
||||
if (executeEndIfNotEqual(instruction)) {
|
||||
if (isCastle()) {
|
||||
skip = true;
|
||||
skipDepth = conditionalDepth - 1;
|
||||
} else
|
||||
ip = codeSize;
|
||||
}
|
||||
break;
|
||||
case Token::IFGTEQ:
|
||||
skip = !checkIfGreaterOrEqual(instruction);
|
||||
if (skip)
|
||||
skipDepth = conditionalDepth - 1;
|
||||
break;
|
||||
|
||||
case Token::IFLTEQ:
|
||||
skip = !checkIfLessOrEqual(instruction);
|
||||
if (skip)
|
||||
skipDepth = conditionalDepth - 1;
|
||||
break;
|
||||
|
||||
|
||||
case Token::ELSE:
|
||||
skip = !skip;
|
||||
if (skip)
|
||||
skipDepth = conditionalDepth - 1;
|
||||
break;
|
||||
|
||||
case Token::ENDIF:
|
||||
skip = false;
|
||||
break;
|
||||
|
||||
case Token::SWAPJET:
|
||||
executeSwapJet(instruction);
|
||||
break;
|
||||
case Token::ADDVAR:
|
||||
executeIncrementVariable(instruction);
|
||||
break;
|
||||
case Token::SUBVAR:
|
||||
executeDecrementVariable(instruction);
|
||||
break;
|
||||
case Token::SETVAR:
|
||||
executeSetVariable(instruction);
|
||||
break;
|
||||
case Token::GOTO:
|
||||
executeGoto(instruction);
|
||||
break;
|
||||
case Token::TOGVIS:
|
||||
executeToggleVisibility(instruction);
|
||||
break;
|
||||
case Token::INVIS:
|
||||
executeMakeInvisible(instruction);
|
||||
break;
|
||||
case Token::VIS:
|
||||
executeMakeVisible(instruction);
|
||||
break;
|
||||
case Token::DESTROY:
|
||||
executeDestroy(instruction);
|
||||
break;
|
||||
case Token::REDRAW:
|
||||
executeRedraw(instruction);
|
||||
break;
|
||||
case Token::EXECUTE:
|
||||
executeExecute(instruction);
|
||||
ip = codeSize;
|
||||
break;
|
||||
case Token::DELAY:
|
||||
executeDelay(instruction);
|
||||
break;
|
||||
case Token::SOUND:
|
||||
executeSound(instruction);
|
||||
break;
|
||||
case Token::SETBIT:
|
||||
executeSetBit(instruction);
|
||||
break;
|
||||
case Token::CLEARBIT:
|
||||
executeClearBit(instruction);
|
||||
break;
|
||||
case Token::TOGGLEBIT:
|
||||
executeToggleBit(instruction);
|
||||
break;
|
||||
case Token::PRINT:
|
||||
executePrint(instruction);
|
||||
break;
|
||||
case Token::SPFX:
|
||||
executeSPFX(instruction);
|
||||
break;
|
||||
case Token::SCREEN:
|
||||
// TODO
|
||||
break;
|
||||
case Token::SETFLAGS:
|
||||
// TODO
|
||||
break;
|
||||
case Token::STARTANIM:
|
||||
executeStartAnim(instruction);
|
||||
break;
|
||||
case Token::BITNOTEQ:
|
||||
if (executeEndIfBitNotEqual(instruction)) {
|
||||
if (isCastle()) {
|
||||
skip = true;
|
||||
skipDepth = conditionalDepth - 1;
|
||||
} else
|
||||
ip = codeSize;
|
||||
}
|
||||
break;
|
||||
case Token::INVISQ:
|
||||
if (executeEndIfVisibilityIsEqual(instruction)) {
|
||||
if (isCastle()) {
|
||||
skip = true;
|
||||
skipDepth = conditionalDepth - 1;
|
||||
} else
|
||||
ip = codeSize;
|
||||
}
|
||||
break;
|
||||
}
|
||||
ip++;
|
||||
}
|
||||
return executed;
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeRedraw(FCLInstruction &instruction) {
|
||||
debugC(1, kFreescapeDebugCode, "Redrawing screen");
|
||||
uint32 delay = (100 / 15) + 1;
|
||||
if (isEclipse2() && _currentArea->getAreaID() == _startArea && _gameStateControl == kFreescapeGameStateStart)
|
||||
delay = delay * 10;
|
||||
|
||||
if (isCastle() && isSpectrum() && getGameBit(31))
|
||||
delay = delay * 15; // Slow down redraws when the final cutscene is playing
|
||||
waitInLoop(delay);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeExecute(FCLInstruction &instruction) {
|
||||
uint16 objId = instruction._source;
|
||||
debugC(1, kFreescapeDebugCode, "Executing instructions from object %d", objId);
|
||||
Object *obj = _currentArea->objectWithID(objId);
|
||||
if (!obj) {
|
||||
obj = _areaMap[255]->objectWithID(objId);
|
||||
if (!obj) {
|
||||
obj = _areaMap[255]->entranceWithID(objId);
|
||||
if (!obj) {
|
||||
debugC(1, kFreescapeDebugCode, "WARNING: executing instructions from a non-existent object %d", objId);
|
||||
return;
|
||||
}
|
||||
assert(obj);
|
||||
FCLInstructionVector &condition = ((Entrance *)obj)->_condition;
|
||||
executeCode(condition, true, true, true, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
executeObjectConditions((GeometricObject *)obj, true, true, true);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeSound(FCLInstruction &instruction) {
|
||||
stopAllSounds(_movementSoundHandle);
|
||||
_firstSound = false;
|
||||
uint16 index = instruction._source;
|
||||
bool sync = instruction._additional;
|
||||
debugC(1, kFreescapeDebugCode, "Playing sound %d", index);
|
||||
playSound(index, sync, _soundFxHandle);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeDelay(FCLInstruction &instruction) {
|
||||
uint16 delay = instruction._source;
|
||||
debugC(1, kFreescapeDebugCode, "Delaying %d * 1/50 seconds", delay);
|
||||
waitInLoop(((20 * delay) / 15) + 1);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executePrint(FCLInstruction &instruction) {
|
||||
uint16 index = instruction._source - 1;
|
||||
debugC(1, kFreescapeDebugCode, "Printing message %d: \"%s\"", index, _messagesList[index].c_str());
|
||||
_currentAreaMessages.clear();
|
||||
_currentAreaMessages.push_back(_messagesList[index]);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeSPFX(FCLInstruction &instruction) {
|
||||
uint16 src = instruction._source;
|
||||
uint16 dst = instruction._destination;
|
||||
if (isAmiga() || isAtariST()) {
|
||||
uint8 r = 0;
|
||||
uint8 g = 0;
|
||||
uint8 b = 0;
|
||||
uint32 color = 0;
|
||||
|
||||
if (src & (1 << 7)) {
|
||||
uint16 v = 0;
|
||||
color = 0;
|
||||
// Extract the color to replace from the src/dst values
|
||||
v = (src & 0x77) << 8;
|
||||
v = v | (dst & 0x70);
|
||||
v = v >> 4;
|
||||
|
||||
// Convert the color to RGB
|
||||
r = (v & 0xf00) >> 8;
|
||||
r = r << 4 | r;
|
||||
r = r & 0xff;
|
||||
|
||||
g = (v & 0xf0) >> 4;
|
||||
g = g << 4 | g;
|
||||
g = g & 0xff;
|
||||
|
||||
b = v & 0xf;
|
||||
b = b << 4 | b;
|
||||
b = b & 0xff;
|
||||
|
||||
color = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
_currentArea->remapColor(dst & 0x0f, color); // src & 0x77, dst & 0x0f
|
||||
} else if ((src & 0xf0) >> 4 == 1) {
|
||||
_gfx->readFromPalette(src & 0x0f, r, g, b);
|
||||
color = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
for (int i = 1; i < 16; i++)
|
||||
_currentArea->remapColor(i, color);
|
||||
} else if ((src & 0x0f) == 1) {
|
||||
_gfx->readFromPalette(dst & 0x0f, r, g, b);
|
||||
color = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
for (int i = 1; i < 16; i++)
|
||||
_currentArea->remapColor(i, color);
|
||||
}
|
||||
} else {
|
||||
debugC(1, kFreescapeDebugCode, "Switching palette from position %d to %d", src, dst);
|
||||
if (src == 0 && dst == 1) {
|
||||
|
||||
src = _currentArea->_usualBackgroundColor;
|
||||
dst = _currentArea->_underFireBackgroundColor;
|
||||
|
||||
if (_renderMode == Common::kRenderCGA)
|
||||
dst = 1;
|
||||
else if (isC64()) {
|
||||
src %= 16;
|
||||
dst %= 16;
|
||||
}
|
||||
|
||||
_currentArea->remapColor(src, dst);
|
||||
} else if (src == 0 && dst == 0)
|
||||
_currentArea->unremapColor(_currentArea->_usualBackgroundColor);
|
||||
else if (src == 15 && dst == 15) // Found in Total Eclipse (DOS)
|
||||
_currentArea->unremapColor(_currentArea->_usualBackgroundColor);
|
||||
else
|
||||
_currentArea->remapColor(src, dst);
|
||||
}
|
||||
_gfx->setColorRemaps(&_currentArea->_colorRemaps);
|
||||
executeRedraw(instruction);
|
||||
}
|
||||
|
||||
|
||||
bool FreescapeEngine::executeEndIfVisibilityIsEqual(FCLInstruction &instruction) {
|
||||
uint16 source = instruction._source;
|
||||
uint16 additional = instruction._additional;
|
||||
uint16 value = instruction._destination;
|
||||
|
||||
Object *obj = nullptr;
|
||||
if (additional == 0) {
|
||||
obj = _currentArea->objectWithID(source);
|
||||
if (!obj && isCastle())
|
||||
return (true == (value != 0));
|
||||
assert(obj);
|
||||
debugC(1, kFreescapeDebugCode, "End condition if visibility of obj with id %d is %d!", source, value);
|
||||
} else {
|
||||
debugC(1, kFreescapeDebugCode, "End condition if visibility of obj with id %d in area %d is %d!", additional, source, value);
|
||||
if (_areaMap.contains(source)) {
|
||||
obj = _areaMap[source]->objectWithID(additional);
|
||||
assert(obj);
|
||||
} else {
|
||||
assert(isDOS() && isDemo()); // Should only happen in the DOS demo
|
||||
return (value == false);
|
||||
}
|
||||
}
|
||||
|
||||
return (obj->isInvisible() == (value != 0));
|
||||
}
|
||||
|
||||
bool FreescapeEngine::checkConditional(FCLInstruction &instruction, bool shot, bool collided, bool timer, bool activated) {
|
||||
uint16 conditional = instruction._source;
|
||||
bool result = false;
|
||||
|
||||
if (conditional & kConditionalShot)
|
||||
result |= shot;
|
||||
if (conditional & kConditionalTimeout)
|
||||
result |= timer;
|
||||
if (conditional & kConditionalCollided)
|
||||
result |= collided;
|
||||
if (conditional & kConditionalActivated)
|
||||
result |= activated;
|
||||
|
||||
debugC(1, kFreescapeDebugCode, "Check if conditional %x is true: %d!", conditional, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool FreescapeEngine::checkIfGreaterOrEqual(FCLInstruction &instruction) {
|
||||
assert(instruction._destination <= 128);
|
||||
|
||||
uint16 variable = instruction._source;
|
||||
int8 value = instruction._destination;
|
||||
debugC(1, kFreescapeDebugCode, "Check if variable %d with value %d is greater or equal to %d!", variable, (int8)_gameStateVars[variable], value);
|
||||
return ((int8)_gameStateVars[variable] >= value);
|
||||
}
|
||||
|
||||
bool FreescapeEngine::checkIfLessOrEqual(FCLInstruction &instruction) {
|
||||
assert(instruction._destination <= 128);
|
||||
|
||||
uint16 variable = instruction._source;
|
||||
int8 value = instruction._destination;
|
||||
debugC(1, kFreescapeDebugCode, "Check if variable %d with value %d is less or equal to %d!", variable, (int8)_gameStateVars[variable], value);
|
||||
return ((int8)_gameStateVars[variable] <= value);
|
||||
}
|
||||
|
||||
|
||||
bool FreescapeEngine::executeEndIfNotEqual(FCLInstruction &instruction) {
|
||||
uint16 variable = instruction._source;
|
||||
uint16 value = instruction._destination;
|
||||
debugC(1, kFreescapeDebugCode, "End condition if variable %d with value %d is not equal to %d!", variable, (int8)_gameStateVars[variable], value);
|
||||
return (_gameStateVars[variable] != value);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeIncrementVariable(FCLInstruction &instruction) {
|
||||
int32 variable = instruction._source;
|
||||
int32 increment = instruction._destination;
|
||||
_gameStateVars[variable] = _gameStateVars[variable] + increment;
|
||||
if (variable == k8bitVariableScore) {
|
||||
debugC(1, kFreescapeDebugCode, "Score incremented by %d up to %d", increment, _gameStateVars[variable]);
|
||||
} else if (variable == k8bitVariableEnergy) {
|
||||
if (_gameStateVars[variable] > _maxEnergy)
|
||||
_gameStateVars[variable] = _maxEnergy;
|
||||
else if (_gameStateVars[variable] < 0)
|
||||
_gameStateVars[variable] = 0;
|
||||
debugC(1, kFreescapeDebugCode, "Energy incremented by %d up to %d", increment, _gameStateVars[variable]);
|
||||
} else if (variable == k8bitVariableShield) {
|
||||
if (_gameStateVars[variable] > _maxShield)
|
||||
_gameStateVars[variable] = _maxShield;
|
||||
else if (_gameStateVars[variable] < 0)
|
||||
_gameStateVars[variable] = 0;
|
||||
|
||||
if (increment < 0 && !isCastle())
|
||||
flashScreen(_renderMode == Common::kRenderCGA ? 1 :_currentArea->_underFireBackgroundColor);
|
||||
|
||||
debugC(1, kFreescapeDebugCode, "Shield incremented by %d up to %d", increment, _gameStateVars[variable]);
|
||||
} else {
|
||||
debugC(1, kFreescapeDebugCode, "Variable %d by %d incremented up to %d!", variable, increment, _gameStateVars[variable]);
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeDecrementVariable(FCLInstruction &instruction) {
|
||||
uint16 variable = instruction._source;
|
||||
uint16 decrement = instruction._destination;
|
||||
_gameStateVars[variable] = _gameStateVars[variable] - decrement;
|
||||
if (variable == k8bitVariableEnergy) {
|
||||
debugC(1, kFreescapeDebugCode, "Energy decrement by %d up to %d", decrement, _gameStateVars[variable]);
|
||||
} else
|
||||
debugC(1, kFreescapeDebugCode, "Variable %d by %d incremented up to %d!", variable, decrement, _gameStateVars[variable]);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeSetVariable(FCLInstruction &instruction) {
|
||||
uint16 variable = instruction._source;
|
||||
uint16 value = instruction._destination;
|
||||
_gameStateVars[variable] = value;
|
||||
if (variable == k8bitVariableEnergy)
|
||||
debugC(1, kFreescapeDebugCode, "Energy set to %d", value);
|
||||
else
|
||||
debugC(1, kFreescapeDebugCode, "Variable %d by set to %d!", variable, value);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeDestroy(FCLInstruction &instruction) {
|
||||
uint16 objectID = 0;
|
||||
uint16 areaID = _currentArea->getAreaID();
|
||||
|
||||
if (instruction._destination > 0) {
|
||||
objectID = instruction._destination;
|
||||
areaID = instruction._source;
|
||||
} else {
|
||||
objectID = instruction._source;
|
||||
}
|
||||
|
||||
debugC(1, kFreescapeDebugCode, "Destroying obj %d in area %d!", objectID, areaID);
|
||||
assert(_areaMap.contains(areaID));
|
||||
Object *obj = _areaMap[areaID]->objectWithID(objectID);
|
||||
assert(obj); // We know that an object should be there
|
||||
if (obj->isDestroyed())
|
||||
debugC(1, kFreescapeDebugCode, "WARNING: Destroying obj %d in area %d already destroyed!", objectID, areaID);
|
||||
|
||||
obj->destroy();
|
||||
obj->makeInvisible();
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeMakeInvisible(FCLInstruction &instruction) {
|
||||
uint16 objectID = 0;
|
||||
uint16 areaID = _currentArea->getAreaID();
|
||||
|
||||
if (instruction._destination > 0) {
|
||||
objectID = instruction._destination;
|
||||
areaID = instruction._source;
|
||||
} else {
|
||||
objectID = instruction._source;
|
||||
}
|
||||
|
||||
debugC(1, kFreescapeDebugCode, "Making obj %d invisible in area %d!", objectID, areaID);
|
||||
if (_areaMap.contains(areaID)) {
|
||||
Object *obj = _areaMap[areaID]->objectWithID(objectID);
|
||||
|
||||
if (!obj) {
|
||||
// Object is not in the area, but it should be invisible so we can return immediately
|
||||
return;
|
||||
/*obj = _areaMap[255]->objectWithID(objectID);
|
||||
if (!obj) {
|
||||
error("obj %d does not exists in area %d nor in the global one!", objectID, areaID);
|
||||
return;
|
||||
}
|
||||
_currentArea->addObjectFromArea(objectID, _areaMap[255]);
|
||||
obj = _areaMap[areaID]->objectWithID(objectID);*/
|
||||
}
|
||||
|
||||
assert(obj); // We assume the object was there
|
||||
obj->makeInvisible();
|
||||
} else {
|
||||
assert(isDriller() && isDOS() && isDemo());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeMakeVisible(FCLInstruction &instruction) {
|
||||
uint16 objectID = 0;
|
||||
uint16 areaID = _currentArea->getAreaID();
|
||||
|
||||
if (instruction._destination > 0) {
|
||||
objectID = instruction._destination;
|
||||
areaID = instruction._source;
|
||||
} else {
|
||||
objectID = instruction._source;
|
||||
}
|
||||
|
||||
debugC(1, kFreescapeDebugCode, "Making obj %d visible in area %d!", objectID, areaID);
|
||||
if (_areaMap.contains(areaID)) {
|
||||
Object *obj = _areaMap[areaID]->objectWithID(objectID);
|
||||
if (!obj) {
|
||||
obj = _areaMap[255]->objectWithID(objectID);
|
||||
if (!obj) {
|
||||
if (!isCastle() || !isDemo())
|
||||
error("obj %d does not exists in area %d nor in the global one!", objectID, areaID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj->getType() != kGroupType)
|
||||
_currentArea->addObjectFromArea(objectID, _areaMap[255]);
|
||||
else if (obj->_partOfGroup)
|
||||
_currentArea->addGroupFromArea(objectID, _areaMap[255]);
|
||||
obj = _areaMap[areaID]->objectWithID(objectID);
|
||||
assert(obj); // We know that an object should be there
|
||||
}
|
||||
|
||||
obj->makeVisible();
|
||||
if (!isDriller()) {
|
||||
Math::AABB boundingBox = createPlayerAABB(_position, _playerHeight);
|
||||
if (obj->_boundingBox.collides(boundingBox)) {
|
||||
_playerWasCrushed = true;
|
||||
_avoidRenderingFrames = 60 * 3;
|
||||
if (isEclipse())
|
||||
playSoundFx(2, true);
|
||||
_shootingFrames = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assert(isDOS() && isDemo()); // Should only happen in the DOS demo
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeToggleVisibility(FCLInstruction &instruction) {
|
||||
uint16 objectID = 0;
|
||||
uint16 areaID = _currentArea->getAreaID();
|
||||
|
||||
if (instruction._destination > 0) {
|
||||
objectID = instruction._destination;
|
||||
areaID = instruction._source;
|
||||
} else {
|
||||
objectID = instruction._source;
|
||||
}
|
||||
|
||||
debugC(1, kFreescapeDebugCode, "Toggling obj %d visibility in area %d!", objectID, areaID);
|
||||
Object *obj = _areaMap[areaID]->objectWithID(objectID);
|
||||
if (obj)
|
||||
obj->toggleVisibility();
|
||||
else {
|
||||
obj = _areaMap[255]->objectWithID(objectID);
|
||||
if (!obj) {
|
||||
// This happens in Driller, the ketar hangar
|
||||
warning("ERROR!: obj %d does not exists in area %d nor in the global one!", objectID, areaID);
|
||||
return;
|
||||
}
|
||||
// If an object is not in the area, it is considered to be invisible
|
||||
_currentArea->addObjectFromArea(objectID, _areaMap[255]);
|
||||
obj = _areaMap[areaID]->objectWithID(objectID);
|
||||
assert(obj); // We know that an object should be there
|
||||
obj->makeVisible();
|
||||
}
|
||||
if (!obj->isInvisible()) {
|
||||
if (!isDriller()) {
|
||||
Math::AABB boundingBox = createPlayerAABB(_position, _playerHeight);
|
||||
if (obj->_boundingBox.collides(boundingBox)) {
|
||||
_playerWasCrushed = true;
|
||||
_avoidRenderingFrames = 60 * 3;
|
||||
_shootingFrames = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeGoto(FCLInstruction &instruction) {
|
||||
uint16 areaID = instruction._source;
|
||||
uint16 entranceID = instruction._destination;
|
||||
gotoArea(areaID, entranceID);
|
||||
_gotoExecuted = true;
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeSetBit(FCLInstruction &instruction) {
|
||||
uint16 index = instruction._source; // Starts at 1
|
||||
assert(index > 0 && index <= 32);
|
||||
setGameBit(index);
|
||||
debugC(1, kFreescapeDebugCode, "Setting bit %d", index);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeClearBit(FCLInstruction &instruction) {
|
||||
uint16 index = instruction._source; // Starts at 1
|
||||
assert(index > 0 && index <= 32);
|
||||
clearGameBit(index);
|
||||
debugC(1, kFreescapeDebugCode, "Clearing bit %d", index);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeToggleBit(FCLInstruction &instruction) {
|
||||
uint16 index = instruction._source; // Starts at 1
|
||||
assert(index > 0 && index <= 32);
|
||||
toggleGameBit(index);
|
||||
debugC(1, kFreescapeDebugCode, "Toggling bit %d", index);
|
||||
}
|
||||
|
||||
bool FreescapeEngine::executeEndIfBitNotEqual(FCLInstruction &instruction) {
|
||||
uint16 index = instruction._source;
|
||||
uint16 value = instruction._destination;
|
||||
assert(index <= 32);
|
||||
debugC(1, kFreescapeDebugCode, "End condition if bit %d is not equal to %d!", index, value);
|
||||
return (getGameBit(index) != value);
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeSwapJet(FCLInstruction &instruction) {
|
||||
//playSound(15, false);
|
||||
_flyMode = !_flyMode;
|
||||
uint16 areaID = _currentArea->getAreaID();
|
||||
|
||||
if (_flyMode) {
|
||||
debugC(1, kFreescapeDebugCode, "Swaping to ship mode");
|
||||
if (areaID == 27) {
|
||||
traverseEntrance(26);
|
||||
_lastPosition = _position;
|
||||
}
|
||||
_playerHeight = 2;
|
||||
_playerHeightNumber = -1;
|
||||
|
||||
// Save tank energy and shield
|
||||
_gameStateVars[k8bitVariableEnergyDrillerTank] = _gameStateVars[k8bitVariableEnergy];
|
||||
_gameStateVars[k8bitVariableShieldDrillerTank] = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
// Restore ship energy and shield
|
||||
_gameStateVars[k8bitVariableEnergy] = _gameStateVars[k8bitVariableEnergyDrillerJet];
|
||||
_gameStateVars[k8bitVariableShield] = _gameStateVars[k8bitVariableShieldDrillerJet];
|
||||
} else {
|
||||
debugC(1, kFreescapeDebugCode, "Swaping to tank mode");
|
||||
_playerHeightNumber = 0;
|
||||
if (areaID == 27) {
|
||||
traverseEntrance(27);
|
||||
_lastPosition = _position;
|
||||
}
|
||||
|
||||
// Save shield energy and shield
|
||||
_gameStateVars[k8bitVariableEnergyDrillerJet] = _gameStateVars[k8bitVariableEnergy];
|
||||
_gameStateVars[k8bitVariableShieldDrillerJet] = _gameStateVars[k8bitVariableShield];
|
||||
|
||||
// Restore ship energy and shield
|
||||
_gameStateVars[k8bitVariableEnergy] = _gameStateVars[k8bitVariableEnergyDrillerTank];
|
||||
_gameStateVars[k8bitVariableShield] = _gameStateVars[k8bitVariableShieldDrillerTank];
|
||||
}
|
||||
// TODO: implement the rest of the changes (e.g. border)
|
||||
}
|
||||
|
||||
void FreescapeEngine::executeStartAnim(FCLInstruction &instruction) {
|
||||
uint16 objID = instruction._source;
|
||||
debugC(1, kFreescapeDebugCode, "Staring animation of object %d", objID);
|
||||
Object *obj = _currentArea->objectWithID(objID);
|
||||
assert(obj);
|
||||
Group *group = nullptr;
|
||||
if (obj->getType() == kGroupType) {
|
||||
group = (Group *)obj;
|
||||
} else {
|
||||
assert(obj->_partOfGroup);
|
||||
group = (Group *)obj->_partOfGroup;
|
||||
}
|
||||
debugC(1, kFreescapeDebugCode, "From group %d", group->getObjectID());
|
||||
if (!group->isDestroyed())
|
||||
group->start();
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace Freescape
|
||||
70
engines/freescape/language/instruction.h
Normal file
70
engines/freescape/language/instruction.h
Normal file
@@ -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 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#ifndef FREESCAPE_INSTRUCTION_H
|
||||
#define FREESCAPE_INSTRUCTION_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "freescape/language/token.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class FCLInstruction;
|
||||
typedef Common::Array<FCLInstruction> FCLInstructionVector;
|
||||
|
||||
class FCLInstruction {
|
||||
public:
|
||||
FCLInstruction();
|
||||
FCLInstruction(Token::Type type);
|
||||
void setSource(int32 source);
|
||||
void setAdditional(int32 additional);
|
||||
void setDestination(int32 destination);
|
||||
|
||||
Token::Type getType() const;
|
||||
|
||||
bool isConditional() const {
|
||||
Token::Type type = getType();
|
||||
return type == Token::Type::BITNOTEQ || type == Token::Type::VARNOTEQ || \
|
||||
type == Token::Type::IFGTEQ || type == Token::Type::IFLTEQ || \
|
||||
type == Token::Type::VAREQ || _type == Token::Type::INVISQ;
|
||||
}
|
||||
|
||||
void setBranches(FCLInstructionVector *thenBranch, FCLInstructionVector *elseBranch);
|
||||
|
||||
FCLInstruction duplicate();
|
||||
|
||||
int32 _source;
|
||||
int32 _additional;
|
||||
int32 _destination;
|
||||
|
||||
FCLInstructionVector *_thenInstructions;
|
||||
FCLInstructionVector *_elseInstructions;
|
||||
|
||||
private:
|
||||
enum Token::Type _type;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_INSTRUCTION_H
|
||||
121
engines/freescape/language/token.h
Normal file
121
engines/freescape/language/token.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#ifndef FREESCAPE_TOKEN_H
|
||||
#define FREESCAPE_TOKEN_H
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
struct Token {
|
||||
public:
|
||||
enum Type {
|
||||
ADDVAR,
|
||||
AGAIN,
|
||||
AND,
|
||||
ANDV,
|
||||
CONDITIONAL,
|
||||
DELAY,
|
||||
DESTROY,
|
||||
DESTROYEDQ,
|
||||
ELSE,
|
||||
END,
|
||||
ENDGAME,
|
||||
ENDIF,
|
||||
EXECUTE,
|
||||
GOTO,
|
||||
IF,
|
||||
INVIS,
|
||||
INVISQ,
|
||||
INCLUDE,
|
||||
LOOP,
|
||||
MODE,
|
||||
MOVE,
|
||||
MOVETO,
|
||||
NOTV,
|
||||
NOP,
|
||||
OR,
|
||||
ORV,
|
||||
GETXPOS,
|
||||
GETYPOS,
|
||||
GETZPOS,
|
||||
PRINT,
|
||||
RESTART,
|
||||
REDRAW,
|
||||
REMOVE,
|
||||
SCREEN,
|
||||
SOUND,
|
||||
SETVAR,
|
||||
SETFLAGS,
|
||||
START,
|
||||
STARTANIM,
|
||||
STOPANIM,
|
||||
SPFX,
|
||||
SUBVAR,
|
||||
SYNCSND,
|
||||
THEN,
|
||||
TOGVIS,
|
||||
TRIGANIM,
|
||||
UPDATEI,
|
||||
VAREQ,
|
||||
IFGTEQ,
|
||||
IFLTEQ,
|
||||
VISQ,
|
||||
VIS,
|
||||
WAIT,
|
||||
WAITTRIG,
|
||||
COMMA,
|
||||
OPENBRACKET,
|
||||
CLOSEBRACKET,
|
||||
CONSTANT,
|
||||
VARIABLE,
|
||||
STRINGLITERAL,
|
||||
UNKNOWN,
|
||||
ENDOFFILE,
|
||||
SETBIT,
|
||||
CLEARBIT,
|
||||
TOGGLEBIT,
|
||||
SWAPJET,
|
||||
BITNOTEQ,
|
||||
VARNOTEQ
|
||||
};
|
||||
|
||||
Type getType();
|
||||
|
||||
Token() {
|
||||
_type = UNKNOWN;
|
||||
_value = 0;
|
||||
}
|
||||
Token(Type type_) {
|
||||
_type = type_;
|
||||
_value = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
Type _type;
|
||||
int32 _value;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_TOKEN_H
|
||||
1207
engines/freescape/loaders/8bitBinaryLoader.cpp
Normal file
1207
engines/freescape/loaders/8bitBinaryLoader.cpp
Normal file
File diff suppressed because it is too large
Load Diff
109
engines/freescape/loaders/8bitImage.cpp
Normal file
109
engines/freescape/loaders/8bitImage.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/* 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/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void FreescapeEngine::renderPixels8bitBinImage(Graphics::ManagedSurface *surface, int row, int column, int pixels, int bit) {
|
||||
int mask = 0x80;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (column + i >= _screenW)
|
||||
continue;
|
||||
if ((pixels & mask) > 0) {
|
||||
int sample = surface->getPixel(column + i, row) | bit;
|
||||
surface->setPixel(column + i, row, sample);
|
||||
}
|
||||
mask >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
int FreescapeEngine::execute8bitBinImageSingleCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int column, int bit, int count) {
|
||||
int pixel = file->readByte();
|
||||
for (int i = 0; i < count; i++) {
|
||||
renderPixels8bitBinImage(surface, row, column + 8 * i, pixel, bit);
|
||||
}
|
||||
return 8 * count;
|
||||
}
|
||||
|
||||
int FreescapeEngine::execute8bitBinImageMultiCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int column, int bit, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
int pixel = file->readByte();
|
||||
renderPixels8bitBinImage(surface, row, column + 8 * i, pixel, bit);
|
||||
}
|
||||
return 8 * count;
|
||||
}
|
||||
|
||||
int FreescapeEngine::execute8bitBinImageCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int column, int bit) {
|
||||
int code = file->readByte();
|
||||
if (code >= 0x80) {
|
||||
int count = 257 - code;
|
||||
return execute8bitBinImageSingleCommand(file, surface, row, column, bit, count);
|
||||
} else {
|
||||
int count = code + 1;
|
||||
return execute8bitBinImageMultiCommand(file, surface, row, column, bit, count);
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::load8bitBinImageRowIteration(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int bit) {
|
||||
int pixels = 0;
|
||||
while (pixels < surface->w) {
|
||||
pixels += execute8bitBinImageCommand(file, surface, row, pixels, bit);
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::load8bitBinImageRow(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row) {
|
||||
int bit = 1;
|
||||
int nBits = 0;
|
||||
if (_renderMode == Common::kRenderCGA)
|
||||
nBits = 2;
|
||||
else if (_renderMode == Common::kRenderEGA)
|
||||
nBits = 4;
|
||||
else if (_renderMode == Common::kRenderHercG)
|
||||
nBits = 1;
|
||||
else
|
||||
error("Unimplemented render mode for reading images");
|
||||
|
||||
for (int i = 0; i < nBits; i++) {
|
||||
load8bitBinImageRowIteration(file, surface, row, bit);
|
||||
bit <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *FreescapeEngine::load8bitBinImage(Common::SeekableReadStream *file, int offset) {
|
||||
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
|
||||
surface->create(_screenW, _screenH, Graphics::PixelFormat::createFormatCLUT8());
|
||||
surface->fillRect(Common::Rect(0, 0, _screenW, _screenH), 0);
|
||||
|
||||
file->seek(offset);
|
||||
int imageSize = file->readUint16BE();
|
||||
int startImage = file->pos();
|
||||
|
||||
for (int row = 0; row < surface->h; row++)
|
||||
load8bitBinImageRow(file, surface, row);
|
||||
|
||||
assert(startImage + imageSize == file->pos());
|
||||
debugC(1, kFreescapeDebugParser, "Last position: %" PRIx64, file->pos());
|
||||
return surface;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Freescape
|
||||
51
engines/freescape/loaders/c64.cpp
Normal file
51
engines/freescape/loaders/c64.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/* 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/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
byte *FreescapeEngine::decompressC64RLE(byte *buffer, int *size, byte marker) {
|
||||
Common::MemoryReadWriteStream *tmp = new Common::MemoryReadWriteStream(DisposeAfterUse::NO);
|
||||
// Format is: [ Byte, Marker, Length ] or [ Byte ]
|
||||
for (int i = 0; i < *size - 1; ) {
|
||||
if (buffer[i] == marker && i > 0) {
|
||||
int length = buffer[i + 1];
|
||||
byte value = buffer[i - 1];
|
||||
if (length == 0)
|
||||
tmp->writeByte(value);
|
||||
|
||||
for (int j = 0; j < length; j++) {
|
||||
tmp->writeByte(value);
|
||||
}
|
||||
i += 2;
|
||||
} else {
|
||||
tmp->writeByte(buffer[i]);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
*size = tmp->size();
|
||||
byte *data = tmp->getData();
|
||||
delete tmp;
|
||||
return data;
|
||||
}
|
||||
|
||||
} // namespace Freescape
|
||||
222
engines/freescape/metaengine.cpp
Normal file
222
engines/freescape/metaengine.cpp
Normal file
@@ -0,0 +1,222 @@
|
||||
/* 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 "common/translation.h"
|
||||
#include "backends/keymapper/action.h"
|
||||
#include "backends/keymapper/keymap.h"
|
||||
#include "backends/keymapper/standard-actions.h"
|
||||
#include "graphics/thumbnail.h"
|
||||
#include "graphics/scaler.h"
|
||||
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/castle/castle.h"
|
||||
#include "freescape/games/dark/dark.h"
|
||||
#include "freescape/games/driller/driller.h"
|
||||
#include "freescape/games/eclipse/eclipse.h"
|
||||
#include "freescape/detection.h"
|
||||
|
||||
|
||||
static const ADExtraGuiOptionsMap optionsList[] = {
|
||||
{
|
||||
GAMEOPTION_PRERECORDED_SOUNDS,
|
||||
{
|
||||
_s("Prerecorded sounds"),
|
||||
_s("Use high-quality pre-recorded sounds instead of pc speaker emulation"),
|
||||
"prerecorded_sounds",
|
||||
true,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_EXTENDED_TIMER,
|
||||
{
|
||||
_s("Extended timer"),
|
||||
_s("Start the game timer at 99:59:59"),
|
||||
"extended_timer",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_AUTOMATIC_DRILLING,
|
||||
{
|
||||
_s("Automatic drilling"),
|
||||
_s("Allow to successfully drill in any part of the area in Driller"),
|
||||
"automatic_drilling",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_DISABLE_DEMO_MODE,
|
||||
{
|
||||
_s("Disable demo mode"),
|
||||
_s("Never activate demo mode"),
|
||||
"disable_demo_mode",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_DISABLE_SENSORS,
|
||||
{
|
||||
_s("Disable sensors"),
|
||||
_s("Sensors will not shoot the player"),
|
||||
"disable_sensors",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_DISABLE_SENSORS,
|
||||
{
|
||||
_s("Disable falling"),
|
||||
_s("Player cannot fall over edges"),
|
||||
"disable_falling",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_INVERT_Y,
|
||||
{
|
||||
_s("Invert Y-axis on mouse"),
|
||||
_s("Use alternative camera controls"),
|
||||
"invert_y",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_AUTHENTIC_GRAPHICS,
|
||||
{
|
||||
_s("Authentic graphics"),
|
||||
_s("Keep graphics as close as possible to the original"),
|
||||
"authentic_graphics",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_TRAVEL_ROCK,
|
||||
{
|
||||
_s("Enable rock travel"),
|
||||
_s("Enable traveling using a rock shoot at start"),
|
||||
"rock_travel",
|
||||
false,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
GAMEOPTION_MODERN_MOVEMENT,
|
||||
{
|
||||
_s("Smoother movement"),
|
||||
_s("Use smoother movements instead of discrete steps"),
|
||||
"smooth_movement",
|
||||
true,
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
AD_EXTRA_GUI_OPTIONS_TERMINATOR
|
||||
};
|
||||
|
||||
class FreescapeMetaEngine : public AdvancedMetaEngine<ADGameDescription> {
|
||||
public:
|
||||
const char *getName() const override {
|
||||
return "freescape";
|
||||
}
|
||||
|
||||
const ADExtraGuiOptionsMap *getAdvancedExtraGuiOptions() const override {
|
||||
return optionsList;
|
||||
}
|
||||
|
||||
Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const override;
|
||||
void getSavegameThumbnail(Graphics::Surface &thumb) override;
|
||||
Common::KeymapArray initKeymaps(const char *target) const override;
|
||||
};
|
||||
|
||||
Common::Error FreescapeMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const {
|
||||
if (Common::String(gd->gameId) == "driller" || Common::String(gd->gameId) == "spacestationoblivion") {
|
||||
*engine = (Engine *)new Freescape::DrillerEngine(syst, gd);
|
||||
} else if (Common::String(gd->gameId) == "darkside") {
|
||||
*engine = (Engine *)new Freescape::DarkEngine(syst, gd);
|
||||
} else if (Common::String(gd->gameId) == "totaleclipse" || Common::String(gd->gameId) == "totaleclipse2") {
|
||||
*engine = (Engine *)new Freescape::EclipseEngine(syst, gd);
|
||||
} else if (Common::String(gd->gameId) == "castlemaster") {
|
||||
*engine = (Engine *)new Freescape::CastleEngine(syst, gd);
|
||||
} else
|
||||
*engine = new Freescape::FreescapeEngine(syst, gd);
|
||||
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
Common::KeymapArray FreescapeMetaEngine::initKeymaps(const char *target) const {
|
||||
using namespace Freescape;
|
||||
|
||||
FreescapeEngine *engine = (Freescape::FreescapeEngine *)g_engine;
|
||||
Common::Keymap *engineKeyMap = new Common::Keymap(Common::Keymap::kKeymapTypeGame, "freescape", "Freescape game");
|
||||
Common::Keymap *infoScreenKeyMap = new Common::Keymap(Common::Keymap::kKeymapTypeGame, "infoscreen-keymap", "Information screen keymapping");
|
||||
|
||||
if (engine)
|
||||
engine->initKeymaps(engineKeyMap, infoScreenKeyMap, target);
|
||||
|
||||
Common::KeymapArray keymaps(2);
|
||||
keymaps[0] = engineKeyMap;
|
||||
keymaps[1] = infoScreenKeyMap;
|
||||
|
||||
return keymaps;
|
||||
}
|
||||
|
||||
void FreescapeMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
|
||||
Freescape::FreescapeEngine *engine = (Freescape::FreescapeEngine *)g_engine;
|
||||
assert(engine->_savedScreen);
|
||||
Graphics::Surface *scaledSavedScreen = scale(*engine->_savedScreen, kThumbnailWidth, kThumbnailHeight2);
|
||||
assert(scaledSavedScreen);
|
||||
thumb.copyFrom(*scaledSavedScreen);
|
||||
|
||||
scaledSavedScreen->free();
|
||||
delete scaledSavedScreen;
|
||||
}
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
bool FreescapeEngine::isDemo() const {
|
||||
return (bool)(_gameDescription->flags & ADGF_DEMO);
|
||||
}
|
||||
|
||||
} // namespace Freescape
|
||||
|
||||
#if PLUGIN_ENABLED_DYNAMIC(FREESCAPE)
|
||||
REGISTER_PLUGIN_DYNAMIC(FREESCAPE, PLUGIN_TYPE_ENGINE, FreescapeMetaEngine);
|
||||
#else
|
||||
REGISTER_PLUGIN_STATIC(FREESCAPE, PLUGIN_TYPE_ENGINE, FreescapeMetaEngine);
|
||||
#endif
|
||||
85
engines/freescape/module.mk
Normal file
85
engines/freescape/module.mk
Normal file
@@ -0,0 +1,85 @@
|
||||
MODULE := engines/freescape
|
||||
|
||||
MODULE_OBJS := \
|
||||
area.o \
|
||||
assets.o \
|
||||
font.o \
|
||||
events.o \
|
||||
demo.o \
|
||||
doodle.o \
|
||||
freescape.o \
|
||||
games/castle/castle.o \
|
||||
games/castle/amiga.o \
|
||||
games/castle/cpc.o \
|
||||
games/castle/dos.o \
|
||||
games/castle/zx.o \
|
||||
games/dark/amiga.o \
|
||||
games/dark/atari.o \
|
||||
games/dark/c64.o \
|
||||
games/dark/cpc.o \
|
||||
games/dark/dark.o \
|
||||
games/dark/dos.o \
|
||||
games/dark/zx.o \
|
||||
games/driller/amiga.o \
|
||||
games/driller/atari.o \
|
||||
games/driller/c64.o \
|
||||
games/driller/c64.music.o \
|
||||
games/driller/cpc.o \
|
||||
games/driller/dos.o \
|
||||
games/driller/driller.o \
|
||||
games/driller/zx.o \
|
||||
games/eclipse/atari.o \
|
||||
games/eclipse/c64.o \
|
||||
games/eclipse/dos.o \
|
||||
games/eclipse/eclipse.o \
|
||||
games/eclipse/cpc.o \
|
||||
games/eclipse/zx.o \
|
||||
games/palettes.o \
|
||||
gfx.o \
|
||||
loaders/8bitImage.o \
|
||||
loaders/8bitBinaryLoader.o \
|
||||
loaders/c64.o \
|
||||
language/8bitDetokeniser.o \
|
||||
language/instruction.o \
|
||||
metaengine.o \
|
||||
movement.o \
|
||||
objects/geometricobject.o \
|
||||
objects/group.o \
|
||||
objects/sensor.o \
|
||||
sweepAABB.o \
|
||||
sound.o \
|
||||
ui.o \
|
||||
unpack.o
|
||||
|
||||
ifdef USE_TINYGL
|
||||
MODULE_OBJS += \
|
||||
gfx_tinygl.o \
|
||||
gfx_tinygl_texture.o
|
||||
endif
|
||||
|
||||
ifdef USE_OPENGL_SHADERS
|
||||
MODULE_OBJS += \
|
||||
gfx_opengl_shaders.o
|
||||
endif
|
||||
|
||||
ifdef USE_OPENGL
|
||||
MODULE_OBJS += \
|
||||
gfx_opengl.o \
|
||||
gfx_opengl_texture.o
|
||||
endif
|
||||
|
||||
|
||||
MODULE_DIRS += \
|
||||
engines/freescape
|
||||
|
||||
|
||||
# This module can be built as a plugin
|
||||
ifeq ($(ENABLE_FREESCAPE), DYNAMIC_PLUGIN)
|
||||
PLUGIN := 1
|
||||
endif
|
||||
|
||||
# Include common rules
|
||||
include $(srcdir)/rules.mk
|
||||
|
||||
# Detection objects
|
||||
DETECT_OBJS += $(MODULE)/detection.o
|
||||
669
engines/freescape/movement.cpp
Normal file
669
engines/freescape/movement.cpp
Normal file
@@ -0,0 +1,669 @@
|
||||
/* 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 "common/translation.h"
|
||||
|
||||
#include "backends/keymapper/action.h"
|
||||
#include "backends/keymapper/keymap.h"
|
||||
#include "backends/keymapper/standard-actions.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void FreescapeEngine::initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) {
|
||||
Common::Action *act;
|
||||
|
||||
act = new Common::Action(Common::kStandardActionMoveUp, _("Up"));
|
||||
act->setCustomEngineActionEvent(kActionMoveUp);
|
||||
act->addDefaultInputMapping("UP");
|
||||
act->addDefaultInputMapping("JOY_UP");
|
||||
act->addDefaultInputMapping("o");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action(Common::kStandardActionMoveDown, _("Down"));
|
||||
act->setCustomEngineActionEvent(kActionMoveDown);
|
||||
act->addDefaultInputMapping("DOWN");
|
||||
act->addDefaultInputMapping("JOY_DOWN");
|
||||
act->addDefaultInputMapping("k");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action(Common::kStandardActionMoveLeft, _("Strafe left"));
|
||||
act->setCustomEngineActionEvent(kActionMoveLeft);
|
||||
act->addDefaultInputMapping("LEFT");
|
||||
act->addDefaultInputMapping("JOY_LEFT");
|
||||
// act->addDefaultInputMapping("q");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action(Common::kStandardActionMoveRight, _("Strafe right"));
|
||||
act->setCustomEngineActionEvent(kActionMoveRight);
|
||||
act->addDefaultInputMapping("RIGHT");
|
||||
act->addDefaultInputMapping("JOY_RIGHT");
|
||||
// act->addDefaultInputMapping("w");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("SHOOT", _("Shoot"));
|
||||
act->setCustomEngineActionEvent(kActionShoot);
|
||||
act->addDefaultInputMapping("JOY_A");
|
||||
act->addDefaultInputMapping("KP5");
|
||||
act->addDefaultInputMapping("5");
|
||||
act->addDefaultInputMapping("KP0");
|
||||
act->addDefaultInputMapping("0");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("ROTUP", _("Rotate up"));
|
||||
act->setCustomEngineActionEvent(kActionRotateUp);
|
||||
act->addDefaultInputMapping("p");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("ROTDN", _("Rotate down"));
|
||||
act->setCustomEngineActionEvent(kActionRotateDown);
|
||||
act->addDefaultInputMapping("l");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("TURNB", _("Turn back"));
|
||||
act->setCustomEngineActionEvent(kActionTurnBack);
|
||||
act->addDefaultInputMapping("u");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("SKIP", _("Skip"));
|
||||
act->setCustomEngineActionEvent(kActionSkip);
|
||||
act->addDefaultInputMapping("SPACE");
|
||||
act->addDefaultInputMapping("RETURN");
|
||||
act->addDefaultInputMapping("JOY_X");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
// I18N: Toggles between cursor lock modes, switching between free cursor movement and camera/head movement.
|
||||
act = new Common::Action("SWITCH", _("Change mode"));
|
||||
act->setCustomEngineActionEvent(kActionChangeMode);
|
||||
act->addDefaultInputMapping("SPACE");
|
||||
act->addDefaultInputMapping("JOY_X");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("ESCAPE", _("Escape"));
|
||||
act->setCustomEngineActionEvent(kActionEscape);
|
||||
act->addDefaultInputMapping("ESCAPE");
|
||||
engineKeyMap->addAction(act);
|
||||
|
||||
act = new Common::Action("MENU", _("Info menu"));
|
||||
act->setCustomEngineActionEvent(kActionInfoMenu);
|
||||
act->addDefaultInputMapping("i");
|
||||
act->addDefaultInputMapping("JOY_GUIDE");
|
||||
engineKeyMap->addAction(act);
|
||||
}
|
||||
|
||||
Math::AABB createPlayerAABB(Math::Vector3d const position, int playerHeight, float reductionHeight = 0.0f) {
|
||||
Math::Vector3d v1(position.x() + 1, position.y() - playerHeight * reductionHeight - 1, position.z() + 1);
|
||||
Math::Vector3d v2(position.x() - 1, position.y() - playerHeight, position.z() - 1);
|
||||
|
||||
Math::AABB boundingBox(v1, v2);
|
||||
|
||||
boundingBox.expand(v1);
|
||||
boundingBox.expand(v2);
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
void FreescapeEngine::gotoArea(uint16 areaID, int entranceID) {
|
||||
error("Function \"%s\" not implemented", __FUNCTION__);
|
||||
}
|
||||
|
||||
void FreescapeEngine::traverseEntrance(uint16 entranceID) {
|
||||
Entrance *entrance = (Entrance *)_currentArea->entranceWithID(entranceID);
|
||||
assert(entrance);
|
||||
|
||||
int scale = _currentArea->getScale();
|
||||
assert(scale > 0);
|
||||
|
||||
Math::Vector3d rotation = entrance->getRotation();
|
||||
_position = entrance->getOrigin();
|
||||
|
||||
if (_position.x() < 0) {
|
||||
assert(isCastle());
|
||||
_position.x() = _lastPosition.x();
|
||||
}
|
||||
|
||||
if (_position.y() < 0) {
|
||||
assert(isCastle());
|
||||
_position.y() = _lastPosition.y();
|
||||
}
|
||||
|
||||
if (_position.z() < 0) {
|
||||
assert(isCastle());
|
||||
_position.z() = _lastPosition.z();
|
||||
}
|
||||
|
||||
// TODO: verify if this is needed
|
||||
/*if (scale == 1) {
|
||||
_position.x() = _position.x() + 16;
|
||||
_position.z() = _position.z() + 16;
|
||||
} else if (scale == 5) {
|
||||
_position.x() = _position.x() + 4;
|
||||
_position.z() = _position.z() + 4;
|
||||
}*/
|
||||
|
||||
if (rotation.x() >= 0 && rotation.y() >= 0 && rotation.z() >= 0) {
|
||||
_pitch = rotation.x();
|
||||
float y = rotation.y();
|
||||
|
||||
// Adjust _yaw based on normalized angle
|
||||
if (y >= 0 && y < 90)
|
||||
_yaw = 90 - y; // 0 to 90 maps to 90 to 0 (yaw should be 90 to 0)
|
||||
else if (y >= 90 && y <= 180)
|
||||
_yaw = 450 - y; // 90 to 180 maps to 360 to 270 (yaw should be 360 to 270)
|
||||
else if (y > 180 && y <= 225)
|
||||
_yaw = y; // 180 to 225 maps to 180 to 225 (yaw should be 180 to 225)
|
||||
else if (y > 225 && y < 270)
|
||||
_yaw = y - 90; // 180 to 270 maps to 90 to 0 (yaw should be 90 to 0)
|
||||
else
|
||||
_yaw = 360 + 90 - y; // 270 to 360 maps to 90 to 180 (yaw should be 90 to 180)
|
||||
|
||||
_roll = rotation.z();
|
||||
}
|
||||
|
||||
debugC(1, kFreescapeDebugMove, "entrace position: %f %f %f", _position.x(), _position.y(), _position.z());
|
||||
// Set the player height
|
||||
_playerHeight = 0;
|
||||
changePlayerHeight(_playerHeightNumber);
|
||||
debugC(1, kFreescapeDebugMove, "player height: %d", _playerHeight);
|
||||
|
||||
_sensors = _currentArea->getSensors();
|
||||
_gfx->_scale = _currentArea->_scale;
|
||||
}
|
||||
|
||||
void FreescapeEngine::activate() {
|
||||
Common::Point center(_viewArea.left + _viewArea.width() / 2, _viewArea.top + _viewArea.height() / 2);
|
||||
// Convert to normalized coordinates [-1, 1]
|
||||
float ndcX = (2.0f * (_crossairPosition.x - _viewArea.left) / _viewArea.width()) - 1.0f;
|
||||
float ndcY = 1.0f - (2.0f * (_crossairPosition.y - _viewArea.top) / _viewArea.height());
|
||||
|
||||
// Calculate angular offsets using perspective projection
|
||||
float fovHorizontalRad = (float)(75.0f * M_PI / 180.0f);
|
||||
float aspectRatio = isCastle() ? 1.6 : 2.18;
|
||||
float fovVerticalRad = 2.0f * atan(tan(fovHorizontalRad / 2.0f) / aspectRatio);
|
||||
|
||||
// Convert NDC to angle offset
|
||||
float angleOffsetX = atan(ndcX * tan(fovHorizontalRad / 2.0f)) * 180.0f / M_PI;
|
||||
float angleOffsetY = atan(ndcY * tan(fovVerticalRad / 2.0f)) * 180.0f / M_PI;
|
||||
|
||||
Math::Vector3d direction = directionToVector(_pitch + angleOffsetY, _yaw - angleOffsetX, false);
|
||||
Math::Ray ray(_position, direction);
|
||||
Object *interacted = _currentArea->checkCollisionRay(ray, 1250.0 / _currentArea->getScale());
|
||||
if (interacted) {
|
||||
GeometricObject *gobj = (GeometricObject *)interacted;
|
||||
debugC(1, kFreescapeDebugMove, "Interact with object %d with flags %x", gobj->getObjectID(), gobj->getObjectFlags());
|
||||
|
||||
if (!gobj->_conditionSource.empty())
|
||||
debugC(1, kFreescapeDebugMove, "Must use interact = true when executing: %s", gobj->_conditionSource.c_str());
|
||||
|
||||
executeObjectConditions(gobj, false, false, true);
|
||||
} else {
|
||||
if (!_outOfReachMessage.empty()) {
|
||||
clearTemporalMessages();
|
||||
insertTemporaryMessage(_outOfReachMessage, _countdown - 2);
|
||||
}
|
||||
}
|
||||
//executeLocalGlobalConditions(true, false, false); // Only execute "on shot" room/global conditions
|
||||
}
|
||||
|
||||
|
||||
void FreescapeEngine::shoot() {
|
||||
if (_shootingFrames > 0) // No more than one shot at a time
|
||||
return;
|
||||
|
||||
playSound(_soundIndexShoot, false, _movementSoundHandle);
|
||||
g_system->delayMillis(2);
|
||||
_shootingFrames = 10;
|
||||
|
||||
// Convert to normalized coordinates [-1, 1]
|
||||
float ndcX = (2.0f * (_crossairPosition.x - _viewArea.left) / _viewArea.width()) - 1.0f;
|
||||
float ndcY = 1.0f - (2.0f * (_crossairPosition.y - _viewArea.top) / _viewArea.height());
|
||||
|
||||
// Calculate angular offsets using perspective projection
|
||||
float fovHorizontalRad = (float)(75.0f * M_PI / 180.0f);
|
||||
float aspectRatio = isCastle() ? 1.6 : 2.18;
|
||||
float fovVerticalRad = 2.0f * atan(tan(fovHorizontalRad / 2.0f) / aspectRatio);
|
||||
|
||||
// Convert NDC to angle offset
|
||||
float angleOffsetX = atan(ndcX * tan(fovHorizontalRad / 2.0f)) * 180.0f / M_PI;
|
||||
float angleOffsetY = atan(ndcY * tan(fovVerticalRad / 2.0f)) * 180.0f / M_PI;
|
||||
|
||||
Math::Vector3d direction = directionToVector(_pitch + angleOffsetY, _yaw - angleOffsetX, false);
|
||||
Math::Ray ray(_position, direction);
|
||||
Object *shot = _currentArea->checkCollisionRay(ray, 8192);
|
||||
if (shot) {
|
||||
GeometricObject *gobj = (GeometricObject *)shot;
|
||||
debugC(1, kFreescapeDebugMove, "Shot object %d with flags %x", gobj->getObjectID(), gobj->getObjectFlags());
|
||||
|
||||
if (!gobj->_conditionSource.empty())
|
||||
debugC(1, kFreescapeDebugMove, "Must use shot = true when executing: %s", gobj->_conditionSource.c_str());
|
||||
|
||||
_delayedShootObject = gobj;
|
||||
}
|
||||
|
||||
executeLocalGlobalConditions(true, false, false); // Only execute "on shot" room/global conditions
|
||||
}
|
||||
|
||||
void FreescapeEngine::changeAngle(int offset, bool wrapAround) {
|
||||
_angleRotationIndex = _angleRotationIndex + offset;
|
||||
|
||||
if (_angleRotationIndex < 0) {
|
||||
if (wrapAround)
|
||||
_angleRotationIndex = int(_angleRotations.size()) - 1;
|
||||
else
|
||||
_angleRotationIndex = 0;
|
||||
} else if (_angleRotationIndex >= int(_angleRotations.size())) {
|
||||
if (wrapAround)
|
||||
_angleRotationIndex = 0;
|
||||
else
|
||||
_angleRotationIndex = int(_angleRotations.size()) - 1;
|
||||
}
|
||||
|
||||
_angleRotationIndex = _angleRotationIndex % int(_angleRotations.size());
|
||||
}
|
||||
|
||||
void FreescapeEngine::changePlayerHeight(int index) {
|
||||
int scale = _currentArea->getScale();
|
||||
|
||||
_position.setValue(1, _position.y() - _playerHeight);
|
||||
_playerHeight = 32 * (index + 1) - 16 / float(scale);
|
||||
assert(_playerHeight > 0);
|
||||
_position.setValue(1, _position.y() + _playerHeight);
|
||||
}
|
||||
|
||||
void FreescapeEngine::changeStepSize() {
|
||||
_playerStepIndex++;
|
||||
_playerStepIndex = _playerStepIndex % int(_playerSteps.size());
|
||||
}
|
||||
|
||||
void FreescapeEngine::increaseStepSize() {
|
||||
if (_playerStepIndex == int(_playerSteps.size()) - 1)
|
||||
return;
|
||||
|
||||
_playerStepIndex++;
|
||||
}
|
||||
|
||||
void FreescapeEngine::decreaseStepSize() {
|
||||
if (_playerStepIndex == 0)
|
||||
return;
|
||||
|
||||
_playerStepIndex--;
|
||||
}
|
||||
|
||||
bool FreescapeEngine::rise() {
|
||||
bool result = false;
|
||||
debugC(1, kFreescapeDebugMove, "playerHeightNumber: %d", _playerHeightNumber);
|
||||
int previousAreaID = _currentArea->getAreaID();
|
||||
if (_flyMode) {
|
||||
Math::Vector3d destination = _position;
|
||||
destination.y() = destination.y() + _playerSteps[_playerStepIndex];
|
||||
resolveCollisions(destination);
|
||||
} else {
|
||||
if (_playerHeightNumber >= _playerHeightMaxNumber)
|
||||
return result;
|
||||
|
||||
_playerHeightNumber++;
|
||||
changePlayerHeight(_playerHeightNumber);
|
||||
|
||||
Math::AABB boundingBox = createPlayerAABB(_position, _playerHeight);
|
||||
ObjectArray objs = _currentArea->checkCollisions(boundingBox);
|
||||
bool collided = objs.size() > 0;
|
||||
if (collided) {
|
||||
if (_currentArea->getAreaID() == previousAreaID) {
|
||||
_playerHeightNumber--;
|
||||
changePlayerHeight(_playerHeightNumber);
|
||||
if (!isCastle())
|
||||
setGameBit(31);
|
||||
}
|
||||
} else
|
||||
result = true;
|
||||
}
|
||||
checkIfStillInArea();
|
||||
_lastPosition = _position;
|
||||
debugC(1, kFreescapeDebugMove, "new player position: %f, %f, %f", _position.x(), _position.y(), _position.z());
|
||||
executeMovementConditions();
|
||||
return result;
|
||||
}
|
||||
|
||||
void FreescapeEngine::lower() {
|
||||
debugC(1, kFreescapeDebugMove, "playerHeightNumber: %d", _playerHeightNumber);
|
||||
if (_flyMode) {
|
||||
Math::Vector3d destination = _position;
|
||||
destination.y() = destination.y() - _playerSteps[_playerStepIndex];
|
||||
resolveCollisions(destination);
|
||||
} else {
|
||||
if (_playerHeightNumber == 0)
|
||||
return;
|
||||
|
||||
_playerHeightNumber--;
|
||||
changePlayerHeight(_playerHeightNumber);
|
||||
}
|
||||
checkIfStillInArea();
|
||||
_lastPosition = _position;
|
||||
debugC(1, kFreescapeDebugMove, "new player position: %f, %f, %f", _position.x(), _position.y(), _position.z());
|
||||
executeMovementConditions();
|
||||
}
|
||||
|
||||
void FreescapeEngine::checkIfStillInArea() {
|
||||
int maxPositiveDistance = 8192;
|
||||
int maxNegativeDistance = 0;
|
||||
|
||||
if (_currentArea->isOutside()) {
|
||||
maxPositiveDistance = 16384;
|
||||
maxNegativeDistance = -16384;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (_position.getValue(i) < maxNegativeDistance)
|
||||
_position.setValue(i, maxNegativeDistance);
|
||||
else if (_position.getValue(i) > maxPositiveDistance)
|
||||
_position.setValue(i, maxPositiveDistance);
|
||||
}
|
||||
if (_position.y() >= 2016)
|
||||
_position.y() = _lastPosition.z();
|
||||
}
|
||||
|
||||
void FreescapeEngine::updatePlayerMovement(float deltaTime) {
|
||||
if (_smoothMovement)
|
||||
updatePlayerMovementSmooth(deltaTime);
|
||||
else
|
||||
updatePlayerMovementClassic(deltaTime);
|
||||
}
|
||||
|
||||
void FreescapeEngine::updatePlayerMovementClassic(float deltaTime) {
|
||||
if (!_moveForward && !_moveBackward && !_strafeLeft && !_strafeRight)
|
||||
return;
|
||||
|
||||
debugC(1, kFreescapeDebugMove, "old player position: %f, %f, %f", _position.x(), _position.y(), _position.z());
|
||||
int previousAreaID = _currentArea->getAreaID();
|
||||
|
||||
Math::Vector3d stepFront;
|
||||
Math::Vector3d stepRight;
|
||||
|
||||
if (_playerSteps[_playerStepIndex] > 2) {
|
||||
stepFront = _cameraFront * (float(_playerSteps[_playerStepIndex]) / 2 / _cameraFront.length());
|
||||
stepRight = _cameraRight * (float(_playerSteps[_playerStepIndex]) / 2 / _cameraRight.length());
|
||||
|
||||
stepFront.x() = floor(stepFront.x()) + 0.5;
|
||||
stepFront.z() = floor(stepFront.z()) + 0.5;
|
||||
} else {
|
||||
stepFront = _cameraFront * (float(_playerSteps[_playerStepIndex]) / _cameraFront.length());
|
||||
stepRight = _cameraRight * (float(_playerSteps[_playerStepIndex]) / _cameraRight.length());
|
||||
|
||||
stepFront.x() = ceil(stepFront.x());
|
||||
stepFront.z() = ceil(stepFront.z());
|
||||
}
|
||||
|
||||
float positionY = _position.y();
|
||||
Math::Vector3d destination = _position;
|
||||
|
||||
if (_moveForward)
|
||||
destination += stepFront;
|
||||
if (_moveBackward)
|
||||
destination -= stepFront;
|
||||
if (_strafeRight)
|
||||
destination -= stepRight;
|
||||
if (_strafeLeft)
|
||||
destination += stepRight;
|
||||
|
||||
_moveForward = false;
|
||||
_moveBackward = false;
|
||||
_strafeLeft = false;
|
||||
_strafeRight = false;
|
||||
|
||||
if (!_flyMode)
|
||||
destination.y() = positionY;
|
||||
resolveCollisions(destination);
|
||||
checkIfStillInArea();
|
||||
|
||||
_lastPosition = _position;
|
||||
debugC(1, kFreescapeDebugMove, "new player position: %f, %f, %f", _position.x(), _position.y(), _position.z());
|
||||
//debugC(1, kFreescapeDebugMove, "player height: %f", _position.y() - areaScale * _playerHeight);
|
||||
if (_currentArea->getAreaID() == previousAreaID)
|
||||
executeMovementConditions();
|
||||
_gotoExecuted = false;
|
||||
if (!isCastle())
|
||||
clearGameBit(31);
|
||||
}
|
||||
|
||||
void FreescapeEngine::updatePlayerMovementSmooth(float deltaTime) {
|
||||
if (_moveForward && !_eventManager->isActionActive(kActionMoveUp))
|
||||
_moveForward = false;
|
||||
|
||||
if (_moveBackward && !_eventManager->isActionActive(kActionMoveDown))
|
||||
_moveBackward = false;
|
||||
|
||||
if (_strafeLeft && !_eventManager->isActionActive(kActionMoveLeft))
|
||||
_strafeLeft = false;
|
||||
|
||||
if (_strafeRight && !_eventManager->isActionActive(kActionMoveRight))
|
||||
_strafeRight = false;
|
||||
|
||||
if (!_moveForward && !_moveBackward && !_strafeLeft && !_strafeRight)
|
||||
return;
|
||||
|
||||
const float moveSpeed = _playerSteps[_playerStepIndex] * 5.0f;
|
||||
Math::Vector3d moveDir;
|
||||
|
||||
if (_moveForward)
|
||||
moveDir += _cameraFront;
|
||||
else if (_moveBackward)
|
||||
moveDir -= _cameraFront;
|
||||
else if (_strafeLeft)
|
||||
moveDir += _cameraRight;
|
||||
else if (_strafeRight)
|
||||
moveDir -= _cameraRight;
|
||||
|
||||
if (_flyMode) {
|
||||
if (_moveUp)
|
||||
moveDir.y() += 1.0f;
|
||||
if (_moveDown)
|
||||
moveDir.y() -= 1.0f;
|
||||
}
|
||||
|
||||
moveDir.normalize();
|
||||
moveDir = moveDir * moveSpeed * deltaTime;
|
||||
if (moveDir.length() > 1.0f) {
|
||||
Math::Vector3d destination = _position + moveDir;
|
||||
resolveCollisions(destination);
|
||||
checkIfStillInArea();
|
||||
_lastPosition = _position;
|
||||
executeMovementConditions();
|
||||
}
|
||||
_gotoExecuted = false;
|
||||
if (!isCastle())
|
||||
clearGameBit(31);
|
||||
}
|
||||
|
||||
void FreescapeEngine::resolveCollisions(Math::Vector3d const position) {
|
||||
if (_noClipMode) {
|
||||
_position = position;
|
||||
return;
|
||||
}
|
||||
|
||||
Math::Vector3d newPosition = position;
|
||||
Math::Vector3d lastPosition = _lastPosition;
|
||||
|
||||
_gotoExecuted = false;
|
||||
bool executed = runCollisionConditions(lastPosition, newPosition);
|
||||
|
||||
if (_gotoExecuted) {
|
||||
_gotoExecuted = false;
|
||||
return;
|
||||
}
|
||||
|
||||
newPosition = _currentArea->resolveCollisions(lastPosition, newPosition, _playerHeight);
|
||||
|
||||
if (_flyMode) {
|
||||
if ((lastPosition - newPosition).length() < 1) { // Something is blocking the player
|
||||
if (!executed && !isCastle())
|
||||
setGameBit(31);
|
||||
playSound(_soundIndexCollide, false, _movementSoundHandle);
|
||||
}
|
||||
_position = newPosition;
|
||||
return;
|
||||
}
|
||||
|
||||
bool isSteppingUp = false;
|
||||
bool isSteppingDown = false;
|
||||
bool isCollidingWithWall = false;
|
||||
|
||||
// If the player has not moved, try to step up
|
||||
if ((lastPosition - newPosition).length() < 1) { // If the player has not moved
|
||||
// Try to step up
|
||||
newPosition = position;
|
||||
newPosition.y() = newPosition.y() + _stepUpDistance;
|
||||
|
||||
lastPosition = _lastPosition;
|
||||
lastPosition.y() = lastPosition.y() + _stepUpDistance;
|
||||
|
||||
newPosition = _currentArea->resolveCollisions(lastPosition, newPosition, _playerHeight);
|
||||
if (_lastPosition.y() < newPosition.y())
|
||||
isSteppingUp = true;
|
||||
|
||||
if (!executed && !isCastle())
|
||||
setGameBit(31);
|
||||
|
||||
isCollidingWithWall = true;
|
||||
}
|
||||
|
||||
// Check for falling
|
||||
Math::Vector3d fallStart = newPosition; // current standing point
|
||||
Math::Vector3d fallEnd = fallStart; // copy for downward probe
|
||||
fallEnd.y() = -8192; // probe way down below
|
||||
newPosition = _currentArea->resolveCollisions(fallStart, fallEnd, _playerHeight);
|
||||
int fallen = _lastPosition.y() - newPosition.y();
|
||||
|
||||
if (fallen > _maxFallingDistance) {
|
||||
_hasFallen = !_disableFalling;
|
||||
if (isDriller() || isDark()) {
|
||||
_roll = -90;
|
||||
_pitch = 0;
|
||||
_yaw = 0;
|
||||
changePlayerHeight(0);
|
||||
}
|
||||
_avoidRenderingFrames = 60 * 3;
|
||||
_endGameDelayTicks = 60 * 5;
|
||||
if (isEclipse()) // No need for an variable index, since these are special types of sound
|
||||
playSoundFx(0, true);
|
||||
else
|
||||
playSound(_soundIndexFall, false, _movementSoundHandle);
|
||||
|
||||
if (_hasFallen)
|
||||
stopMovement();
|
||||
}
|
||||
|
||||
if (!_hasFallen && fallen > 0) {
|
||||
isSteppingDown = true;
|
||||
// Position in Y was changed, let's re-run effects
|
||||
runCollisionConditions(_lastPosition, newPosition);
|
||||
}
|
||||
|
||||
if (isSteppingUp && (newPosition - _lastPosition).length() <= 1) {
|
||||
isCollidingWithWall = true;
|
||||
isSteppingUp = false;
|
||||
}
|
||||
|
||||
if (isSteppingDown && (newPosition - _lastPosition).length() <= 1) {
|
||||
isCollidingWithWall = true;
|
||||
isSteppingDown = false;
|
||||
}
|
||||
|
||||
if (isSteppingUp) {
|
||||
//debug("Stepping up sound!");
|
||||
if (!_mixer->isSoundHandleActive(_movementSoundHandle))
|
||||
playSound(_soundIndexStepUp, false, _movementSoundHandle);
|
||||
} else if (isSteppingDown) {
|
||||
//debug("Stepping down sound!");
|
||||
if (!_mixer->isSoundHandleActive(_movementSoundHandle))
|
||||
playSound(_soundIndexStepDown, false, _movementSoundHandle);
|
||||
} else if (isCollidingWithWall) {
|
||||
//debug("Colliding with wall sound!");
|
||||
if (!_mixer->isSoundHandleActive(_movementSoundHandle))
|
||||
playSound(_soundIndexCollide, false, _movementSoundHandle);
|
||||
}
|
||||
|
||||
_position = newPosition;
|
||||
}
|
||||
|
||||
void FreescapeEngine::stopMovement() {
|
||||
_moveForward = false;
|
||||
_moveBackward = false;
|
||||
_strafeLeft = false;
|
||||
_strafeRight = false;
|
||||
_moveUp = false;
|
||||
_moveDown = false;
|
||||
_eventManager->purgeKeyboardEvents();
|
||||
}
|
||||
|
||||
bool FreescapeEngine::runCollisionConditions(Math::Vector3d const lastPosition, Math::Vector3d const newPosition) {
|
||||
bool floorExecuted = false;
|
||||
bool wallExecuted = false;
|
||||
|
||||
GeometricObject *gobj = nullptr;
|
||||
Object *collided = nullptr;
|
||||
_gotoExecuted = false;
|
||||
|
||||
_speaker->stop();
|
||||
|
||||
Math::Ray ray(newPosition, -_upVector);
|
||||
collided = _currentArea->checkCollisionRay(ray, _playerHeight + 3);
|
||||
if (collided) {
|
||||
gobj = (GeometricObject *)collided;
|
||||
debugC(1, kFreescapeDebugMove, "Collided down with object id %d of size %f %f %f", gobj->getObjectID(), gobj->getSize().x(), gobj->getSize().y(), gobj->getSize().z());
|
||||
floorExecuted |= executeObjectConditions(gobj, false, true, false);
|
||||
}
|
||||
|
||||
if (_gotoExecuted) {
|
||||
executeMovementConditions();
|
||||
return true;
|
||||
}
|
||||
|
||||
Math::Vector3d direction = newPosition - lastPosition;
|
||||
direction.normalize();
|
||||
int rayLenght = 45;
|
||||
if (_currentArea->getScale() == 16)
|
||||
rayLenght = 20;
|
||||
else if (_currentArea->getScale() >= 5)
|
||||
rayLenght = MAX(5, 45 / (2 * _currentArea->getScale()));
|
||||
|
||||
_gotoExecuted = false;
|
||||
for (int i = 0; i <= 4; i++) {
|
||||
Math::Vector3d rayPosition = lastPosition;
|
||||
rayPosition.y() = rayPosition.y() - _playerHeight * (i / 4.0);
|
||||
ray = Math::Ray(rayPosition, direction);
|
||||
collided = _currentArea->checkCollisionRay(ray, rayLenght);
|
||||
if (collided) {
|
||||
gobj = (GeometricObject *)collided;
|
||||
debugC(1, kFreescapeDebugMove, "Collided with object id %d of size %f %f %f", gobj->getObjectID(), gobj->getSize().x(), gobj->getSize().y(), gobj->getSize().z());
|
||||
wallExecuted |= executeObjectConditions(gobj, false, true, false);
|
||||
}
|
||||
if (_gotoExecuted) {
|
||||
executeMovementConditions();
|
||||
return true;
|
||||
}
|
||||
if (wallExecuted)
|
||||
break;
|
||||
}
|
||||
|
||||
return floorExecuted || wallExecuted;
|
||||
}
|
||||
|
||||
} // namespace Freescape
|
||||
45
engines/freescape/objects/connections.h
Normal file
45
engines/freescape/objects/connections.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_CONNECTIONS_H
|
||||
#define FREESCAPE_CONNECTIONS_H
|
||||
|
||||
#include "freescape/objects/object.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class AreaConnections : public Object {
|
||||
public:
|
||||
Common::Array<byte> _connections;
|
||||
AreaConnections(const Common::Array<byte> connections_) {
|
||||
_objectID = 254;
|
||||
_connections = connections_;
|
||||
}
|
||||
|
||||
ObjectType getType() override { return ObjectType::kEntranceType; };
|
||||
void draw(Freescape::Renderer *gfx, float offset = 0.0) override { error("cannot render AreaConnections"); };
|
||||
void scale(int factor) override { /* Nothing */ };
|
||||
Object *duplicate() override { error("cannot duplicate AreaConnections"); };
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_CONNECTIONS_H
|
||||
74
engines/freescape/objects/entrance.h
Normal file
74
engines/freescape/objects/entrance.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#ifndef FREESCAPE_ENTRANCE_H
|
||||
#define FREESCAPE_ENTRANCE_H
|
||||
|
||||
#include "freescape/objects/object.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
extern FCLInstructionVector *duplicateCondition(FCLInstructionVector *condition);
|
||||
|
||||
class Entrance : public Object {
|
||||
public:
|
||||
Entrance(
|
||||
uint16 objectID_,
|
||||
const Math::Vector3d &origin_,
|
||||
const Math::Vector3d &rotation_,
|
||||
FCLInstructionVector conditionInstructions_,
|
||||
Common::String conditionSource_) {
|
||||
_objectID = objectID_;
|
||||
_origin = origin_;
|
||||
_rotation = rotation_;
|
||||
|
||||
_condition = conditionInstructions_;
|
||||
_conditionSource = conditionSource_;
|
||||
_flags = 0;
|
||||
}
|
||||
virtual ~Entrance() {}
|
||||
|
||||
bool isDrawable() override { return false; }
|
||||
bool isPlanar() override { return true; }
|
||||
void scale(int factor) override { _origin = _origin / factor; };
|
||||
Object *duplicate() override {
|
||||
FCLInstructionVector *conditionCopy = duplicateCondition(&_condition);
|
||||
assert(conditionCopy);
|
||||
Entrance *entrance = new Entrance(_objectID, _origin, _rotation, *conditionCopy, _conditionSource);
|
||||
delete conditionCopy;
|
||||
return entrance;
|
||||
};
|
||||
|
||||
ObjectType getType() override { return ObjectType::kEntranceType; };
|
||||
Math::Vector3d getRotation() { return _rotation; }
|
||||
|
||||
Common::String _conditionSource;
|
||||
FCLInstructionVector _condition;
|
||||
|
||||
void draw(Freescape::Renderer *gfx, float offset = 0.0) override { error("cannot render Entrance"); };
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_ENTRANCE_H
|
||||
481
engines/freescape/objects/geometricobject.cpp
Normal file
481
engines/freescape/objects/geometricobject.cpp
Normal file
@@ -0,0 +1,481 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#include "common/system.h"
|
||||
|
||||
#include "freescape/objects/geometricobject.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
extern FCLInstructionVector *duplicateCondition(FCLInstructionVector *condition);
|
||||
|
||||
int GeometricObject::numberOfColoursForObjectOfType(ObjectType type) {
|
||||
switch (type) {
|
||||
default:
|
||||
case kEntranceType:
|
||||
case kGroupType:
|
||||
case kSensorType:
|
||||
return 0;
|
||||
|
||||
case kLineType:
|
||||
return 2;
|
||||
|
||||
case kRectangleType:
|
||||
case kTriangleType:
|
||||
case kQuadrilateralType:
|
||||
case kPentagonType:
|
||||
case kHexagonType:
|
||||
return 2;
|
||||
|
||||
case kCubeType:
|
||||
case kEastPyramidType:
|
||||
case kWestPyramidType:
|
||||
case kUpPyramidType:
|
||||
case kDownPyramidType:
|
||||
case kNorthPyramidType:
|
||||
case kSouthPyramidType:
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
int GeometricObject::numberOfOrdinatesForType(ObjectType type) {
|
||||
switch (type) {
|
||||
default:
|
||||
case kEntranceType:
|
||||
case kGroupType:
|
||||
case kRectangleType:
|
||||
case kSensorType:
|
||||
return 0;
|
||||
|
||||
case kEastPyramidType:
|
||||
case kWestPyramidType:
|
||||
case kUpPyramidType:
|
||||
case kDownPyramidType:
|
||||
case kNorthPyramidType:
|
||||
case kSouthPyramidType:
|
||||
return 4;
|
||||
|
||||
case kLineType:
|
||||
case kTriangleType:
|
||||
case kQuadrilateralType:
|
||||
case kPentagonType:
|
||||
case kHexagonType:
|
||||
return 3 * (2 + type - kLineType);
|
||||
}
|
||||
}
|
||||
|
||||
bool GeometricObject::isPyramid(ObjectType type) {
|
||||
switch (type) {
|
||||
default:
|
||||
return false;
|
||||
|
||||
case kEastPyramidType:
|
||||
case kWestPyramidType:
|
||||
case kUpPyramidType:
|
||||
case kDownPyramidType:
|
||||
case kNorthPyramidType:
|
||||
case kSouthPyramidType:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool GeometricObject::isPolygon(ObjectType type) {
|
||||
switch (type) {
|
||||
default:
|
||||
return false;
|
||||
|
||||
case kLineType:
|
||||
case kTriangleType:
|
||||
case kQuadrilateralType:
|
||||
case kPentagonType:
|
||||
case kHexagonType:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
GeometricObject::GeometricObject(
|
||||
ObjectType type_,
|
||||
uint16 objectID_,
|
||||
uint16 flags_,
|
||||
const Math::Vector3d &origin_,
|
||||
const Math::Vector3d &size_,
|
||||
Common::Array<uint8> *colours_,
|
||||
Common::Array<uint8> *ecolours_,
|
||||
Common::Array<float> *ordinates_,
|
||||
FCLInstructionVector conditionInstructions_,
|
||||
Common::String conditionSource_) {
|
||||
_type = type_;
|
||||
assert(_type != kGroupType);
|
||||
_flags = flags_;
|
||||
|
||||
if (isDestroyed()) // If the object is destroyed, restore it
|
||||
restore();
|
||||
|
||||
if (isInitiallyInvisible())
|
||||
makeInvisible();
|
||||
else
|
||||
makeVisible();
|
||||
|
||||
_objectID = objectID_;
|
||||
_origin = origin_;
|
||||
_size = size_;
|
||||
|
||||
_colours = nullptr;
|
||||
|
||||
if (colours_)
|
||||
_colours = colours_;
|
||||
|
||||
_ecolours = nullptr;
|
||||
|
||||
if (ecolours_)
|
||||
_ecolours = ecolours_;
|
||||
|
||||
_cyclingColors = false; // This needs to be set manually
|
||||
_ordinates = nullptr;
|
||||
_initialOrdinates = nullptr;
|
||||
|
||||
if (ordinates_) {
|
||||
_ordinates = ordinates_;
|
||||
_initialOrdinates = new Common::Array<float>(*_ordinates);
|
||||
}
|
||||
_condition = conditionInstructions_;
|
||||
_conditionSource = conditionSource_;
|
||||
|
||||
if (_type == kRectangleType) {
|
||||
if ((_size.x() == 0 && _size.y() == 0) ||
|
||||
(_size.y() == 0 && _size.z() == 0) ||
|
||||
(_size.x() == 0 && _size.z() == 0)) {
|
||||
|
||||
_type = kLineType;
|
||||
assert(!_ordinates);
|
||||
_ordinates = new Common::Array<float>();
|
||||
_ordinates->push_back(_origin.x());
|
||||
_ordinates->push_back(_origin.y());
|
||||
_ordinates->push_back(_origin.z());
|
||||
|
||||
_ordinates->push_back(_origin.x() + _size.x());
|
||||
_ordinates->push_back(_origin.y() + _size.y());
|
||||
_ordinates->push_back(_origin.z() + _size.z());
|
||||
}
|
||||
} else if (isPyramid(_type))
|
||||
assert(_size.x() > 0 && _size.y() > 0 && _size.z() > 0);
|
||||
|
||||
computeBoundingBox();
|
||||
}
|
||||
|
||||
void GeometricObject::setOrigin(Math::Vector3d origin_) {
|
||||
_origin = origin_;
|
||||
computeBoundingBox();
|
||||
}
|
||||
|
||||
void GeometricObject::offsetOrigin(Math::Vector3d origin_) {
|
||||
if (isPolygon(_type)) {
|
||||
Math::Vector3d offset = origin_ - _origin;
|
||||
for (int i = 0; i < int(_ordinates->size()); i = i + 3) {
|
||||
float ordinate = 0;
|
||||
ordinate = (*_ordinates)[i];
|
||||
ordinate += offset.x();
|
||||
assert(ordinate >= 0);
|
||||
(*_ordinates)[i] = ordinate;
|
||||
|
||||
ordinate = (*_ordinates)[i + 1];
|
||||
ordinate += offset.y();
|
||||
assert(ordinate >= 0);
|
||||
(*_ordinates)[i + 1] = ordinate;
|
||||
|
||||
ordinate = (*_ordinates)[i + 2];
|
||||
ordinate += offset.z();
|
||||
assert(ordinate >= 0);
|
||||
(*_ordinates)[i + 2] = ordinate;
|
||||
}
|
||||
}
|
||||
setOrigin(origin_);
|
||||
}
|
||||
|
||||
void GeometricObject::scale(int factor) {
|
||||
_origin = _origin / factor;
|
||||
_size = _size / factor;
|
||||
if (_ordinates) {
|
||||
for (uint i = 0; i < _ordinates->size(); i++) {
|
||||
(*_ordinates)[i] = (*_ordinates)[i] / factor;
|
||||
if (_initialOrdinates)
|
||||
(*_initialOrdinates)[i] = (*_initialOrdinates)[i] / factor;
|
||||
}
|
||||
}
|
||||
computeBoundingBox();
|
||||
}
|
||||
|
||||
void GeometricObject::restoreOrdinates() {
|
||||
if (!isPolygon(_type))
|
||||
return;
|
||||
|
||||
for (uint i = 0; i < _ordinates->size(); i++)
|
||||
(*_ordinates)[i] = (*_initialOrdinates)[i];
|
||||
|
||||
computeBoundingBox();
|
||||
}
|
||||
|
||||
Object *GeometricObject::duplicate() {
|
||||
Common::Array<uint8> *coloursCopy = nullptr;
|
||||
Common::Array<uint8> *ecoloursCopy = nullptr;
|
||||
Common::Array<float> *ordinatesCopy = nullptr;
|
||||
FCLInstructionVector *conditionCopy = nullptr;
|
||||
|
||||
if (_colours)
|
||||
coloursCopy = new Common::Array<uint8>(*_colours);
|
||||
|
||||
if (_ecolours)
|
||||
ecoloursCopy = new Common::Array<uint8>(*_ecolours);
|
||||
|
||||
if (_ordinates)
|
||||
ordinatesCopy = new Common::Array<float>(*_ordinates);
|
||||
|
||||
conditionCopy = duplicateCondition(&_condition);
|
||||
assert(conditionCopy);
|
||||
|
||||
GeometricObject *copy = new GeometricObject(
|
||||
_type,
|
||||
_objectID,
|
||||
_flags,
|
||||
_origin,
|
||||
_size,
|
||||
coloursCopy,
|
||||
ecoloursCopy,
|
||||
ordinatesCopy,
|
||||
*conditionCopy,
|
||||
_conditionSource
|
||||
);
|
||||
|
||||
copy->_cyclingColors = _cyclingColors;
|
||||
return copy;
|
||||
}
|
||||
|
||||
void GeometricObject::computeBoundingBox() {
|
||||
_boundingBox = Math::AABB();
|
||||
Math::Vector3d v;
|
||||
switch (_type) {
|
||||
default:
|
||||
break;
|
||||
case kCubeType:
|
||||
_boundingBox.expand(_origin);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
v = _origin;
|
||||
v.setValue(i, v.getValue(i) + _size.getValue(i));
|
||||
_boundingBox.expand(v);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
v = _origin + _size;
|
||||
v.setValue(i, v.getValue(i) - _size.getValue(i));
|
||||
_boundingBox.expand(v);
|
||||
}
|
||||
_boundingBox.expand(_origin + _size);
|
||||
assert(_boundingBox.isValid());
|
||||
break;
|
||||
case kRectangleType:
|
||||
_boundingBox.expand(_origin);
|
||||
_boundingBox.expand(_origin + _size);
|
||||
break;
|
||||
case kLineType:
|
||||
if (!_ordinates)
|
||||
error("Ordinates needed to compute bounding box!");
|
||||
for (uint i = 0; i < _ordinates->size(); i = i + 3) {
|
||||
_boundingBox.expand(Math::Vector3d((*_ordinates)[i], (*_ordinates)[i + 1], (*_ordinates)[i + 2]));
|
||||
}
|
||||
int dx, dy, dz;
|
||||
dx = dy = dz = 0;
|
||||
if (_size.x() == 0 && _size.y() == 0) {
|
||||
dx = 2;
|
||||
dy = 2;
|
||||
} else if (_size.x() == 0 && _size.z() == 0) {
|
||||
dx = 2;
|
||||
dz = 2;
|
||||
} else if (_size.y() == 0 && _size.z() == 0) {
|
||||
dy = 2;
|
||||
dz = 2;
|
||||
}
|
||||
|
||||
for (uint i = 0; i < _ordinates->size(); i = i + 3) {
|
||||
_boundingBox.expand(Math::Vector3d((*_ordinates)[i] + dx, (*_ordinates)[i + 1] + dy, (*_ordinates)[i + 2] + dz));
|
||||
}
|
||||
|
||||
break;
|
||||
case kTriangleType:
|
||||
case kQuadrilateralType:
|
||||
case kPentagonType:
|
||||
case kHexagonType:
|
||||
if (!_ordinates)
|
||||
error("Ordinates needed to compute bounding box!");
|
||||
for (uint i = 0; i < _ordinates->size(); i = i + 3) {
|
||||
_boundingBox.expand(Math::Vector3d((*_ordinates)[i], (*_ordinates)[i + 1], (*_ordinates)[i + 2]));
|
||||
}
|
||||
break;
|
||||
|
||||
case kEastPyramidType:
|
||||
if (!_ordinates)
|
||||
error("Ordinates needed to compute bounding box!");
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, 0, _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, _size.y(), _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, _size.y(), 0));
|
||||
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), (*_ordinates)[0], (*_ordinates)[3]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), (*_ordinates)[2], (*_ordinates)[3]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), (*_ordinates)[2], (*_ordinates)[1]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), (*_ordinates)[0], (*_ordinates)[1]));
|
||||
break;
|
||||
case kWestPyramidType:
|
||||
if (!_ordinates)
|
||||
error("Ordinates needed to compute bounding box!");
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), 0, 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), _size.y(), 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), _size.y(), _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), 0, _size.z()));
|
||||
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, (*_ordinates)[0], (*_ordinates)[1]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, (*_ordinates)[2], (*_ordinates)[1]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, (*_ordinates)[2], (*_ordinates)[3]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, (*_ordinates)[0], (*_ordinates)[3]));
|
||||
break;
|
||||
case kUpPyramidType:
|
||||
if (!_ordinates)
|
||||
error("Ordinates needed to compute bounding box!");
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), 0, 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), 0, _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, 0, _size.z()));
|
||||
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[0], _size.y(), (*_ordinates)[1]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[2], _size.y(), (*_ordinates)[1]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[2], _size.y(), (*_ordinates)[3]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[0], _size.y(), (*_ordinates)[3]));
|
||||
break;
|
||||
case kDownPyramidType:
|
||||
if (!_ordinates)
|
||||
error("Ordinates needed to compute bounding box!");
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), _size.y(), 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, _size.y(), 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, _size.y(), _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), _size.y(), _size.z()));
|
||||
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[2], 0, (*_ordinates)[1]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[0], 0, (*_ordinates)[1]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[0], 0, (*_ordinates)[3]));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[2], 0, (*_ordinates)[3]));
|
||||
break;
|
||||
case kNorthPyramidType:
|
||||
if (!_ordinates)
|
||||
error("Ordinates needed to compute bounding box!");
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, _size.y(), 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), _size.y(), 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), 0, 0));
|
||||
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[0], (*_ordinates)[3], _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[2], (*_ordinates)[3], _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[2], (*_ordinates)[1], _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[0], (*_ordinates)[1], _size.z()));
|
||||
break;
|
||||
case kSouthPyramidType:
|
||||
if (!_ordinates)
|
||||
error("Ordinates needed to compute bounding box!");
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, 0, _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), 0, _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d(_size.x(), _size.y(), _size.z()));
|
||||
|
||||
_boundingBox.expand(_origin + Math::Vector3d(0, _size.y(), _size.z()));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[0], (*_ordinates)[1], 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[2], (*_ordinates)[1], 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[2], (*_ordinates)[3], 0));
|
||||
_boundingBox.expand(_origin + Math::Vector3d((*_ordinates)[0], (*_ordinates)[3], 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GeometricObject::~GeometricObject() {
|
||||
delete _colours;
|
||||
delete _ordinates;
|
||||
delete _initialOrdinates;
|
||||
}
|
||||
|
||||
// This function returns when the object is a line, but it is not a straight line
|
||||
bool GeometricObject::isLineButNotStraight() {
|
||||
if (_type != kLineType)
|
||||
return false;
|
||||
|
||||
if (!_ordinates)
|
||||
return false;
|
||||
|
||||
if (_ordinates->size() != 6)
|
||||
return false;
|
||||
|
||||
// At least two coordinates should be the same to be a straight line
|
||||
if ((*_ordinates)[0] == (*_ordinates)[3] && (*_ordinates)[1] == (*_ordinates)[4])
|
||||
return false;
|
||||
|
||||
if ((*_ordinates)[0] == (*_ordinates)[3] && (*_ordinates)[2] == (*_ordinates)[5])
|
||||
return false;
|
||||
|
||||
if ((*_ordinates)[1] == (*_ordinates)[4] && (*_ordinates)[2] == (*_ordinates)[5])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeometricObject::isDrawable() { return true; }
|
||||
bool GeometricObject::isPlanar() {
|
||||
ObjectType t = this->getType();
|
||||
return (t >= kLineType) || t == kRectangleType || !_size.x() || !_size.y() || !_size.z();
|
||||
}
|
||||
|
||||
bool GeometricObject::collides(const Math::AABB &boundingBox_) {
|
||||
if (isDestroyed() || isInvisible() || !_boundingBox.isValid() || !boundingBox_.isValid())
|
||||
return false;
|
||||
|
||||
return _boundingBox.collides(boundingBox_);
|
||||
}
|
||||
|
||||
void GeometricObject::draw(Renderer *gfx, float offset) {
|
||||
if (_cyclingColors) {
|
||||
assert(_colours);
|
||||
if (g_system->getMillis() % 10 == 0)
|
||||
for (uint i = 0; i < _colours->size(); i++) {
|
||||
(*_colours)[i] = ((*_colours)[i] + 1) % 0xf;
|
||||
if (_ecolours)
|
||||
(*_ecolours)[i] = ((*_ecolours)[i] + 1) % 0xf;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->getType() == kCubeType) {
|
||||
gfx->renderCube(_origin, _size, _colours, _ecolours, offset);
|
||||
} else if (this->getType() == kRectangleType) {
|
||||
gfx->renderRectangle(_origin, _size, _colours, _ecolours, offset);
|
||||
} else if (isPyramid(this->getType())) {
|
||||
gfx->renderPyramid(_origin, _size, _ordinates, _colours, _ecolours, this->getType());
|
||||
} else if (this->isPlanar() && _type <= 14) {
|
||||
if (this->getType() == kTriangleType)
|
||||
assert(_ordinates->size() == 9);
|
||||
|
||||
gfx->renderPolygon(_origin, _size, _ordinates, _colours, _ecolours, offset);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
80
engines/freescape/objects/geometricobject.h
Normal file
80
engines/freescape/objects/geometricobject.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#ifndef FREESCAPE_GEOMETRICOBJECT_H
|
||||
#define FREESCAPE_GEOMETRICOBJECT_H
|
||||
|
||||
#include "freescape/language/instruction.h"
|
||||
#include "freescape/objects/group.h"
|
||||
#include "freescape/objects/object.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class GeometricObject : public Object {
|
||||
public:
|
||||
static int numberOfColoursForObjectOfType(ObjectType type);
|
||||
static int numberOfOrdinatesForType(ObjectType type);
|
||||
static bool isPyramid(ObjectType type);
|
||||
static bool isPolygon(ObjectType type);
|
||||
|
||||
GeometricObject(
|
||||
ObjectType type,
|
||||
uint16 objectID,
|
||||
uint16 flags,
|
||||
const Math::Vector3d &origin,
|
||||
const Math::Vector3d &size,
|
||||
Common::Array<uint8> *colours,
|
||||
Common::Array<uint8> *ecolours,
|
||||
Common::Array<float> *ordinates,
|
||||
FCLInstructionVector conditionInstructions,
|
||||
Common::String conditionSource = "");
|
||||
virtual ~GeometricObject();
|
||||
void setOrigin(Math::Vector3d origin) override;
|
||||
void offsetOrigin(Math::Vector3d origin_);
|
||||
void restoreOrdinates();
|
||||
|
||||
Object *duplicate() override;
|
||||
void scale(int factor) override;
|
||||
void computeBoundingBox();
|
||||
bool collides(const Math::AABB &boundingBox);
|
||||
void draw(Freescape::Renderer *gfx, float offset = 0.0) override;
|
||||
bool isDrawable() override;
|
||||
bool isPlanar() override;
|
||||
bool _cyclingColors;
|
||||
|
||||
bool isLineButNotStraight();
|
||||
|
||||
Common::String _conditionSource;
|
||||
FCLInstructionVector _condition;
|
||||
|
||||
private:
|
||||
Common::Array<uint8> *_colours;
|
||||
Common::Array<uint8> *_ecolours;
|
||||
Common::Array<float> *_ordinates;
|
||||
Common::Array<float> *_initialOrdinates;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_GEOMETRICOBJECT_H
|
||||
45
engines/freescape/objects/global.h
Normal file
45
engines/freescape/objects/global.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_GLOBAL_H
|
||||
#define FREESCAPE_GLOBAL_H
|
||||
|
||||
#include "freescape/objects/object.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class GlobalStructure : public Object {
|
||||
public:
|
||||
Common::Array<byte> _structure;
|
||||
GlobalStructure(const Common::Array<byte> structure_) {
|
||||
_objectID = 255;
|
||||
_structure = structure_;
|
||||
}
|
||||
|
||||
ObjectType getType() override { return ObjectType::kEntranceType; };
|
||||
void draw(Freescape::Renderer *gfx, float offset = 0.0) override { error("cannot render GlobalStructure"); };
|
||||
void scale(int factor) override { /* Nothing */ };
|
||||
Object *duplicate() override { error("cannot duplicate GlobalStructure"); };
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_GLOBAL_H
|
||||
226
engines/freescape/objects/group.cpp
Normal file
226
engines/freescape/objects/group.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
/* 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/freescape.h"
|
||||
#include "freescape/objects/group.h"
|
||||
#include "freescape/objects/geometricobject.h"
|
||||
#include "freescape/language/8bitDetokeniser.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
Group::Group(uint16 objectID_, uint16 flags_,
|
||||
const Common::Array<uint16> objectIds_,
|
||||
const Math::Vector3d offset1_,
|
||||
const Math::Vector3d offset2_,
|
||||
const Common::Array<AnimationOpcode *> operations_) {
|
||||
_type = kGroupType;
|
||||
_objectID = objectID_;
|
||||
_flags = flags_;
|
||||
_scale = 0;
|
||||
_active = true;
|
||||
_step = 0;
|
||||
_offset1 = offset1_;
|
||||
_offset2 = offset2_;
|
||||
|
||||
for (int i = 0; i < 3; i++) { // three is the maximum number of objects in a group
|
||||
if (objectIds_[i] == 0 || objectIds_[i] == 0xffff)
|
||||
break;
|
||||
_objectIds.push_back(objectIds_[i]);
|
||||
}
|
||||
|
||||
_operations = operations_;
|
||||
|
||||
if (isDestroyed()) // If the object is destroyed, restore it
|
||||
restore();
|
||||
|
||||
makeInitiallyVisible();
|
||||
makeVisible();
|
||||
}
|
||||
|
||||
Group::~Group() {
|
||||
for (int i = 0; i < int(_operations.size()); i++)
|
||||
delete _operations[i];
|
||||
}
|
||||
|
||||
Object *Group::duplicate() {
|
||||
return new Group(
|
||||
_objectID,
|
||||
_flags,
|
||||
_objectIds,
|
||||
_offset1,
|
||||
_offset2,
|
||||
_operations
|
||||
);
|
||||
}
|
||||
|
||||
void Group::linkObject(Object *obj) {
|
||||
int objectIndex = -1;
|
||||
for (int i = 0; i < int(_objectIds.size()) ; i++) {
|
||||
if (_objectIds[i] == obj->getObjectID()) {
|
||||
objectIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (objectIndex == -1)
|
||||
return;
|
||||
|
||||
debugC(1, kFreescapeDebugParser, "Linking object: %d to group %d", obj->getObjectID(), this->getObjectID());
|
||||
_origins.push_back(obj->getOrigin());
|
||||
debugC(1, kFreescapeDebugParser, "Origin %f, %f %f", obj->getOrigin().x(), obj->getOrigin().y(), obj->getOrigin().z());
|
||||
|
||||
obj->_partOfGroup = this;
|
||||
_objects.push_back(obj);
|
||||
}
|
||||
|
||||
void Group::assemble(int index) {
|
||||
GeometricObject *gobj = (GeometricObject *)_objects[index];
|
||||
Math::Vector3d position = _operations[_step]->position;
|
||||
Math::Vector3d offset = _origins[index] - _origins[0];
|
||||
/*if (index == 0)
|
||||
; // offset is always zero
|
||||
else if (index == 1)
|
||||
offset = _offset1;
|
||||
else if (index == 2)
|
||||
offset = _offset1 + _offset2;
|
||||
else
|
||||
error("Invalid index: %d", index);
|
||||
|
||||
offset = 32 * offset / _scale;*/
|
||||
position = 32 * position / _scale;
|
||||
|
||||
debugC(1, kFreescapeDebugGroup, "Group %d: Assembling object %d originally at %f, %f, %f", _objectID, gobj->getObjectID(), gobj->getOrigin().x(), gobj->getOrigin().y(), gobj->getOrigin().z());
|
||||
gobj->offsetOrigin(position + offset);
|
||||
debugC(1, kFreescapeDebugGroup, "Group %d: Assembling object %d moved to %f, %f, %f", _objectID, gobj->getObjectID(), gobj->getOrigin().x(), gobj->getOrigin().y(), gobj->getOrigin().z());
|
||||
}
|
||||
|
||||
void Group::run() {
|
||||
if (!_active)
|
||||
return;
|
||||
|
||||
int opcode = _operations[_step]->opcode;
|
||||
debugC(1, kFreescapeDebugGroup, "Executing opcode 0x%x at step %d", opcode, _step);
|
||||
if (opcode == 0x80 || opcode == 0xff) {
|
||||
debugC(1, kFreescapeDebugGroup, "Executing group rewind");
|
||||
_active = true;
|
||||
_step = -1;
|
||||
if (opcode == 0xff)
|
||||
return;
|
||||
//reset();
|
||||
}
|
||||
|
||||
if (opcode & 0x01) {
|
||||
debugC(1, kFreescapeDebugGroup, "Executing group condition %s", _operations[_step]->conditionSource.c_str());
|
||||
g_freescape->executeCode(_operations[_step]->condition, false, true, false, false);
|
||||
}
|
||||
|
||||
if (opcode & 0x10) {
|
||||
uint32 groupSize = _objects.size();
|
||||
for (uint32 i = 0; i < groupSize ; i++)
|
||||
assemble(i);
|
||||
_active = false;
|
||||
_step++;
|
||||
}
|
||||
|
||||
if (opcode == 0x0) {
|
||||
debugC(1, kFreescapeDebugGroup, "Executing group assemble");
|
||||
uint32 groupSize = _objects.size();
|
||||
for (uint32 i = 0; i < groupSize ; i++)
|
||||
assemble(i);
|
||||
}
|
||||
|
||||
if (opcode & 0x08) {
|
||||
uint32 groupSize = _objects.size();
|
||||
for (uint32 i = 0; i < groupSize ; i++)
|
||||
_objects[i]->makeVisible();
|
||||
|
||||
if (opcode & 0x20) {
|
||||
for (uint32 i = 0; i < groupSize ; i++)
|
||||
_objects[i]->destroy();
|
||||
}
|
||||
|
||||
if (opcode & 0x40) {
|
||||
for (uint32 i = 0; i < groupSize ; i++)
|
||||
_objects[i]->makeInvisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Group::start() {
|
||||
makeVisible();
|
||||
_active = true;
|
||||
}
|
||||
|
||||
void Group::reset() {
|
||||
uint32 groupSize = _objects.size();
|
||||
for (uint32 i = 0; i < groupSize ; i++) {
|
||||
GeometricObject *gobj = (GeometricObject *)_objects[i];
|
||||
if (GeometricObject::isPolygon(_objects[i]->getType())) {
|
||||
gobj->setOrigin(_origins[i]);
|
||||
gobj->restoreOrdinates();
|
||||
//gobj->makeInvisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Group::draw(Renderer *gfx, float offset) {
|
||||
if (!_active)
|
||||
return;
|
||||
|
||||
uint32 groupSize = _objects.size();
|
||||
for (uint32 i = 0; i < groupSize ; i++) {
|
||||
if (!_objects[i]->isDestroyed() && !_objects[i]->isInvisible())
|
||||
_objects[i]->draw(gfx);
|
||||
}
|
||||
}
|
||||
|
||||
void Group::step() {
|
||||
if (!_active)
|
||||
return;
|
||||
|
||||
debugC(1, kFreescapeDebugGroup, "Stepping group %d", _objectID);
|
||||
if (_step < int(_operations.size() - 1))
|
||||
_step++;
|
||||
else {
|
||||
_active = false;
|
||||
_step = -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool Group::collides(const Math::AABB &aabb) {
|
||||
uint32 groupSize = _objects.size();
|
||||
for (uint32 i = 0; i < groupSize ; i++) {
|
||||
if (!_objects[i]->isInvisible() && !_objects[i]->isDestroyed() && _objects[i]->isDrawable()) {
|
||||
GeometricObject *gobj = (GeometricObject *)_objects[i];
|
||||
if (gobj->collides(aabb))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Group::makePartsInvisible() {
|
||||
uint32 groupSize = _objects.size();
|
||||
for (uint32 i = 0; i < groupSize ; i++) {
|
||||
_objects[i]->makeInvisible();
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
78
engines/freescape/objects/group.h
Normal file
78
engines/freescape/objects/group.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_GROUP_H
|
||||
#define FREESCAPE_GROUP_H
|
||||
|
||||
#include "freescape/gfx.h"
|
||||
#include "freescape/objects/object.h"
|
||||
|
||||
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 Math::Vector3d offset1_,
|
||||
const Math::Vector3d offset2_,
|
||||
const Common::Array<AnimationOpcode *> operations);
|
||||
~Group();
|
||||
void linkObject(Object *obj);
|
||||
void assemble(int index);
|
||||
void step();
|
||||
void run();
|
||||
void run(int index);
|
||||
void reset();
|
||||
void start();
|
||||
bool collides(const Math::AABB &aabb);
|
||||
void makePartsInvisible();
|
||||
|
||||
Common::Array<Object *> _objects;
|
||||
Common::Array<Math::Vector3d> _origins;
|
||||
Math::Vector3d _offset1;
|
||||
Math::Vector3d _offset2;
|
||||
Common::Array<AnimationOpcode *> _operations;
|
||||
Common::Array<uint16> _objectIds;
|
||||
int _scale;
|
||||
int _step;
|
||||
bool _active;
|
||||
|
||||
ObjectType getType() override { return ObjectType::kGroupType; };
|
||||
bool isDrawable() override { return true; }
|
||||
void draw(Renderer *gfx, float offset = 0.0) override;
|
||||
void scale(int scale_) override { _scale = scale_; };
|
||||
bool isActive() { return !isDestroyed() && !isInvisible() && _step > 0 && _active; };
|
||||
Object *duplicate() override;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_GLOBAL_H
|
||||
99
engines/freescape/objects/object.h
Normal file
99
engines/freescape/objects/object.h
Normal file
@@ -0,0 +1,99 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#ifndef FREESCAPE_OBJECT_H
|
||||
#define FREESCAPE_OBJECT_H
|
||||
|
||||
#include "math/aabb.h"
|
||||
|
||||
#include "freescape/gfx.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
enum ObjectType {
|
||||
kEntranceType = 0,
|
||||
kCubeType = 1,
|
||||
kSensorType = 2,
|
||||
kRectangleType = 3,
|
||||
|
||||
kEastPyramidType = 4,
|
||||
kWestPyramidType = 5,
|
||||
kUpPyramidType = 6,
|
||||
kDownPyramidType = 7,
|
||||
kNorthPyramidType = 8,
|
||||
kSouthPyramidType = 9,
|
||||
|
||||
kLineType = 10,
|
||||
kTriangleType = 11,
|
||||
kQuadrilateralType = 12,
|
||||
kPentagonType = 13,
|
||||
kHexagonType = 14,
|
||||
|
||||
kGroupType = 15
|
||||
};
|
||||
|
||||
class Object {
|
||||
public:
|
||||
virtual ObjectType getType() { return _type; }
|
||||
uint16 getObjectID() { return _objectID; }
|
||||
uint16 getObjectFlags() { return _flags; }
|
||||
bool isGeometric() {
|
||||
return _type != kEntranceType && _type != kGroupType && _type != kSensorType;
|
||||
}
|
||||
void setObjectFlags(uint32 flags_) { _flags = flags_; }
|
||||
Math::Vector3d getOrigin() { return _origin; }
|
||||
virtual void setOrigin(Math::Vector3d origin_) { _origin = origin_; };
|
||||
Math::Vector3d getSize() { return _size; }
|
||||
|
||||
virtual bool isDrawable() { return false; }
|
||||
virtual bool isPlanar() { return false; }
|
||||
virtual void scale(int factor) = 0;
|
||||
|
||||
bool isInvisible() { return _flags & 0x40; }
|
||||
void makeInvisible() { _flags = _flags | 0x40; }
|
||||
void makeVisible() { _flags = _flags & ~0x40; }
|
||||
bool isInitiallyInvisible() { return _flags & 0x80; }
|
||||
void makeInitiallyInvisible() { _flags = _flags | 0x80; }
|
||||
void makeInitiallyVisible() { _flags = _flags & ~0x80; }
|
||||
bool isDestroyed() { return _flags & 0x20; }
|
||||
void destroy() { _flags = _flags | 0x20; }
|
||||
void restore() { _flags = _flags & ~0x20; }
|
||||
void toggleVisibility() { _flags = _flags ^ 0x40; }
|
||||
|
||||
virtual ~Object() {}
|
||||
virtual Object *duplicate() = 0;
|
||||
|
||||
virtual void draw(Freescape::Renderer *gfx, float offset = 0.0) = 0;
|
||||
|
||||
uint16 _flags;
|
||||
ObjectType _type;
|
||||
uint16 _objectID;
|
||||
Math::Vector3d _origin, _size, _rotation;
|
||||
Math::AABB _boundingBox;
|
||||
Object *_partOfGroup = nullptr;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_OBJECT_H
|
||||
114
engines/freescape/objects/sensor.cpp
Normal file
114
engines/freescape/objects/sensor.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/* 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_) {
|
||||
_type = kSensorType;
|
||||
_objectID = objectID_;
|
||||
_origin = origin_;
|
||||
_rotation = rotation_;
|
||||
|
||||
if (axis_ == 0x01 || axis_ == 0x02)
|
||||
_size = Math::Vector3d(0, 3, 3);
|
||||
else if (axis_ == 0x04 || axis_ == 0x08)
|
||||
_size = Math::Vector3d(3, 0, 3);
|
||||
else if (axis_ == 0x10 || axis_ == 0x20)
|
||||
_size = Math::Vector3d(3, 3, 0);
|
||||
else
|
||||
_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_;
|
||||
|
||||
if (isInitiallyInvisible())
|
||||
makeInvisible();
|
||||
else
|
||||
makeVisible();
|
||||
|
||||
_conditionSource = conditionSource_;
|
||||
_condition = condition_;
|
||||
_isShooting = false;
|
||||
}
|
||||
|
||||
void Sensor::scale(int factor) {
|
||||
_origin = _origin / factor;
|
||||
_size = _size / factor;
|
||||
}
|
||||
|
||||
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, float offset) {
|
||||
gfx->renderCube(_origin, _size, _colours, nullptr, offset);
|
||||
}
|
||||
|
||||
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
|
||||
77
engines/freescape/objects/sensor.h
Normal file
77
engines/freescape/objects/sensor.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on Phantasma code by Thomas Harte (2013),
|
||||
// available at https://github.com/TomHarte/Phantasma/ (MIT)
|
||||
|
||||
#ifndef FREESCAPE_SENSOR_H
|
||||
#define FREESCAPE_SENSOR_H
|
||||
|
||||
#include "freescape/area.h"
|
||||
#include "freescape/objects/object.h"
|
||||
#include "freescape/language/instruction.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
class Sensor : public Object {
|
||||
public:
|
||||
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_);
|
||||
|
||||
byte _firingInterval;
|
||||
uint16 _firingRange;
|
||||
uint16 _axis;
|
||||
bool _isShooting;
|
||||
|
||||
Common::String _conditionSource;
|
||||
FCLInstructionVector _condition;
|
||||
|
||||
virtual ~Sensor() { delete _colours; }
|
||||
bool isDrawable() override { return true; }
|
||||
bool isPlanar() override { return true; }
|
||||
bool isShooting() { return _isShooting; }
|
||||
void scale(int factor) override;
|
||||
Object *duplicate() override;
|
||||
|
||||
ObjectType getType() override { return kSensorType; };
|
||||
Math::Vector3d getRotation() { return _rotation; }
|
||||
void shouldShoot(bool shooting) { _isShooting = shooting; }
|
||||
|
||||
void draw(Freescape::Renderer *gfx, float offset = 0.0) override;
|
||||
|
||||
bool playerDetected(const Math::Vector3d &position, Area *area);
|
||||
|
||||
private:
|
||||
Common::Array<uint8> *_colours;
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_SENSOR_H
|
||||
9
engines/freescape/shaders/freescape_bitmap.fragment
Normal file
9
engines/freescape/shaders/freescape_bitmap.fragment
Normal file
@@ -0,0 +1,9 @@
|
||||
in vec2 Texcoord;
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
outColor = texture(tex, Texcoord);
|
||||
}
|
||||
21
engines/freescape/shaders/freescape_bitmap.vertex
Normal file
21
engines/freescape/shaders/freescape_bitmap.vertex
Normal file
@@ -0,0 +1,21 @@
|
||||
in vec2 position;
|
||||
in vec2 texcoord;
|
||||
|
||||
uniform UBOOL flipY;
|
||||
|
||||
out vec2 Texcoord;
|
||||
|
||||
void main() {
|
||||
Texcoord = texcoord;
|
||||
|
||||
vec2 pos = position;
|
||||
// Coordinates are [0.0;1.0], transform to [-1.0; 1.0]
|
||||
pos.x = pos.x * 2.0 - 1.0;
|
||||
pos.y = -1.0 * (pos.y * 2.0 - 1.0);
|
||||
|
||||
if (UBOOL_TEST(flipY)) {
|
||||
pos.y *= -1.0;
|
||||
}
|
||||
|
||||
gl_Position = vec4(pos, 0.0, 1.0);
|
||||
}
|
||||
10
engines/freescape/shaders/freescape_cubemap.fragment
Normal file
10
engines/freescape/shaders/freescape_cubemap.fragment
Normal file
@@ -0,0 +1,10 @@
|
||||
in vec2 TexCoord;
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform sampler2D skyTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = texture(skyTexture, TexCoord);
|
||||
}
|
||||
11
engines/freescape/shaders/freescape_cubemap.vertex
Normal file
11
engines/freescape/shaders/freescape_cubemap.vertex
Normal file
@@ -0,0 +1,11 @@
|
||||
in vec3 position;
|
||||
in vec2 texcoord;
|
||||
|
||||
uniform mat4 mvpMatrix;
|
||||
out vec2 TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoord = texcoord;
|
||||
gl_Position = mvpMatrix * vec4(position, 1.0);
|
||||
}
|
||||
42
engines/freescape/shaders/freescape_triangle.fragment
Normal file
42
engines/freescape/shaders/freescape_triangle.fragment
Normal file
@@ -0,0 +1,42 @@
|
||||
OUTPUT
|
||||
|
||||
uniform UBOOL useStipple;
|
||||
uniform int stipple[128];
|
||||
|
||||
varying vec4 var_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (UBOOL_TEST(useStipple)) {
|
||||
// Calculate the 32x32 pattern coordinates
|
||||
ivec2 coord = ivec2(gl_FragCoord.xy);
|
||||
|
||||
// Calculate the byte position and bit position within that byte
|
||||
int x = int(mod(float(coord.x), 32.));
|
||||
int y = int(mod(float(coord.y), 32.));
|
||||
|
||||
// Each row in the 32x32 pattern is represented by 4 bytes (4 * 8 bits = 32 bits)
|
||||
int byteIndex = y * 4 + (x / 8);
|
||||
int bitIndex = int(mod(float(x), 8.));
|
||||
|
||||
// Get the stipple pattern byte
|
||||
int patternByte = 0;
|
||||
for (int i = 0; i < 128; i++) {
|
||||
if (i == byteIndex) {
|
||||
patternByte = stipple[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (i >= 7 - bitIndex)
|
||||
break;
|
||||
patternByte = patternByte / 2;
|
||||
}
|
||||
|
||||
if (int(mod(float(patternByte), 2.)) == 0)
|
||||
discard;
|
||||
}
|
||||
|
||||
outColor = var_color;
|
||||
}
|
||||
12
engines/freescape/shaders/freescape_triangle.vertex
Normal file
12
engines/freescape/shaders/freescape_triangle.vertex
Normal file
@@ -0,0 +1,12 @@
|
||||
in vec3 position;
|
||||
|
||||
uniform mat4 mvpMatrix;
|
||||
uniform vec3 color;
|
||||
|
||||
varying vec4 var_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
var_color = vec4(color, 1.0);
|
||||
gl_Position = mvpMatrix * vec4(position, 1.0);
|
||||
}
|
||||
570
engines/freescape/sound.cpp
Normal file
570
engines/freescape/sound.cpp
Normal file
@@ -0,0 +1,570 @@
|
||||
/* 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 "common/file.h"
|
||||
#include "audio/audiostream.h"
|
||||
#include "audio/decoders/raw.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
#include "freescape/games/eclipse/eclipse.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void FreescapeEngine::loadSpeakerFxZX(Common::SeekableReadStream *file, int sfxTable, int sfxData) {
|
||||
debugC(1, kFreescapeDebugParser, "Reading sound table for ZX");
|
||||
int numberSounds = 25;
|
||||
|
||||
if (isDark())
|
||||
numberSounds = 34;
|
||||
|
||||
if (isEclipse() && (_variant & GF_ZX_DEMO_MICROHOBBY))
|
||||
numberSounds = 21;
|
||||
|
||||
for (int i = 1; i < numberSounds; i++) {
|
||||
debugC(1, kFreescapeDebugParser, "Reading sound table entry: %d ", i);
|
||||
_soundsSpeakerFxZX[i] = new Common::Array<soundUnitZX>();
|
||||
int soundIdx = (i - 1) * 4;
|
||||
file->seek(sfxTable + soundIdx);
|
||||
|
||||
byte SFXtempStruct[8] = {};
|
||||
|
||||
uint8 dataIndex = file->readByte();
|
||||
uint16 soundValue = file->readUint16LE();
|
||||
SFXtempStruct[0] = file->readByte();
|
||||
|
||||
file->seek(sfxData + dataIndex * 4);
|
||||
uint8 soundType = file->readByte();
|
||||
int original_sound_ptr = sfxData + dataIndex * 4 + 1;
|
||||
int sound_ptr = original_sound_ptr;
|
||||
uint8 soundSize = 0;
|
||||
int16 repetitions = 0;
|
||||
debugC(1, kFreescapeDebugParser, "dataIndex: %x, value: %x, SFXtempStruct[0]: %x, type: %x", dataIndex, soundValue, SFXtempStruct[0], soundType);
|
||||
if (soundType == 0xff)
|
||||
break;
|
||||
|
||||
if ((soundType & 0x80) == 0) {
|
||||
SFXtempStruct[6] = 0;
|
||||
SFXtempStruct[4] = soundType;
|
||||
|
||||
while (true) {
|
||||
while (true) {
|
||||
file->seek(sound_ptr);
|
||||
//debug("start sound ptr: %x", sound_ptr);
|
||||
soundSize = file->readByte();
|
||||
SFXtempStruct[1] = soundSize;
|
||||
SFXtempStruct[2] = file->readByte();
|
||||
SFXtempStruct[3] = file->readByte();
|
||||
|
||||
for (int j = 0; j <= 7; j++)
|
||||
debugC(1, kFreescapeDebugParser, "SFXtempStruct[%d]: %x", j, SFXtempStruct[j]);
|
||||
|
||||
do {
|
||||
uint32 var9 = 0xffffff & (SFXtempStruct[3] * 0xd0);
|
||||
uint32 var10 = var9 / soundValue;
|
||||
|
||||
var9 = 0xffffff & (7 * soundValue);
|
||||
uint16 var5 = (0xffff & var9) - 0x1e;
|
||||
if ((short)var5 < 0)
|
||||
var5 = 1;
|
||||
|
||||
soundUnitZX soundUnit;
|
||||
soundUnit.isRaw = false;
|
||||
soundUnit.freqTimesSeconds = (var10 & 0xffff) + 1;
|
||||
soundUnit.tStates = var5;
|
||||
soundUnit.multiplier = 10;
|
||||
//debug("playSFX(%x, %x)", soundUnit.freqTimesSeconds, soundUnit.tStates);
|
||||
_soundsSpeakerFxZX[i]->push_back(soundUnit);
|
||||
int16 var4 = 0;
|
||||
|
||||
if ((SFXtempStruct[2] & 0x80) != 0) {
|
||||
var4 = 0xff;
|
||||
}
|
||||
//debug("var4: %d", var4);
|
||||
//debug("soundValue delta: %d", int16(((var4 << 8) | SFXtempStruct[2])));
|
||||
soundValue = soundValue + int16(((var4 << 8) | SFXtempStruct[2]));
|
||||
//debug("soundValue: %x", soundValue);
|
||||
soundSize = soundSize - 1;
|
||||
} while (soundSize != 0);
|
||||
SFXtempStruct[5] = SFXtempStruct[5] + 1;
|
||||
if (SFXtempStruct[5] == SFXtempStruct[4])
|
||||
break;
|
||||
|
||||
sound_ptr = original_sound_ptr + SFXtempStruct[5] * 3;
|
||||
//debug("sound ptr: %x", sound_ptr);
|
||||
}
|
||||
|
||||
soundSize = SFXtempStruct[0];
|
||||
SFXtempStruct[0] = soundSize - 1;
|
||||
sound_ptr = original_sound_ptr;
|
||||
if ((soundSize - 1) == 0)
|
||||
break;
|
||||
SFXtempStruct[5] = 0;
|
||||
}
|
||||
} else if (soundType & 0x80) {
|
||||
file->seek(sound_ptr);
|
||||
for (int j = 1; j <= 7; j++) {
|
||||
SFXtempStruct[j] = file->readByte();
|
||||
debugC(1, kFreescapeDebugParser, "SFXtempStruct[%d]: %x", j, SFXtempStruct[j]);
|
||||
}
|
||||
soundSize = SFXtempStruct[0];
|
||||
repetitions = SFXtempStruct[1] | (SFXtempStruct[2] << 8);
|
||||
uint16 var5 = soundValue;
|
||||
//debug("Repetitions: %x", repetitions);
|
||||
if ((soundType & 0x7f) == 1) {
|
||||
do {
|
||||
do {
|
||||
soundUnitZX soundUnit;
|
||||
soundUnit.isRaw = false;
|
||||
soundUnit.tStates = var5;
|
||||
soundUnit.freqTimesSeconds = SFXtempStruct[3] | (SFXtempStruct[4] << 8);
|
||||
soundUnit.multiplier = 1.8f;
|
||||
//debug("playSFX(%x, %x)", soundUnit.freqTimesSeconds, soundUnit.tStates);
|
||||
_soundsSpeakerFxZX[i]->push_back(soundUnit);
|
||||
repetitions = repetitions - 1;
|
||||
var5 = var5 + (SFXtempStruct[5] | (SFXtempStruct[6] << 8));
|
||||
|
||||
} while ((byte)((byte)repetitions | (byte)((uint16)repetitions >> 8)) != 0);
|
||||
soundSize = soundSize - 1;
|
||||
repetitions = SFXtempStruct[1] | (SFXtempStruct[2] << 8);
|
||||
var5 = soundValue;
|
||||
} while (soundSize != 0);
|
||||
} else if ((soundType & 0x7f) == 2) {
|
||||
repetitions = SFXtempStruct[1] | (SFXtempStruct[0] << 8);
|
||||
debugC(1, kFreescapeDebugParser, "Raw sound, repetitions: %x", repetitions);
|
||||
uint16 sVar7 = SFXtempStruct[3];
|
||||
soundType = 0;
|
||||
soundSize = SFXtempStruct[2];
|
||||
uint16 silenceSize = SFXtempStruct[4];
|
||||
bool cond1 = (SFXtempStruct[4] != 0 && SFXtempStruct[4] != 2);
|
||||
bool cond2 = SFXtempStruct[4] == 2;
|
||||
bool cond3 = SFXtempStruct[4] == 0;
|
||||
|
||||
assert(cond1 || cond2 || cond3);
|
||||
do {
|
||||
soundUnitZX soundUnit;
|
||||
soundUnit.isRaw = true;
|
||||
int totalSize = soundSize + sVar7;
|
||||
soundUnit.rawFreq = 0.1f;
|
||||
soundUnit.rawLengthus = totalSize;
|
||||
_soundsSpeakerFxZX[i]->push_back(soundUnit);
|
||||
//debugN("%x ", silenceSize);
|
||||
soundUnit.rawFreq = 0;
|
||||
soundUnit.rawLengthus = silenceSize;
|
||||
_soundsSpeakerFxZX[i]->push_back(soundUnit);
|
||||
repetitions = repetitions + -1;
|
||||
soundSize = SFXtempStruct[5] + soundSize;
|
||||
|
||||
if (cond1)
|
||||
silenceSize = (repetitions & 0xff) | (repetitions >> 8);
|
||||
else if (cond2)
|
||||
silenceSize = (repetitions & 0xff);
|
||||
else
|
||||
silenceSize = soundSize;
|
||||
|
||||
//debug("soundSize: %x", soundSize);
|
||||
//sVar7 = (uint16)bVar9 << 8;
|
||||
} while (repetitions != 0);
|
||||
//debug("\n");
|
||||
//if (i == 15)
|
||||
// assert(0);
|
||||
} else {
|
||||
debugC(1, kFreescapeDebugParser, "Sound type: %x", soundType);
|
||||
bool beep = false;
|
||||
do {
|
||||
soundType = 0;
|
||||
uint16 uVar2 = SFXtempStruct[1] | (SFXtempStruct[2] << 8);
|
||||
uint8 cVar3 = 0;
|
||||
do {
|
||||
//debug("start cycle %d:", cVar3);
|
||||
//ULA_PORT = bVar4;
|
||||
//bVar4 = bVar4 ^ 0x10;
|
||||
beep = !beep;
|
||||
repetitions = (((uint16)soundType * 0x100 + (uint16)soundType * -2) -
|
||||
(uint16)((uint16)soundType * 0x100 < (uint16)soundType)) + (uVar2 & 0xff);
|
||||
uint8 bVar9 = (byte)repetitions;
|
||||
uint8 bVar8 = (byte)((uint16)repetitions >> 8);
|
||||
uint8 bVar1 = bVar9 - bVar8;
|
||||
soundType = bVar1;
|
||||
if (bVar8 <= bVar9) {
|
||||
bVar1 = bVar1 - 1;
|
||||
soundType = bVar1;
|
||||
}
|
||||
//debug("wait %d", bVar1);
|
||||
assert(bVar1 > 0);
|
||||
soundUnitZX soundUnit;
|
||||
soundUnit.isRaw = false;
|
||||
soundUnit.freqTimesSeconds = beep ? 1000 : 0;
|
||||
soundUnit.tStates = beep ? 437500 / 1000 - 30.125 : 0;
|
||||
soundUnit.multiplier = float(bVar1) / 500;
|
||||
_soundsSpeakerFxZX[i]->push_back(soundUnit);
|
||||
|
||||
// No need to wait
|
||||
//do {
|
||||
// bVar1 = bVar1 - 1;
|
||||
//} while (bVar1 != 0);
|
||||
cVar3 = (char)(uVar2 >> 8) + -1;
|
||||
uVar2 = (((uint16)cVar3) << 8) | (uint8)uVar2;
|
||||
} while (cVar3 != '\0');
|
||||
soundSize = soundSize + -1;
|
||||
} while (soundSize != '\0');
|
||||
}
|
||||
}
|
||||
}
|
||||
//assert(0);
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadSpeakerFxDOS(Common::SeekableReadStream *file, int offsetFreq, int offsetTable, int numberSounds) {
|
||||
debugC(1, kFreescapeDebugParser, "Reading PC speaker sound table for DOS");
|
||||
for (int i = 1; i <= numberSounds; i++) {
|
||||
debugC(1, kFreescapeDebugParser, "Reading sound table entry: %d ", i);
|
||||
int soundIdx = (i - 1) * 4;
|
||||
file->seek(offsetFreq + soundIdx);
|
||||
uint16 index = file->readByte();
|
||||
if (index == 0xff)
|
||||
continue;
|
||||
uint iVar = index * 5;
|
||||
|
||||
uint16 frequencyStart = file->readUint16LE();
|
||||
uint8 repetitions = file->readByte();
|
||||
debugC(1, kFreescapeDebugParser, "Frequency start: %d ", frequencyStart);
|
||||
debugC(1, kFreescapeDebugParser, "Repetitions: %d ", repetitions);
|
||||
|
||||
uint8 frequencyStepsNumber = 0;
|
||||
uint16 frequencyStep = 0;
|
||||
|
||||
file->seek(offsetTable + iVar);
|
||||
uint8 lastIndex = file->readByte();
|
||||
debugC(1, kFreescapeDebugParser, "0x%x %d (lastIndex)", offsetTable - 0x200, lastIndex);
|
||||
|
||||
frequencyStepsNumber = file->readByte();
|
||||
debugC(1, kFreescapeDebugParser, "0x%x %d (frequency steps)", offsetTable + 1 - 0x200, frequencyStepsNumber);
|
||||
|
||||
int basePtr = offsetTable + iVar + 1;
|
||||
debugC(1, kFreescapeDebugParser, "0x%x (basePtr)", basePtr - 0x200);
|
||||
|
||||
frequencyStep = file->readUint16LE();
|
||||
debugC(1, kFreescapeDebugParser, "0x%x %d (steps number)", offsetTable + 2 - 0x200, (int16)frequencyStep);
|
||||
|
||||
uint8 frequencyDuration = file->readByte();
|
||||
debugC(1, kFreescapeDebugParser, "0x%x %d (frequency duration)", offsetTable + 4 - 0x200, frequencyDuration);
|
||||
|
||||
soundSpeakerFx *speakerFxInfo = new soundSpeakerFx();
|
||||
_soundsSpeakerFx[i] = speakerFxInfo;
|
||||
|
||||
speakerFxInfo->frequencyStart = frequencyStart;
|
||||
speakerFxInfo->repetitions = repetitions;
|
||||
speakerFxInfo->frequencyStepsNumber = frequencyStepsNumber;
|
||||
speakerFxInfo->frequencyStep = frequencyStep;
|
||||
speakerFxInfo->frequencyDuration = frequencyDuration;
|
||||
|
||||
for (int j = 1; j < lastIndex; j++) {
|
||||
|
||||
soundSpeakerFx *speakerFxInfoAdditionalStep = new soundSpeakerFx();
|
||||
speakerFxInfoAdditionalStep->frequencyStart = 0;
|
||||
speakerFxInfoAdditionalStep->repetitions = 0;
|
||||
|
||||
file->seek(basePtr + 4 * j);
|
||||
debugC(1, kFreescapeDebugParser, "Reading at %x", basePtr + 4 * j - 0x200);
|
||||
frequencyStepsNumber = file->readByte();
|
||||
debugC(1, kFreescapeDebugParser, "%d (steps number)", frequencyStepsNumber);
|
||||
frequencyStep = file->readUint16LE();
|
||||
debugC(1, kFreescapeDebugParser, "%d (frequency step)", (int16)frequencyStep);
|
||||
frequencyDuration = file->readByte();
|
||||
debugC(1, kFreescapeDebugParser, "%d (frequency duration)", frequencyDuration);
|
||||
|
||||
speakerFxInfoAdditionalStep->frequencyStepsNumber = frequencyStepsNumber;
|
||||
speakerFxInfoAdditionalStep->frequencyStep = frequencyStep;
|
||||
speakerFxInfoAdditionalStep->frequencyDuration = frequencyDuration;
|
||||
speakerFxInfo->additionalSteps.push_back(speakerFxInfoAdditionalStep);
|
||||
}
|
||||
debugC(1, kFreescapeDebugParser, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::playSound(int index, bool sync, Audio::SoundHandle &handle) {
|
||||
if (index < 0) {
|
||||
debugC(1, kFreescapeDebugMedia, "Sound not specified");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_syncSound)
|
||||
waitForSounds();
|
||||
|
||||
_syncSound = sync;
|
||||
|
||||
debugC(1, kFreescapeDebugMedia, "Playing sound %d with sync: %d", index, sync);
|
||||
if (isAmiga() || isAtariST()) {
|
||||
playSoundFx(index, sync);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDOS()) {
|
||||
soundSpeakerFx *speakerFxInfo = _soundsSpeakerFx[index];
|
||||
if (speakerFxInfo)
|
||||
playSoundDOS(speakerFxInfo, sync, handle);
|
||||
else
|
||||
debugC(1, kFreescapeDebugMedia, "WARNING: Sound %d is not available", index);
|
||||
|
||||
return;
|
||||
} else if (isSpectrum() && !isDriller()) {
|
||||
playSoundZX(_soundsSpeakerFxZX[index], handle);
|
||||
return;
|
||||
}
|
||||
|
||||
Common::Path filename;
|
||||
filename = Common::String::format("%s-%d.wav", _targetName.c_str(), index);
|
||||
debugC(1, kFreescapeDebugMedia, "Playing sound %s", filename.toString().c_str());
|
||||
playWav(filename);
|
||||
/*switch (index) {
|
||||
case 1:
|
||||
playWav("fsDOS_laserFire.wav");
|
||||
break;
|
||||
case 2: // Done
|
||||
playWav("fsDOS_WallBump.wav");
|
||||
break;
|
||||
case 3:
|
||||
playWav("fsDOS_stairDown.wav");
|
||||
break;
|
||||
case 4:
|
||||
playWav("fsDOS_stairUp.wav");
|
||||
break;
|
||||
case 5:
|
||||
playWav("fsDOS_roomChange.wav");
|
||||
break;
|
||||
case 6:
|
||||
playWav("fsDOS_configMenu.wav");
|
||||
break;
|
||||
case 7:
|
||||
playWav("fsDOS_bigHit.wav");
|
||||
break;
|
||||
case 8:
|
||||
playWav("fsDOS_teleporterActivated.wav");
|
||||
break;
|
||||
case 9:
|
||||
playWav("fsDOS_powerUp.wav");
|
||||
break;
|
||||
case 10:
|
||||
playWav("fsDOS_energyDrain.wav");
|
||||
break;
|
||||
case 11: // ???
|
||||
debugC(1, kFreescapeDebugMedia, "Playing unknown sound");
|
||||
break;
|
||||
case 12:
|
||||
playWav("fsDOS_switchOff.wav");
|
||||
break;
|
||||
case 13: // Seems to be repeated?
|
||||
playWav("fsDOS_laserHit.wav");
|
||||
break;
|
||||
case 14:
|
||||
playWav("fsDOS_tankFall.wav");
|
||||
break;
|
||||
case 15:
|
||||
playWav("fsDOS_successJingle.wav");
|
||||
break;
|
||||
case 16: // Silence?
|
||||
break;
|
||||
case 17:
|
||||
playWav("fsDOS_badJingle.wav");
|
||||
break;
|
||||
case 18: // Silence?
|
||||
break;
|
||||
case 19:
|
||||
debugC(1, kFreescapeDebugMedia, "Playing unknown sound");
|
||||
break;
|
||||
case 20:
|
||||
playWav("fsDOS_bigHit.wav");
|
||||
break;
|
||||
default:
|
||||
debugC(1, kFreescapeDebugMedia, "Unexpected sound %d", index);
|
||||
break;
|
||||
}*/
|
||||
_syncSound = sync;
|
||||
}
|
||||
void FreescapeEngine::playWav(const Common::Path &filename) {
|
||||
|
||||
Common::SeekableReadStream *s = _dataBundle->createReadStreamForMember(filename);
|
||||
if (!s) {
|
||||
debugC(1, kFreescapeDebugMedia, "WARNING: Sound %s not found", filename.toString().c_str());
|
||||
return;
|
||||
}
|
||||
Audio::AudioStream *stream = Audio::makeWAVStream(s, DisposeAfterUse::YES);
|
||||
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundFxHandle, stream);
|
||||
}
|
||||
|
||||
void FreescapeEngine::playMusic(const Common::Path &filename) {
|
||||
Audio::SeekableAudioStream *stream = nullptr;
|
||||
stream = Audio::SeekableAudioStream::openStreamFile(filename);
|
||||
if (stream) {
|
||||
_mixer->stopHandle(_musicHandle);
|
||||
Audio::LoopingAudioStream *loop = new Audio::LoopingAudioStream(stream, 0);
|
||||
_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, loop);
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::playSoundFx(int index, bool sync) {
|
||||
if (_soundsFx.size() == 0) {
|
||||
debugC(1, kFreescapeDebugMedia, "WARNING: Sounds are not loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
if (index < 0 || index >= int(_soundsFx.size())) {
|
||||
debugC(1, kFreescapeDebugMedia, "WARNING: Sound %d not available", index);
|
||||
return;
|
||||
}
|
||||
|
||||
int size = _soundsFx[index]->size;
|
||||
int sampleRate = _soundsFx[index]->sampleRate;
|
||||
int repetitions = _soundsFx[index]->repetitions;
|
||||
byte *data = _soundsFx[index]->data;
|
||||
|
||||
if (size > 4) {
|
||||
Audio::SeekableAudioStream *s = Audio::makeRawStream(data, size, sampleRate, Audio::FLAG_16BITS, DisposeAfterUse::NO);
|
||||
Audio::AudioStream *stream = new Audio::LoopingAudioStream(s, repetitions);
|
||||
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundFxHandle, stream);
|
||||
} else
|
||||
debugC(1, kFreescapeDebugMedia, "WARNING: Sound %d is empty", index);
|
||||
}
|
||||
|
||||
void FreescapeEngine::stopAllSounds(Audio::SoundHandle &handle) {
|
||||
debugC(1, kFreescapeDebugMedia, "Stopping sound");
|
||||
_mixer->stopHandle(handle);
|
||||
}
|
||||
|
||||
void FreescapeEngine::waitForSounds() {
|
||||
if (_usePrerecordedSounds || isAmiga() || isAtariST())
|
||||
while (_mixer->isSoundHandleActive(_soundFxHandle))
|
||||
waitInLoop(10);
|
||||
else {
|
||||
while (!_speaker->endOfStream())
|
||||
waitInLoop(10);
|
||||
}
|
||||
}
|
||||
|
||||
bool FreescapeEngine::isPlayingSound() {
|
||||
if (_usePrerecordedSounds || isAmiga() || isAtariST())
|
||||
return _mixer->isSoundHandleActive(_soundFxHandle);
|
||||
|
||||
return (!_speaker->endOfStream());
|
||||
}
|
||||
|
||||
void FreescapeEngine::playSilence(int duration, bool sync) {
|
||||
_speaker->playQueue(Audio::PCSpeaker::kWaveFormSilence, 0, 1000 * 10 * duration);
|
||||
_mixer->stopHandle(_soundFxHandle);
|
||||
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundFxHandle, _speaker, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
|
||||
}
|
||||
|
||||
void FreescapeEngine::queueSoundConst(double hzFreq, int duration) {
|
||||
_speaker->playQueue(Audio::PCSpeaker::kWaveFormSquare, hzFreq, 1000 * 10 * duration);
|
||||
}
|
||||
|
||||
uint16 FreescapeEngine::playSoundDOSSpeaker(uint16 frequencyStart, soundSpeakerFx *speakerFxInfo) {
|
||||
uint8 frequencyStepsNumber = speakerFxInfo->frequencyStepsNumber;
|
||||
int16 frequencyStep = speakerFxInfo->frequencyStep;
|
||||
uint8 frequencyDuration = speakerFxInfo->frequencyDuration;
|
||||
|
||||
int16 freq = frequencyStart;
|
||||
int waveDurationMultipler = 1800;
|
||||
int waveDuration = waveDurationMultipler * (frequencyDuration + 1);
|
||||
|
||||
while (true) {
|
||||
if (freq > 0) {
|
||||
float hzFreq = 1193180.0 / freq;
|
||||
debugC(1, kFreescapeDebugMedia, "raw %d, hz: %f, duration: %d", freq, hzFreq, waveDuration);
|
||||
_speaker->playQueue(Audio::PCSpeaker::kWaveFormSquare, hzFreq, waveDuration);
|
||||
}
|
||||
if (frequencyStepsNumber > 0) {
|
||||
// Ascending initial portions of cycle
|
||||
freq += frequencyStep;
|
||||
frequencyStepsNumber--;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
void FreescapeEngine::playSoundZX(Common::Array<soundUnitZX> *data, Audio::SoundHandle &handle) {
|
||||
for (auto &it : *data) {
|
||||
soundUnitZX value = it;
|
||||
|
||||
if (value.isRaw) {
|
||||
debugC(1, kFreescapeDebugMedia, "raw hz: %f, duration: %d", value.rawFreq, value.rawLengthus);
|
||||
if (value.rawFreq == 0) {
|
||||
_speaker->playQueue(Audio::PCSpeaker::kWaveFormSilence, 1, 5 * value.rawLengthus);
|
||||
continue;
|
||||
}
|
||||
_speaker->playQueue(Audio::PCSpeaker::kWaveFormSquare, value.rawFreq, 5 * value.rawLengthus);
|
||||
} else {
|
||||
if (value.freqTimesSeconds == 0 && value.tStates == 0) {
|
||||
_speaker->playQueue(Audio::PCSpeaker::kWaveFormSilence, 1, 1000 * value.multiplier);
|
||||
continue;
|
||||
}
|
||||
|
||||
float hzFreq = 1 / ((value.tStates + 30.125) / 437500.0);
|
||||
float waveDuration = value.freqTimesSeconds / hzFreq;
|
||||
waveDuration = value.multiplier * 1000 * (waveDuration + 1);
|
||||
debugC(1, kFreescapeDebugMedia, "non raw hz: %f, duration: %f", hzFreq, waveDuration);
|
||||
_speaker->playQueue(Audio::PCSpeaker::kWaveFormSquare, hzFreq, waveDuration);
|
||||
}
|
||||
}
|
||||
|
||||
_mixer->stopHandle(_soundFxHandle);
|
||||
_mixer->playStream(Audio::Mixer::kSFXSoundType, &handle, _speaker, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
|
||||
}
|
||||
|
||||
void FreescapeEngine::playSoundDOS(soundSpeakerFx *speakerFxInfo, bool sync, Audio::SoundHandle &handle) {
|
||||
uint freq = speakerFxInfo->frequencyStart;
|
||||
|
||||
for (int i = 0; i < speakerFxInfo->repetitions; i++) {
|
||||
freq = playSoundDOSSpeaker(freq, speakerFxInfo);
|
||||
|
||||
for (auto &it : speakerFxInfo->additionalSteps) {
|
||||
assert(it);
|
||||
freq = playSoundDOSSpeaker(freq, it);
|
||||
}
|
||||
}
|
||||
|
||||
_mixer->stopHandle(handle);
|
||||
_mixer->playStream(Audio::Mixer::kSFXSoundType, &handle, _speaker, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
|
||||
}
|
||||
|
||||
void FreescapeEngine::loadSoundsFx(Common::SeekableReadStream *file, int offset, int number) {
|
||||
file->seek(offset);
|
||||
soundFx *sound = nullptr;
|
||||
_soundsFx[0] = sound;
|
||||
for (int i = 1; i < number + 1; i++) {
|
||||
sound = (soundFx *)malloc(sizeof(soundFx));
|
||||
int zero = file->readUint16BE();
|
||||
assert(zero == 0);
|
||||
int size = file->readUint16BE();
|
||||
float sampleRate = float(file->readUint16BE()) / 2;
|
||||
debugC(1, kFreescapeDebugParser, "Loading sound: %d (size: %d, sample rate: %f) at %" PRIx64, i, size, sampleRate, file->pos());
|
||||
byte *data = (byte *)malloc(size * sizeof(byte));
|
||||
file->read(data, size);
|
||||
sound->sampleRate = sampleRate;
|
||||
sound->size = size;
|
||||
sound->data = (byte *)data;
|
||||
sound->repetitions = 1;
|
||||
_soundsFx[i] = sound;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Freescape
|
||||
63
engines/freescape/sound.h
Normal file
63
engines/freescape/sound.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_SOUND_H
|
||||
#define FREESCAPE_SOUND_H
|
||||
|
||||
#include "audio/softsynth/pcspk.h"
|
||||
#include "common/array.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
struct soundFx {
|
||||
int size;
|
||||
float sampleRate;
|
||||
int repetitions;
|
||||
byte *data;
|
||||
};
|
||||
|
||||
struct soundUnitZX {
|
||||
bool isRaw;
|
||||
uint16 freqTimesSeconds;
|
||||
uint16 tStates;
|
||||
float rawFreq;
|
||||
uint32 rawLengthus;
|
||||
float multiplier;
|
||||
};
|
||||
|
||||
struct soundSpeakerFx {
|
||||
uint16 frequencyStart;
|
||||
uint8 frequencyDuration;
|
||||
uint8 frequencyStepsNumber;
|
||||
uint16 frequencyStep;
|
||||
uint8 repetitions;
|
||||
Common::Array<struct soundSpeakerFx *>additionalSteps;
|
||||
};
|
||||
|
||||
// TODO: Migrate to Audio::PCSpeaker
|
||||
class SizedPCSpeaker : public Audio::PCSpeakerStream {
|
||||
public:
|
||||
bool endOfStream() const override { return !isPlaying(); }
|
||||
};
|
||||
|
||||
} // End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_SOUND_H
|
||||
102
engines/freescape/sweepAABB.cpp
Normal file
102
engines/freescape/sweepAABB.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/* 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/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
/*
|
||||
This code is inspired by the Luis Eduard Reis implementation:
|
||||
https://luisreis.net/blog/aabb_collision_handling/
|
||||
*/
|
||||
|
||||
float lineToPlane(Math::Vector3d const &p, Math::Vector3d const &u, Math::Vector3d const &v, Math::Vector3d const &n) {
|
||||
float NdotU = n.dotProduct(u);
|
||||
if (NdotU == 0)
|
||||
return INFINITY;
|
||||
|
||||
return n.dotProduct(v - p) / NdotU;
|
||||
}
|
||||
|
||||
bool between(float x, float a, float b) {
|
||||
return x >= a && x <= b;
|
||||
}
|
||||
|
||||
float sweepAABB(Math::AABB const &a, Math::AABB const &b, Math::Vector3d const &direction, Math::Vector3d &normal) {
|
||||
Math::Vector3d m = b.getMin() - a.getMax();
|
||||
Math::Vector3d mh = a.getSize() + b.getSize();
|
||||
|
||||
float h = 1.0;
|
||||
float s = 0.0;
|
||||
Math::Vector3d zero;
|
||||
|
||||
// X min
|
||||
s = lineToPlane(zero, direction, m, Math::Vector3d(-1, 0, 0));
|
||||
if (s >= 0 && direction.x() > 0 && s < h && between(s * direction.y(), m.y(), m.y() + mh.y()) && between(s * direction.z(), m.z(), m.z() + mh.z())) {
|
||||
h = s;
|
||||
normal = Math::Vector3d(-1, 0, 0);
|
||||
}
|
||||
|
||||
// X max
|
||||
m.x() = m.x() + mh.x();
|
||||
s = lineToPlane(zero, direction, m, Math::Vector3d(1, 0, 0));
|
||||
if (s >= 0 && direction.x() < 0 && s < h && between(s * direction.y(), m.y(), m.y() + mh.y()) && between(s * direction.z(), m.z(), m.z() + mh.z())) {
|
||||
h = s;
|
||||
normal = Math::Vector3d(1, 0, 0);
|
||||
}
|
||||
|
||||
// Y min
|
||||
m.x() = m.x() - mh.x();
|
||||
s = lineToPlane(zero, direction, m, Math::Vector3d(0, -1, 0));
|
||||
if (s >= 0 && direction.y() > 0 && s < h && between(s * direction.x(), m.x(), m.x() + mh.x()) && between(s * direction.z(), m.z(), m.z() + mh.z())) {
|
||||
h = s;
|
||||
normal = Math::Vector3d(0, -1, 0);
|
||||
}
|
||||
|
||||
// Y max
|
||||
m.y() = m.y() + mh.y();
|
||||
s = lineToPlane(zero, direction, m, Math::Vector3d(0, 1, 0));
|
||||
if (s >= 0 && direction.y() < 0 && s < h && between(s * direction.x(), m.x(), m.x() + mh.x()) && between(s * direction.z(), m.z(), m.z() + mh.z())) {
|
||||
h = s;
|
||||
normal = Math::Vector3d(0, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
// Z min
|
||||
m.y() = m.y() - mh.y();
|
||||
s = lineToPlane(zero, direction, m, Math::Vector3d(0, 0, -1));
|
||||
if (s >= 0 && direction.z() > 0 && s < h && between(s * direction.x(), m.x(), m.x() + mh.x()) && between(s * direction.y(), m.y(), m.y() + mh.y())) {
|
||||
h = s;
|
||||
normal = Math::Vector3d(0, 0, -1);
|
||||
}
|
||||
|
||||
// Z max
|
||||
m.z() = m.z() + mh.z();
|
||||
s = lineToPlane(zero, direction, m, Math::Vector3d(0, 0, 1));
|
||||
if (s >= 0 && direction.z() < 0 && s < h && between(s * direction.x(), m.x(), m.x() + mh.x()) && between(s * direction.y(), m.y(), m.y() + mh.y())) {
|
||||
h = s;
|
||||
normal = Math::Vector3d(0, 0, 1);
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
}
|
||||
34
engines/freescape/sweepAABB.h
Normal file
34
engines/freescape/sweepAABB.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREESCAPE_SWEEPAABB_H
|
||||
#define FREESCAPE_SWEEPAABB_H
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
extern Math::AABB createPlayerAABB(Math::Vector3d const position, int playerHeight, float reductionHeight = 0.0f);
|
||||
extern float sweepAABB(Math::AABB const &a, Math::AABB const &b, Math::Vector3d const &direction, Math::Vector3d &normal);
|
||||
|
||||
}
|
||||
|
||||
// End of namespace Freescape
|
||||
|
||||
#endif // FREESCAPE_SWEEPAABB_H
|
||||
430
engines/freescape/ui.cpp
Normal file
430
engines/freescape/ui.cpp
Normal file
@@ -0,0 +1,430 @@
|
||||
/* 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/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
void FreescapeEngine::waitInLoop(int maxWait) {
|
||||
long int startTick = _ticks;
|
||||
while (_ticks <= startTick + maxWait) {
|
||||
Common::Event event;
|
||||
while (_eventManager->pollEvent(event)) {
|
||||
if (_ticks > startTick + maxWait)
|
||||
break;
|
||||
|
||||
Common::Point mousePos;
|
||||
switch (event.type) {
|
||||
case Common::EVENT_QUIT:
|
||||
case Common::EVENT_RETURN_TO_LAUNCHER:
|
||||
quitGame();
|
||||
return;
|
||||
|
||||
case Common::EVENT_MOUSEMOVE:
|
||||
if (_hasFallen || _playerWasCrushed || _gameStateControl != kFreescapeGameStatePlaying)
|
||||
break;
|
||||
if (isCastle() && isSpectrum() && getGameBit(31)) // Game is finished
|
||||
break;
|
||||
mousePos = event.mouse;
|
||||
|
||||
if (_demoMode)
|
||||
break;
|
||||
|
||||
if (_shootMode) {
|
||||
;
|
||||
break;
|
||||
} else {
|
||||
// Mouse pointer is locked into the the middle of the screen
|
||||
// since we only need the relative movements. This will not affect any touchscreen device
|
||||
// so on-screen controls are still accesible
|
||||
mousePos.x = g_system->getWidth() * (_viewArea.left + _viewArea.width() / 2) / _screenW;
|
||||
mousePos.y = g_system->getHeight() * (_viewArea.top + _viewArea.height() / 2) / _screenW;
|
||||
if (_invertY)
|
||||
event.relMouse.y = -event.relMouse.y;
|
||||
|
||||
g_system->warpMouse(mousePos.x, mousePos.y);
|
||||
_eventManager->purgeMouseEvents();
|
||||
}
|
||||
|
||||
rotate(event.relMouse.x * _mouseSensitivity, event.relMouse.y * _mouseSensitivity, 0);
|
||||
break;
|
||||
|
||||
case Common::EVENT_SCREEN_CHANGED:
|
||||
_gfx->computeScreenViewport();
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// This is a simplified version of the draw frame code
|
||||
// that we used only for this loop in order to only allow the player to look around
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
int farClipPlane = _farClipPlane;
|
||||
if (_currentArea->isOutside())
|
||||
farClipPlane *= 100;
|
||||
|
||||
float aspectRatio = isCastle() ? 1.6 : 2.18;
|
||||
_gfx->updateProjectionMatrix(75.0, aspectRatio, _nearClipPlane, farClipPlane);
|
||||
_gfx->positionCamera(_position, _position + _cameraFront, _roll);
|
||||
|
||||
drawBackground();
|
||||
_currentArea->draw(_gfx, _ticks / 10, _position, _cameraFront, true);
|
||||
drawBorder();
|
||||
drawUI();
|
||||
|
||||
_gfx->flipBuffer();
|
||||
g_system->updateScreen();
|
||||
g_system->delayMillis(15); // try to target ~60 FPS
|
||||
}
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
_eventManager->purgeMouseEvents();
|
||||
_eventManager->purgeKeyboardEvents();
|
||||
}
|
||||
|
||||
void FreescapeEngine::titleScreen() {
|
||||
if (!_title)
|
||||
return;
|
||||
|
||||
int maxWait = 60 * 6;
|
||||
for (int i = 0; i < maxWait; i++) {
|
||||
Common::Event event;
|
||||
while (_eventManager->pollEvent(event)) {
|
||||
switch (event.type) {
|
||||
case Common::EVENT_QUIT:
|
||||
case Common::EVENT_RETURN_TO_LAUNCHER:
|
||||
quitGame();
|
||||
return;
|
||||
|
||||
case Common::EVENT_SCREEN_CHANGED:
|
||||
_gfx->computeScreenViewport();
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
break;
|
||||
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
|
||||
switch (event.customType) {
|
||||
case kActionSkip:
|
||||
maxWait = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Common::EVENT_RBUTTONDOWN:
|
||||
// fallthrough
|
||||
case Common::EVENT_LBUTTONDOWN:
|
||||
if (g_system->hasFeature(OSystem::kFeatureTouchscreen))
|
||||
maxWait = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
drawTitle();
|
||||
_gfx->flipBuffer();
|
||||
g_system->updateScreen();
|
||||
g_system->delayMillis(15); // try to target ~60 FPS
|
||||
}
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
}
|
||||
|
||||
Graphics::Surface *FreescapeEngine::drawStringsInSurface(const Common::Array<Common::String> &lines, Graphics::Surface *surface) {
|
||||
if (!_fontLoaded)
|
||||
return surface;
|
||||
|
||||
uint32 color = 0;
|
||||
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
switch (_renderMode) {
|
||||
case Common::kRenderCGA:
|
||||
case Common::kRenderHercG:
|
||||
color = 1;
|
||||
break;
|
||||
case Common::kRenderZX:
|
||||
color = isCastle() ? 7 : 6;
|
||||
break;
|
||||
case Common::kRenderCPC:
|
||||
color = _gfx->_underFireBackgroundColor;
|
||||
if (color == uint32(-1))
|
||||
color = 14;
|
||||
break;
|
||||
default:
|
||||
color = 14;
|
||||
}
|
||||
uint8 r, g, b;
|
||||
|
||||
_gfx->readFromPalette(color, r, g, b);
|
||||
if (isAmiga() || isAtariST()) {
|
||||
r = 0xFF;
|
||||
g = 0xFF;
|
||||
b = 0x55;
|
||||
}
|
||||
|
||||
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
|
||||
|
||||
int x = _viewArea.left + 3;
|
||||
int y = _viewArea.top + 3;
|
||||
|
||||
for (int i = 0; i < int(lines.size()); i++) {
|
||||
drawStringInSurface(lines[i], x, y, front, back, surface);
|
||||
y = y + (isCastle() ? 12 : 9);
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
void FreescapeEngine::borderScreen() {
|
||||
if (!_border)
|
||||
return;
|
||||
|
||||
if (isDriller()) {
|
||||
if (isAmiga() || isAtariST())
|
||||
return; // TODO: add animation
|
||||
|
||||
drawBorderScreenAndWait(nullptr, 6 * 60);
|
||||
// Modify and reload the border
|
||||
_border->fillRect(_viewArea, _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0, 0));
|
||||
delete _borderTexture;
|
||||
_borderTexture = nullptr;
|
||||
loadBorder();
|
||||
|
||||
if (isDemo())
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDOS() || isSpectrum() || isCPC()) {
|
||||
Common::Array<Common::String> lines;
|
||||
int pad = 25;
|
||||
if (isDOS()) {
|
||||
if (isDOS() && !isCastle())
|
||||
pad = 30;
|
||||
|
||||
lines.push_back(centerAndPadString("CONFIGURATION MENU", pad));
|
||||
lines.push_back("");
|
||||
lines.push_back(centerAndPadString("1: KEYBOARD ONLY ", pad));
|
||||
lines.push_back(centerAndPadString("2: IBM JOYSTICK ", pad));
|
||||
lines.push_back(centerAndPadString("3: AMSTRAD JOYSTICK", pad));
|
||||
lines.push_back("");
|
||||
lines.push_back("");
|
||||
lines.push_back(centerAndPadString("SPACEBAR: BEGIN MISSION", pad));
|
||||
lines.push_back("");
|
||||
lines.push_back(centerAndPadString("COPYRIGHT 1988 INCENTIVE", pad));
|
||||
} else if (isSpectrum() || isCPC()) {
|
||||
if (isCastle())
|
||||
pad = 22;
|
||||
|
||||
if (_language == Common::ES_ESP) {
|
||||
assert(isCastle());
|
||||
lines.push_back(centerAndPadString("MENU DE OPCIONES", pad));
|
||||
lines.push_back("");
|
||||
lines.push_back(centerAndPadString("1 TECLADO ", pad));
|
||||
lines.push_back(centerAndPadString("2 JOYSTICK SINCLAIR", pad));
|
||||
lines.push_back(centerAndPadString("3 JOYSTICK KEMSTON ", pad));
|
||||
lines.push_back(centerAndPadString("4 JOYSTICK CURSOR ", pad));
|
||||
lines.push_back("");
|
||||
lines.push_back(centerAndPadString("ENTER: EMPEZAR MISION", pad));
|
||||
lines.push_back(centerAndPadString("(c) 1990 INCENTIVE", pad));
|
||||
} else {
|
||||
lines.push_back(centerAndPadString("CONTROL OPTIONS", pad));
|
||||
lines.push_back("");
|
||||
lines.push_back(centerAndPadString("1 KEYBOARD ", pad));
|
||||
lines.push_back(centerAndPadString("2 SINCLAIR JOYSTICK", pad));
|
||||
lines.push_back(centerAndPadString("3 KEMSTON JOYSTICK ", pad));
|
||||
lines.push_back(centerAndPadString("4 CURSOR JOYSTICK ", pad));
|
||||
lines.push_back("");
|
||||
lines.push_back(centerAndPadString("ENTER: BEGIN MISSION", pad));
|
||||
if (!isCastle())
|
||||
lines.push_back("");;
|
||||
lines.push_back(centerAndPadString("(c) 1990 INCENTIVE", pad));
|
||||
}
|
||||
}
|
||||
|
||||
lines.push_back("");
|
||||
|
||||
uint32 color = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
|
||||
Graphics::Surface *surface = new Graphics::Surface();
|
||||
surface->create(_screenW, _screenH, _gfx->_texturePixelFormat);
|
||||
surface->fillRect(_fullscreenViewArea, color);
|
||||
|
||||
surface = drawStringsInSurface(lines, surface);
|
||||
drawBorderScreenAndWait(surface, 6 * 60);
|
||||
surface->free();
|
||||
delete surface;
|
||||
}
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawFullscreenMessageAndWait(Common::String message) {
|
||||
int letterPerLine = 0;
|
||||
int numberOfLines = 0;
|
||||
|
||||
if (isDOS()) {
|
||||
letterPerLine = 28;
|
||||
numberOfLines = 10;
|
||||
} else if (isSpectrum() || isCPC()) {
|
||||
letterPerLine = 24;
|
||||
numberOfLines = 12;
|
||||
} else if (isAtariST()) {
|
||||
letterPerLine = 32;
|
||||
numberOfLines = 10;
|
||||
}
|
||||
|
||||
Common::Array<Common::String> lines;
|
||||
for (int i = 0; i < numberOfLines; i++) {
|
||||
lines.push_back(message.substr(letterPerLine * i, letterPerLine));
|
||||
}
|
||||
|
||||
uint32 color = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
|
||||
Graphics::Surface *surface = new Graphics::Surface();
|
||||
surface->create(_screenW, _screenH, _gfx->_texturePixelFormat);
|
||||
surface->fillRect(_fullscreenViewArea, color);
|
||||
|
||||
surface = drawStringsInSurface(lines, surface);
|
||||
drawBorderScreenAndWait(surface);
|
||||
surface->free();
|
||||
delete surface;
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawBorderScreenAndWait(Graphics::Surface *surface, int maxWait) {
|
||||
for (int i = 0; i < maxWait; i++) {
|
||||
Common::Event event;
|
||||
while (_eventManager->pollEvent(event)) {
|
||||
switch (event.type) {
|
||||
case Common::EVENT_QUIT:
|
||||
case Common::EVENT_RETURN_TO_LAUNCHER:
|
||||
quitGame();
|
||||
return;
|
||||
|
||||
case Common::EVENT_SCREEN_CHANGED:
|
||||
_gfx->computeScreenViewport();
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
break;
|
||||
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
|
||||
switch (event.customType) {
|
||||
case kActionSkip:
|
||||
maxWait = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Common::EVENT_KEYDOWN:
|
||||
switch (event.kbd.keycode) {
|
||||
case Common::KEYCODE_d:
|
||||
_demoMode = true;
|
||||
maxWait = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Common::EVENT_RBUTTONDOWN:
|
||||
// fallthrough
|
||||
case Common::EVENT_LBUTTONDOWN:
|
||||
if (g_system->hasFeature(OSystem::kFeatureTouchscreen))
|
||||
maxWait = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
drawBorder();
|
||||
if (surface)
|
||||
drawFullscreenSurface(surface);
|
||||
_gfx->flipBuffer();
|
||||
g_system->updateScreen();
|
||||
g_system->delayMillis(15); // try to target ~60 FPS
|
||||
}
|
||||
playSound(_soundIndexMenu, false, _soundFxHandle);
|
||||
_gfx->clear(0, 0, 0, true);
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawFullscreenSurface(Graphics::Surface *surface) {
|
||||
if (!_uiTexture)
|
||||
_uiTexture = _gfx->createTexture(surface);
|
||||
else
|
||||
_uiTexture->update(surface);
|
||||
|
||||
_gfx->setViewport(_fullscreenViewArea);
|
||||
_gfx->drawTexturedRect2D(_fullscreenViewArea, _fullscreenViewArea, _uiTexture);
|
||||
_gfx->setViewport(_viewArea);
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawUI() {
|
||||
Graphics::Surface *surface = nullptr;
|
||||
if (_border) { // This can be removed when all the borders are loaded
|
||||
uint32 gray = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0xA0, 0xA0, 0xA0);
|
||||
surface = new Graphics::Surface();
|
||||
surface->create(_screenW, _screenH, _gfx->_texturePixelFormat);
|
||||
surface->fillRect(_fullscreenViewArea, gray);
|
||||
} else
|
||||
return;
|
||||
|
||||
if (isDOS())
|
||||
drawDOSUI(surface);
|
||||
else if (isC64())
|
||||
drawC64UI(surface);
|
||||
else if (isSpectrum())
|
||||
drawZXUI(surface);
|
||||
else if (isCPC())
|
||||
drawCPCUI(surface);
|
||||
else if (isAmiga() || isAtariST())
|
||||
drawAmigaAtariSTUI(surface);
|
||||
|
||||
drawFullscreenSurface(surface);
|
||||
|
||||
_gfx->setViewport(_fullscreenViewArea);
|
||||
_gfx->renderCrossair(_crossairPosition);
|
||||
|
||||
surface->free();
|
||||
delete surface;
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawInfoMenu() {
|
||||
warning("Function \"%s\" not implemented", __FUNCTION__);
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawCrossair(Graphics::Surface *surface) {
|
||||
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
|
||||
|
||||
surface->drawLine(_crossairPosition.x - 3, _crossairPosition.y, _crossairPosition.x - 2, _crossairPosition.y, white);
|
||||
surface->drawLine(_crossairPosition.x + 2, _crossairPosition.y, _crossairPosition.x + 3, _crossairPosition.y, white);
|
||||
|
||||
surface->drawLine(_crossairPosition.x, _crossairPosition.y - 3, _crossairPosition.x, _crossairPosition.y - 2, white);
|
||||
surface->drawLine(_crossairPosition.x, _crossairPosition.y + 2, _crossairPosition.x, _crossairPosition.y + 3, white);
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawAmigaAtariSTUI(Graphics::Surface *surface) {
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawDOSUI(Graphics::Surface *surface) {
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawZXUI(Graphics::Surface *surface) {
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawCPCUI(Graphics::Surface *surface) {
|
||||
}
|
||||
|
||||
void FreescapeEngine::drawC64UI(Graphics::Surface *surface) {
|
||||
}
|
||||
|
||||
} // End of namespace Freescape
|
||||
426
engines/freescape/unpack.cpp
Normal file
426
engines/freescape/unpack.cpp
Normal file
@@ -0,0 +1,426 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This code was modified from https://github.com/w4kfu/unEXEPACK/blob/master/unpack.c
|
||||
|
||||
*/
|
||||
|
||||
#include "common/file.h"
|
||||
#include "common/memstream.h"
|
||||
|
||||
#include "freescape/freescape.h"
|
||||
|
||||
namespace Freescape {
|
||||
|
||||
#define DOS_SIGNATURE 0x5A4D
|
||||
#define EXEPACK_SIGNATURE 0x4252
|
||||
|
||||
struct memstream {
|
||||
unsigned char *buf;
|
||||
unsigned int length;
|
||||
unsigned int pos;
|
||||
};
|
||||
|
||||
struct dos_header {
|
||||
unsigned short e_magic;
|
||||
unsigned short e_cblp;
|
||||
unsigned short e_cp;
|
||||
unsigned short e_crlc;
|
||||
unsigned short e_cparhdr;
|
||||
unsigned short e_minalloc;
|
||||
unsigned short e_maxalloc;
|
||||
unsigned short e_ss;
|
||||
unsigned short e_sp;
|
||||
unsigned short e_csum;
|
||||
unsigned short e_ip;
|
||||
unsigned short e_cs;
|
||||
unsigned short e_lfarlc;
|
||||
unsigned short e_ovno;
|
||||
};
|
||||
|
||||
struct exepack_header {
|
||||
unsigned short real_ip;
|
||||
unsigned short real_cs;
|
||||
unsigned short mem_start;
|
||||
unsigned short exepack_size;
|
||||
unsigned short real_sp;
|
||||
unsigned short real_ss;
|
||||
unsigned short dest_len;
|
||||
unsigned short skip_len;
|
||||
unsigned short signature;
|
||||
};
|
||||
|
||||
void reverse(unsigned char *s, size_t length);
|
||||
void unpack_data(unsigned char *unpacked_data, unsigned char *buf, unsigned int *unpacked_data_size, unsigned int packed_data_len);
|
||||
Common::MemoryReadStream *unpack(struct memstream *ms);
|
||||
unsigned char *create_reloc_table(struct memstream *ms, struct dos_header *dh, struct exepack_header *eh, unsigned int *reloc_table_size);
|
||||
Common::MemoryReadStream *writeExe(struct dos_header *dh, unsigned char *unpacked_data, unsigned int unpacked_data_size, unsigned char *reloc, size_t reloc_size, size_t padding);
|
||||
Common::MemoryReadStream *craftexec(struct dos_header *dh, struct exepack_header *eh, unsigned char *unpacked_data, unsigned int unpacked_data_size, unsigned char *reloc, unsigned int reloc_size);
|
||||
|
||||
// Utils
|
||||
int test_dos_header(struct memstream *ms);
|
||||
void msopen(Common::File &file, struct memstream *ms);
|
||||
unsigned int msread(struct memstream *ms, void *buf, unsigned int count);
|
||||
int mscanread(struct memstream *ms, unsigned int count);
|
||||
unsigned int msgetavailable(struct memstream *ms);
|
||||
void msseek(struct memstream *ms, unsigned int offset);
|
||||
void msclose(struct memstream *ms);
|
||||
void *memmem(void *l, size_t l_len, const void *s, size_t s_len);
|
||||
|
||||
void reverse(unsigned char *s, size_t length) {
|
||||
size_t i, j;
|
||||
unsigned char c;
|
||||
|
||||
if (length == 0x00) {
|
||||
return;
|
||||
}
|
||||
for (i = 0, j = length - 1; i < j; i++, j--) {
|
||||
c = s[i];
|
||||
s[i] = s[j];
|
||||
s[j] = c;
|
||||
}
|
||||
}
|
||||
|
||||
/* buf is already reversed, because EXEPACK use backward processing */
|
||||
void unpack_data(unsigned char *unpacked_data, unsigned char *buf, unsigned int *unpacked_data_size, unsigned int packed_data_len) {
|
||||
unsigned char opcode;
|
||||
unsigned short count;
|
||||
unsigned char fillbyte;
|
||||
unsigned char *save_buf = NULL;
|
||||
unsigned char *save_unp = NULL;
|
||||
unsigned int cur_unpacked_data_size = 0x00;
|
||||
unsigned int cur_index = 0x00;
|
||||
|
||||
save_buf = buf;
|
||||
save_unp = unpacked_data;
|
||||
while (*buf == 0xFF) {
|
||||
buf++;
|
||||
}
|
||||
while (1) {
|
||||
opcode = *buf++;
|
||||
count = *(buf) * 0x100 + *(buf + 1);
|
||||
buf += 2;
|
||||
if ((opcode & 0xFE) == 0xB0) {
|
||||
fillbyte = *buf++;
|
||||
if ((cur_unpacked_data_size + count) > *unpacked_data_size) {
|
||||
debug("overflow");
|
||||
}
|
||||
memset(unpacked_data, fillbyte, count);
|
||||
unpacked_data += count;
|
||||
cur_unpacked_data_size += count;
|
||||
} else if ((opcode & 0xFE) == 0xB2) {
|
||||
if ((cur_unpacked_data_size + count) > *unpacked_data_size) {
|
||||
debug("overflow");
|
||||
}
|
||||
memcpy(unpacked_data, buf, count);
|
||||
unpacked_data += count;
|
||||
cur_unpacked_data_size += count;
|
||||
buf += count;
|
||||
} else {
|
||||
debug("unknown opcode");
|
||||
}
|
||||
if ((opcode & 1) == 1) {
|
||||
break;
|
||||
}
|
||||
if ((unsigned int)(buf - save_buf) >= packed_data_len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
cur_index = (unsigned int)(buf - save_buf);
|
||||
if (cur_index < packed_data_len) {
|
||||
if ((packed_data_len - cur_index) > (*unpacked_data_size - (unpacked_data - save_unp))) {
|
||||
debug("Data left are too large!");
|
||||
}
|
||||
memcpy(unpacked_data, buf, packed_data_len - cur_index);
|
||||
cur_unpacked_data_size += packed_data_len - cur_index;
|
||||
}
|
||||
*unpacked_data_size = cur_unpacked_data_size;
|
||||
}
|
||||
|
||||
unsigned char *create_reloc_table(struct memstream *ms, struct dos_header *dh, struct exepack_header *eh, unsigned int *reloc_table_size) {
|
||||
unsigned int exepack_offset = 0x00;
|
||||
unsigned int reloc_length;
|
||||
int nb_reloc;
|
||||
unsigned char *buf_reloc = NULL;
|
||||
unsigned char *reloc = NULL;
|
||||
int i, j;
|
||||
unsigned short count = 0x00;
|
||||
unsigned short entry;
|
||||
unsigned int reloc_position = 0x00;
|
||||
|
||||
exepack_offset = (dh->e_cparhdr + dh->e_cs) * 16;
|
||||
msseek(ms, exepack_offset);
|
||||
reloc = (unsigned char*)memmem(ms->buf + exepack_offset, msgetavailable(ms), "Packed file is corrupt", strlen("Packed file is corrupt"));
|
||||
if (!reloc) {
|
||||
debug("Cannot find string \"Packed file is corrupt\", is it really EXEPACK ?");
|
||||
}
|
||||
|
||||
reloc_length = (unsigned int)(eh->exepack_size - ((reloc - (ms->buf + exepack_offset)) & 0xFFFFFFFF) + strlen("Packed file is corrupt"));
|
||||
nb_reloc = (reloc_length - 16 * sizeof(unsigned short)) / 2;
|
||||
*reloc_table_size = nb_reloc * 2 * sizeof(unsigned short);
|
||||
buf_reloc = (unsigned char*)malloc(sizeof(char) * *reloc_table_size);
|
||||
assert(buf_reloc);
|
||||
reloc += strlen("Packed file is corrupt");
|
||||
msseek(ms, (reloc - ms->buf) & 0xFFFFFFFF);
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (msread(ms, &count, sizeof(unsigned short)) != sizeof(unsigned short)) {
|
||||
debug("msread failed");
|
||||
}
|
||||
for (j = 0; j < count; j++) {
|
||||
if (msread(ms, &entry, sizeof(unsigned short)) != sizeof(unsigned short)) {
|
||||
debug("msread failed");
|
||||
}
|
||||
if (reloc_position >= *reloc_table_size) {
|
||||
debug("overflow");
|
||||
}
|
||||
*(unsigned short*)(buf_reloc + reloc_position) = entry;
|
||||
reloc_position += 2;
|
||||
if (reloc_position >= *reloc_table_size) {
|
||||
debug("overflow");
|
||||
}
|
||||
*(unsigned short*)(buf_reloc + reloc_position) = (i * 0x1000) & 0xFFFF;
|
||||
reloc_position += 2;
|
||||
}
|
||||
}
|
||||
*reloc_table_size = reloc_position;
|
||||
return buf_reloc;
|
||||
}
|
||||
|
||||
Common::MemoryReadStream *writeExe(struct dos_header *dh, unsigned char *unpacked_data, unsigned int unpacked_data_size, unsigned char *reloc, size_t reloc_size, size_t padding) {
|
||||
Common::MemoryWriteStreamDynamic buf(DisposeAfterUse::NO);
|
||||
|
||||
buf.write(dh, sizeof(struct dos_header));
|
||||
buf.write(reloc, reloc_size);
|
||||
for (size_t i = 0; i < padding; i++) {
|
||||
buf.write("\x00", 1);
|
||||
}
|
||||
buf.write(unpacked_data, unpacked_data_size);
|
||||
return (new Common::MemoryReadStream(buf.getData(), buf.size()));
|
||||
}
|
||||
|
||||
Common::MemoryReadStream *craftexec(struct dos_header *dh, struct exepack_header *eh, unsigned char *unpacked_data, unsigned int unpacked_data_size, unsigned char *reloc, unsigned int reloc_size) {
|
||||
struct dos_header dhead;
|
||||
int header_size;
|
||||
int total_length;
|
||||
int padding_length;
|
||||
|
||||
memset(&dhead, 0, sizeof(struct dos_header));
|
||||
header_size = sizeof(struct dos_header) + reloc_size;
|
||||
dhead.e_magic = DOS_SIGNATURE;
|
||||
dhead.e_cparhdr = (header_size / 16) & 0xFFFF;
|
||||
dhead.e_cparhdr = (dhead.e_cparhdr / 32 + 1) * 32;
|
||||
padding_length = dhead.e_cparhdr * 16 - header_size;
|
||||
total_length = header_size + padding_length + unpacked_data_size;
|
||||
dhead.e_ss = eh->real_ss;
|
||||
dhead.e_sp = eh->real_sp;
|
||||
dhead.e_ip = eh->real_ip;
|
||||
dhead.e_cs = eh->real_cs;
|
||||
dhead.e_minalloc = dh->e_minalloc;
|
||||
dhead.e_maxalloc = 0xFFFF;
|
||||
dhead.e_lfarlc = sizeof(struct dos_header);
|
||||
dhead.e_crlc = (reloc_size / (2 * sizeof(unsigned short))) & 0xFFFF;
|
||||
dhead.e_cblp = total_length % 512;
|
||||
dhead.e_cp = (total_length / 512 + 1) & 0xFFFF;
|
||||
//print_dos_header(&dhead);
|
||||
return writeExe(&dhead, unpacked_data, unpacked_data_size, reloc, reloc_size, padding_length);
|
||||
}
|
||||
|
||||
Common::MemoryReadStream *unpack(struct memstream *ms) {
|
||||
struct dos_header dh;
|
||||
struct exepack_header eh;
|
||||
unsigned int exepack_offset = 0x00;
|
||||
unsigned char *unpacked_data = NULL;
|
||||
unsigned int unpacked_data_size = 0x00;
|
||||
unsigned int packed_data_start;
|
||||
unsigned int packed_data_end;
|
||||
unsigned int packed_data_len;
|
||||
unsigned int reloc_size;
|
||||
unsigned char *reloc = NULL;
|
||||
|
||||
if (msread(ms, &dh, sizeof(struct dos_header)) != sizeof(struct dos_header)) {
|
||||
return nullptr;
|
||||
}
|
||||
//print_dos_header(&dh);
|
||||
exepack_offset = (dh.e_cparhdr + dh.e_cs) * 16;
|
||||
msseek(ms, exepack_offset);
|
||||
if (msread(ms, &eh, sizeof(struct exepack_header)) != sizeof(struct exepack_header)) {
|
||||
return nullptr;
|
||||
}
|
||||
//print_exepack_header(&eh);
|
||||
if ((eh.signature != EXEPACK_SIGNATURE && eh.skip_len != EXEPACK_SIGNATURE) || eh.exepack_size == 0x00) {
|
||||
debug("This is not a valid EXEPACK executable");
|
||||
return nullptr;
|
||||
}
|
||||
debug("Header exepack = %X\n", exepack_offset);
|
||||
//print_exepack_header(&eh);
|
||||
unpacked_data_size = eh.dest_len * 16;
|
||||
unpacked_data = (unsigned char*)malloc(sizeof(char) * unpacked_data_size);
|
||||
assert(unpacked_data);
|
||||
memset(unpacked_data, 0x00, sizeof(char) * unpacked_data_size);
|
||||
packed_data_start = dh.e_cparhdr * 16;
|
||||
packed_data_end = exepack_offset;
|
||||
packed_data_len = packed_data_end - packed_data_start;
|
||||
msseek(ms, packed_data_start);
|
||||
if (mscanread(ms, packed_data_len) == 0x00) {
|
||||
free(unpacked_data);
|
||||
return nullptr;
|
||||
}
|
||||
reverse(ms->buf + packed_data_start, packed_data_len);
|
||||
unpack_data(unpacked_data, ms->buf + packed_data_start, &unpacked_data_size, packed_data_len);
|
||||
reverse(unpacked_data, unpacked_data_size);
|
||||
reloc = create_reloc_table(ms, &dh, &eh, &reloc_size);
|
||||
Common::MemoryReadStream *ret = craftexec(&dh, &eh, unpacked_data, unpacked_data_size, reloc, reloc_size);
|
||||
free(reloc);
|
||||
free(unpacked_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *memmem(void *l, size_t l_len, const void *s, size_t s_len) {
|
||||
char *cur, *last;
|
||||
char *cl = (char *)l;
|
||||
const char *cs = (const char *)s;
|
||||
|
||||
if (l_len == 0 || s_len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (l_len < s_len) {
|
||||
return NULL;
|
||||
}
|
||||
if (s_len == 1) {
|
||||
return (void *)memchr(l, (int)*cs, l_len);
|
||||
}
|
||||
last = cl + l_len - s_len;
|
||||
for (cur = (char *)cl; cur <= last; cur++) {
|
||||
if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0) {
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void msopen(Common::File &file, struct memstream *ms) {
|
||||
assert(ms);
|
||||
|
||||
ms->buf = (unsigned char*)malloc(sizeof(char) * file.size());
|
||||
assert(ms->buf);
|
||||
|
||||
assert(file.read(ms->buf, file.size()) == file.size());
|
||||
ms->pos = 0x00;
|
||||
ms->length = file.size();
|
||||
}
|
||||
|
||||
unsigned int msread(struct memstream *ms, void *buf, unsigned int count) {
|
||||
unsigned int length;
|
||||
|
||||
if (buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (ms->pos > ms->length) {
|
||||
debug("invalid read");
|
||||
}
|
||||
if (count < (ms->length - ms->pos)) {
|
||||
length = count;
|
||||
} else {
|
||||
length = ms->length - ms->pos;
|
||||
}
|
||||
if (length > 0) {
|
||||
memcpy(buf, ms->buf + ms->pos, length);
|
||||
}
|
||||
ms->pos += length;
|
||||
return length;
|
||||
}
|
||||
|
||||
int mscanread(struct memstream *ms, unsigned int count) {
|
||||
if (ms->pos > ms->length) {
|
||||
return 0;
|
||||
}
|
||||
if (count > (ms->length - ms->pos)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned int msgetavailable(struct memstream *ms) {
|
||||
if (ms->pos > ms->length) {
|
||||
return 0;
|
||||
}
|
||||
return ms->length - ms->pos;
|
||||
}
|
||||
|
||||
void msseek(struct memstream *ms, unsigned int offset) {
|
||||
if (offset > ms->length) {
|
||||
debug("invalid seek : 0x%X", offset);
|
||||
}
|
||||
ms->pos = offset;
|
||||
}
|
||||
|
||||
void msclose(struct memstream *ms) {
|
||||
if (ms != NULL) {
|
||||
if (ms->buf != NULL) {
|
||||
free(ms->buf);
|
||||
ms->buf = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int test_dos_header(struct memstream *ms) {
|
||||
struct dos_header dh;
|
||||
|
||||
if (ms == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (msread(ms, &dh, sizeof(struct dos_header)) != sizeof(struct dos_header)) {
|
||||
return 0;
|
||||
}
|
||||
msseek(ms, 0x00);
|
||||
if (dh.e_magic != DOS_SIGNATURE) {
|
||||
return 0;
|
||||
}
|
||||
/* at least one page */
|
||||
if (dh.e_cp == 0) {
|
||||
return 0;
|
||||
}
|
||||
/* last page must not hold 0 bytes */
|
||||
if (dh.e_cblp == 0) {
|
||||
return 0;
|
||||
}
|
||||
/* not even number of paragraphs */
|
||||
if (dh.e_cparhdr % 2 != 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
Common::MemoryReadStream *unpackEXE(Common::File &file) {
|
||||
struct memstream ms;
|
||||
msopen(file, &ms);
|
||||
if (test_dos_header(&ms) == 0) {
|
||||
msclose(&ms);
|
||||
return nullptr;
|
||||
}
|
||||
Common::MemoryReadStream *ret = unpack(&ms);
|
||||
msclose(&ms);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user