STARK: Add some Item resource types

This commit is contained in:
Bastien Bouclet
2015-01-01 14:28:18 +01:00
parent 46bec3da84
commit cae49074ea
7 changed files with 283 additions and 2 deletions
+1
View File
@@ -15,6 +15,7 @@ MODULE_OBJS := \
resources/command.o \
resources/floor.o \
resources/floorface.o \
resources/item.o \
resources/layer.o \
resources/level.o \
resources/location.o \
+141
View File
@@ -0,0 +1,141 @@
/* 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 "common/debug.h"
#include "engines/stark/resources/item.h"
#include "engines/stark/xrcreader.h"
namespace Stark {
Resource *Item::construct(Resource *parent, byte subType, uint16 index, const Common::String &name) {
switch (subType) {
case kItemSub1:
return new UnimplementedResource(parent, TYPE, subType, index, name);
case kItemSub2:
return new UnimplementedResource(parent, TYPE, subType, index, name);
case kItemSub3:
return new UnimplementedResource(parent, TYPE, subType, index, name);
case kItemSub5:
case kItemSub6:
return new ItemSub56(parent, subType, index, name);
case kItemSub7:
case kItemSub8:
return new ItemSub78(parent, subType, index, name);
case kItemSub10:
return new UnimplementedResource(parent, TYPE, subType, index, name);
default:
error("Unknown item subtype %d", subType);
}
}
Item::~Item() {
}
Item::Item(Resource *parent, byte subType, uint16 index, const Common::String &name) :
Resource(parent, subType, index, name),
_field_34(true),
_field_38(0) {
_type = TYPE;
}
void Item::readData(XRCReadStream *stream) {
_field_34 = stream->readBool();
_field_38 = stream->readSint32LE();
}
void Item::printData() {
debug("field_34: %d", _field_34);
debug("field_38: %d", _field_38);
}
ItemVisual::~ItemVisual() {
}
ItemVisual::ItemVisual(Resource *parent, byte subType, uint16 index, const Common::String &name) :
Item(parent, subType, index, name),
_field_44(1) {
}
void ItemVisual::readData(XRCReadStream *stream) {
Item::readData(stream);
_field_44 = stream->readUint32LE();
}
void ItemVisual::printData() {
Item::printData();
debug("field_44: %d", _field_44);
}
ItemSub5610::~ItemSub5610() {
}
ItemSub5610::ItemSub5610(Resource *parent, byte subType, uint16 index, const Common::String &name) :
ItemVisual(parent, subType, index, name) {
}
ItemSub56::~ItemSub56() {
}
ItemSub56::ItemSub56(Resource *parent, byte subType, uint16 index, const Common::String &name) :
ItemSub5610(parent, subType, index, name),
_field_6C(0) {
}
void ItemSub56::readData(XRCReadStream *stream) {
ItemSub5610::readData(stream);
_field_6C = stream->readSint32LE();
_position = stream->readPoint();
}
void ItemSub56::printData() {
ItemSub5610::printData();
debug("field_6C: %d", _field_6C);
debug("position: x %d, y %d", _position.x, _position.y);
}
ItemSub78::~ItemSub78() {
}
ItemSub78::ItemSub78(Resource *parent, byte subType, uint16 index, const Common::String &name) :
ItemVisual(parent, subType, index, name) {
}
void ItemSub78::readData(XRCReadStream *stream) {
ItemVisual::readData(stream);
_reference = stream->readResourceReference();
_position = stream->readPoint();
}
void ItemSub78::printData() {
ItemVisual::printData();
debug("reference: %s", _reference.describe().c_str());
debug("position: x %d, y %d", _position.x, _position.y);
}
} // End of namespace Stark
+115
View File
@@ -0,0 +1,115 @@
/* 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_ITEM_H
#define STARK_RESOURCES_ITEM_H
#include "common/rect.h"
#include "common/str.h"
#include "engines/stark/resources/resource.h"
#include "engines/stark/resourcereference.h"
namespace Stark {
class XRCReadStream;
class Item : public Resource {
public:
static const ResourceType::Type TYPE = ResourceType::kItem;
enum SubType {
kItemSub1 = 1,
kItemSub2 = 2,
kItemSub3 = 3,
kItemSub5 = 5,
kItemSub6 = 6,
kItemSub7 = 7,
kItemSub8 = 8,
kItemSub10 = 10
};
/** Item factory */
static Resource *construct(Resource *parent, byte subType, uint16 index, const Common::String &name);
Item(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~Item();
virtual void readData(XRCReadStream *stream) override;
protected:
void printData() override;
bool _field_34;
int32 _field_38;
};
class ItemVisual : public Item {
public:
ItemVisual(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~ItemVisual();
virtual void readData(XRCReadStream *stream) override;
protected:
void printData() override;
uint32 _field_44;
};
class ItemSub5610 : public ItemVisual {
public:
ItemSub5610(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~ItemSub5610();
};
class ItemSub56 : public ItemSub5610 {
public:
ItemSub56(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~ItemSub56();
virtual void readData(XRCReadStream *stream) override;
protected:
void printData() override;
int32 _field_6C;
Common::Point _position;
};
class ItemSub78 : public ItemVisual {
public:
ItemSub78(Resource *parent, byte subType, uint16 index, const Common::String &name);
virtual ~ItemSub78();
virtual void readData(XRCReadStream *stream) override;
protected:
void printData() override;
ResourceReference _reference;
Common::Point _position;
};
} // End of namespace Stark
#endif // STARK_RESOURCES_ITEM_H
+2 -2
View File
@@ -29,9 +29,9 @@ namespace Stark {
Resource *Layer::construct(Resource *parent, byte subType, uint16 index, const Common::String &name) {
switch (subType) {
case 1:
case kLayer2D:
return new Layer2D(parent, subType, index, name);
case 2:
case kLayer3D:
return new Layer3D(parent, subType, index, name);
default:
error("Unknown layer subtype %d", subType);
+5
View File
@@ -36,6 +36,11 @@ class Layer : public Resource {
public:
static const ResourceType::Type TYPE = ResourceType::kLayer;
enum SubType {
kLayer2D = 1,
kLayer3D = 2
};
/** Layer factory */
static Resource *construct(Resource *parent, byte subType, uint16 index, const Common::String &name);
+16
View File
@@ -24,6 +24,7 @@
#include "engines/stark/resources/camera.h"
#include "engines/stark/resources/command.h"
#include "engines/stark/resources/item.h"
#include "engines/stark/resources/floor.h"
#include "engines/stark/resources/floorface.h"
#include "engines/stark/resources/layer.h"
@@ -87,12 +88,24 @@ Math::Vector4d XRCReadStream::readVector4() {
return v;
}
Common::Point XRCReadStream::readPoint() {
uint32 x = readUint32LE();
uint32 y = readUint32LE();
return Common::Point(x, y);
}
float XRCReadStream::readFloat() {
float f;
read(&f, sizeof(float));
return f;
}
bool XRCReadStream::readBool() {
uint32 b = readUint32LE();
return b != 0;
}
bool XRCReadStream::isDataLeft() {
return pos() < size();
}
@@ -146,6 +159,9 @@ Resource *XRCReader::createResource(XRCReadStream *stream, Resource *parent) {
case ResourceType::kFloorFace:
resource = new FloorFace(parent, subType, index, name);
break;
case ResourceType::kItem:
resource = Item::construct(parent, subType, index, name);
break;
case ResourceType::kCommand:
resource = new Command(parent, subType, index, name);
break;
+3
View File
@@ -24,6 +24,7 @@
#define STARK_XRC_READER_H
#include "common/array.h"
#include "common/rect.h"
#include "common/str.h"
#include "common/substream.h"
#include "common/types.h"
@@ -49,7 +50,9 @@ public:
ResourceReference readResourceReference();
Math::Vector3d readVector3();
Math::Vector4d readVector4();
Common::Point readPoint();
float readFloat();
bool readBool();
bool isDataLeft();
};