diff --git a/engines/stark/formats/xrc.cpp b/engines/stark/formats/xrc.cpp index 8ecffcc2a6c..299b3d932c1 100644 --- a/engines/stark/formats/xrc.cpp +++ b/engines/stark/formats/xrc.cpp @@ -45,6 +45,7 @@ #include "engines/stark/resources/light.h" #include "engines/stark/resources/lipsync.h" #include "engines/stark/resources/location.h" +#include "engines/stark/resources/path.h" #include "engines/stark/resources/pattable.h" #include "engines/stark/resources/root.h" #include "engines/stark/resources/script.h" @@ -228,6 +229,9 @@ Resources::Object *XRCReader::createResource(XRCReadStream *stream, Resources::O case Resources::Type::kSoundItem: resource = new Resources::Sound(parent, subType, index, name); break; + case Resources::Type::kPath: + resource = Resources::Path::construct(parent, subType, index, name); + break; case Resources::Type::kFloorField: resource = new Resources::FloorField(parent, subType, index, name); break; diff --git a/engines/stark/module.mk b/engines/stark/module.mk index 57ac163191a..6ca6cfee945 100644 --- a/engines/stark/module.mk +++ b/engines/stark/module.mk @@ -49,6 +49,7 @@ MODULE_OBJS := \ resources/lipsync.o \ resources/location.o \ resources/object.o \ + resources/path.o \ resources/pattable.o \ resources/root.o \ resources/script.o \ diff --git a/engines/stark/resources/object.cpp b/engines/stark/resources/object.cpp index 7c3ca66c45c..20397a67c81 100644 --- a/engines/stark/resources/object.cpp +++ b/engines/stark/resources/object.cpp @@ -62,6 +62,7 @@ const char *Type::getName() const { { Type::kAnimScript, "AnimScript" }, { Type::kAnimScriptItem, "AnimScriptItem" }, { Type::kSoundItem, "SoundItem" }, + { Type::kPath, "Path" }, { Type::kFloorField, "FloorField" }, { Type::kBookmark, "Bookmark" }, { Type::kKnowledgeSet, "KnowledgeSet" }, diff --git a/engines/stark/resources/object.h b/engines/stark/resources/object.h index 089119c2986..5147c7e72f1 100644 --- a/engines/stark/resources/object.h +++ b/engines/stark/resources/object.h @@ -55,6 +55,7 @@ public: kAnimScript = 14, kAnimScriptItem = 15, kSoundItem = 16, + kPath = 17, kFloorField = 18, kBookmark = 19, kKnowledgeSet = 20, diff --git a/engines/stark/resources/path.cpp b/engines/stark/resources/path.cpp new file mode 100644 index 00000000000..34b7c2e27a1 --- /dev/null +++ b/engines/stark/resources/path.cpp @@ -0,0 +1,123 @@ +/* ResidualVM - A 3D game interpreter + * + * ResidualVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "engines/stark/resources/path.h" + +#include "engines/stark/formats/xrc.h" + +namespace Stark { +namespace Resources { + +Object *Path::construct(Object *parent, byte subType, uint16 index, const Common::String &name) { + switch (subType) { + case kPath2D: + return new Path2D(parent, subType, index, name); + case kPath3D: + return new Path3D(parent, subType, index, name); + default: + error("Unknown path subtype %d", subType); + } +} + +Path::~Path() { +} + +Path::Path(Object *parent, byte subType, uint16 index, const Common::String &name) : + Object(parent, subType, index, name) { + _type = TYPE; +} + +void Path::readData(Formats::XRCReadStream *stream) { + _field_30 = stream->readUint32LE(); +} + +void Path::printData() { + debug("field_30: %d", _field_30); +} + +Path2D::Path2D(Object *parent, byte subType, uint16 index, const Common::String &name) : + Path(parent, subType, index, name) { +} + +void Path2D::readData(Formats::XRCReadStream *stream) { + Path::readData(stream); + + uint32 stepCount = stream->readUint32LE(); + for (uint i = 0; i < stepCount; i++) { + Step step; + step.weight = stream->readFloat(); + step.position = stream->readPoint(); + + _steps.push_back(step); + } + + stream->readUint32LE(); // Unused in the original +} + +void Path2D::printData() { + Path::printData(); + + for (uint i = 0; i < _steps.size(); i++) { + debug("step[%d]: (x %d, y %d), weight: %f", i, + _steps[i].position.x, _steps[i].position.y, _steps[i].weight); + } +} + +Path2D::~Path2D() { +} + +Path3D::Path3D(Object *parent, byte subType, uint16 index, const Common::String &name) : + Path(parent, subType, index, name), + _sortKey(0) { +} + +void Path3D::readData(Formats::XRCReadStream *stream) { + Path::readData(stream); + + uint32 stepCount = stream->readUint32LE(); + for (uint i = 0; i < stepCount; i++) { + Step step; + step.weight = stream->readFloat(); + step.position = stream->readVector3(); + + _steps.push_back(step); + } + + _sortKey = stream->readFloat(); +} + +void Path3D::printData() { + Path::printData(); + + for (uint i = 0; i < _steps.size(); i++) { + debug("step[%d]: (x %f, y %f, z %f), weight: %f", i, + _steps[i].position.x(), _steps[i].position.y(), _steps[i].position.z(), _steps[i].weight); + } + + debug("sortKey: %f", _sortKey); +} + +Path3D::~Path3D() { +} + +} // End of namespace Resources +} // End of namespace Stark diff --git a/engines/stark/resources/path.h b/engines/stark/resources/path.h new file mode 100644 index 00000000000..37debdc9ba4 --- /dev/null +++ b/engines/stark/resources/path.h @@ -0,0 +1,108 @@ +/* ResidualVM - A 3D game interpreter + * + * ResidualVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef STARK_RESOURCES_PATH_H +#define STARK_RESOURCES_PATH_H + +#include +#include +#include "common/str.h" + +#include "engines/stark/resources/object.h" + +namespace Stark { + +namespace Formats { +class XRCReadStream; +} + +namespace Resources { + +class Path : public Object { +public: + static const Type::ResourceType TYPE = Type::kPath; + + enum SubType { + kPath2D = 1, + kPath3D = 2 + }; + + /** Path factory */ + static Object *construct(Object *parent, byte subType, uint16 index, const Common::String &name); + + Path(Object *parent, byte subType, uint16 index, const Common::String &name); + virtual ~Path(); + + // Resource API + virtual void readData(Formats::XRCReadStream *stream) override; + +protected: + void printData() override; + + uint32 _field_30; +}; + +class Path2D : public Path { +public: + Path2D(Object *parent, byte subType, uint16 index, const Common::String &name); + virtual ~Path2D(); + + struct Step { + float weight; + Common::Point position; + }; + + // Resource API + virtual void readData(Formats::XRCReadStream *stream) override; + +private: + // Resource API + void printData(); + + Common::Array _steps; +}; + +class Path3D : public Path { +public: + Path3D(Object *parent, byte subType, uint16 index, const Common::String &name); + virtual ~Path3D(); + + struct Step { + float weight; + Math::Vector3d position; + }; + + // Resource API + virtual void readData(Formats::XRCReadStream *stream) override; + +private: + // Resource API + void printData(); + + Common::Array _steps; + float _sortKey; +}; + +} // End of namespace Resources +} // End of namespace Stark + +#endif // STARK_RESOURCES_PATH_H