STARK: Clean up anim read code

This commit is contained in:
Bastien Bouclet 2015-01-08 08:36:35 +01:00
parent 2b9655e05b
commit d2ee9537db
5 changed files with 24 additions and 20 deletions

View File

@ -33,7 +33,7 @@ namespace Stark {
Actor::Actor() :
_skeleton(nullptr),
_texture(nullptr),
_id(0),
_u1(0),
_u2(0.0) {
}
@ -50,17 +50,25 @@ Actor::~Actor() {
}
void Actor::readFromStream(ArchiveReadStream *stream) {
_id = stream->readUint32LE();
uint32 id = stream->readUint32LE();
if (id != 4) {
error("Wrong magic 1 while reading actor '%d'", id);
}
uint32 format = stream->readUint32LE();
uint32 u1 = stream->readUint32LE();
if (format != 256) {
error("Wrong format while reading actor '%d'", format);
}
_u1 = stream->readUint32LE();
uint32 id2 = stream->readUint32LE();
if (id2 != 0xDEADBABE) {
error("Wrong magic while reading actor");
error("Wrong magic 2 while reading actor '%d'", id2);
}
_u2 = stream->readFloat();
uint32 numMaterials = stream->readUint32LE();
for (uint i = 0; i < numMaterials; ++i) {

View File

@ -131,7 +131,7 @@ public:
void setTexture(Texture *texture);
private:
uint32 _id;
uint32 _u1;
float _u2;
Common::Array<MaterialNode *> _materials;

View File

@ -300,7 +300,7 @@ void AnimSub4::onPostRead() {
// Get the archive loader service
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader;
Common::ReadStream *stream = archiveLoader->getFile(_animFilename, _archiveName);
ArchiveReadStream *stream = archiveLoader->getFile(_animFilename, _archiveName);
_seletonAnim = new SkeletonAnim();
_seletonAnim->createFromStream(stream);

View File

@ -21,11 +21,11 @@
*/
#include "engines/stark/skeleton_anim.h"
#include "engines/stark/archiveloader.h"
#include "engines/stark/skeleton.h"
#include "engines/stark/stark.h"
#include "common/stream.h"
namespace Stark {
@ -38,7 +38,7 @@ SkeletonAnim::~SkeletonAnim() {
delete *it;
}
void SkeletonAnim::createFromStream(Common::ReadStream *stream) {
void SkeletonAnim::createFromStream(ArchiveReadStream *stream) {
_id = stream->readUint32LE();
_ver = stream->readUint32LE();
if (_ver == 3) {
@ -64,11 +64,9 @@ void SkeletonAnim::createFromStream(Common::ReadStream *stream) {
for (uint32 j = 0; j < numKeys; ++j) {
AnimKey *key = new AnimKey();
key->_time = stream->readUint32LE();
char *ptr = new char[7 * 4];
stream->read(ptr, 7 * 4);
key->_rot = Math::Vector3d(get_float(ptr), get_float(ptr + 4), get_float(ptr + 8));
key->_rotW = get_float(ptr + 12);
key->_pos = Math::Vector3d(get_float(ptr + 16), get_float(ptr + 20), get_float(ptr + 24));
key->_rot = stream->readVector3();
key->_rotW = stream->readFloat();
key->_pos = stream->readVector3();
node->_keys.push_back(key);
}

View File

@ -28,12 +28,10 @@
#include "math/vector3d.h"
#include "common/array.h"
namespace Common {
class ReadStream;
}
namespace Stark {
class ArchiveReadStream;
class AnimKey {
public:
uint32 _time;
@ -61,7 +59,7 @@ public:
SkeletonAnim();
~SkeletonAnim();
void createFromStream(Common::ReadStream *stream);
void createFromStream(ArchiveReadStream *stream);
/**
* Get the interpolated bone coordinate for a given bone at a given animation timestamp