Skip to content

Commit

Permalink
PRINCE: Animation classes fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jun 22, 2014
1 parent 94f5135 commit ebf3625
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 188 deletions.
100 changes: 81 additions & 19 deletions engines/prince/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,24 @@
*/

#include "prince/animation.h"
#include "prince/detail/animation.h"
#include "prince/decompress.h"

#include "common/debug.h"
#include "common/endian.h"

namespace Prince {

Animation::Animation() : _helper(NULL) {
}

Animation::~Animation() {
delete _helper;
}

bool Animation::loadFromStream(Common::SeekableReadStream &stream) {

uint32 dataSize = stream.size();
_data = (byte*) malloc(dataSize);

byte *data = (byte*)malloc(dataSize);

if(stream.read(data, dataSize) != dataSize) {
free(data);
if(stream.read(_data, dataSize) != dataSize) {
free(_data);
return false;
}

delete _helper;

_helper = new Detail::Animation(data, dataSize);

return true;
}

/*
const Graphics::Surface * Animation::getSurface(uint16 frameIndex) {
// bida kaszing
if (frameIndex >= _frameList.size()) {
Expand All @@ -60,8 +48,82 @@ const Graphics::Surface * Animation::getSurface(uint16 frameIndex) {
}
return _frameList[frameIndex];
}
*/
Animation::Animation() {

}

Animation::Animation(byte *data, uint32 dataSize)
: _data(data), _dataSize(dataSize) {
}

Animation::~Animation() {
free(_data);
}

int16 Animation::getLoopCount() const {
return READ_LE_UINT16(_data + 2);
}

int16 Animation::getBaseX() const {
return READ_LE_UINT16(_data + 8);
}

int16 Animation::getBaseY() const {
return READ_LE_UINT16(_data + 10);
}

uint Animation::getPhaseCount() const {
return READ_LE_UINT16(_data + 4);
}

uint Animation::getFrameCount() const {
return READ_LE_UINT16(_data + 6);
}

int16 Animation::getPhaseOffsetX(uint phaseIndex) const {
return READ_LE_UINT16(getPhaseEntry(phaseIndex) + 0);
}

int16 Animation::getPhaseOffsetY(uint phaseIndex) const {
return READ_LE_UINT16(getPhaseEntry(phaseIndex) + 2);
}

int16 Animation::getPhaseFrameIndex(uint phaseIndex) const {
return READ_LE_UINT16(getPhaseEntry(phaseIndex) + 4);
}

Graphics::Surface *Animation::getFrame(uint frameIndex) {
byte *frameData = _data + READ_LE_UINT32(_data + 16 + frameIndex * 4);
int16 width = READ_LE_UINT16(frameData + 0);
int16 height = READ_LE_UINT16(frameData + 2);
debug("width = %d; height = %d", width, height);
Graphics::Surface *surf = new Graphics::Surface();
surf->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
debug("frameData %p", frameData);
if (READ_BE_UINT32(frameData + 4) == 0x6D61736D) {
// Compressed
Decompressor dec;
uint32 ddataSize = READ_LE_UINT32(frameData + 8);
byte *ddata = new byte[ddataSize];
dec.decompress(frameData + 12, ddata, ddataSize);
for (uint16 i = 0; i < height; ++i) {
memcpy(surf->getBasePtr(0, i), ddata + width * i, width);
}
delete[] ddata;
} else {
// Uncompressed
for (uint16 i = 0; i < height; ++i) {
memcpy(surf->getBasePtr(0, i), frameData + 4 + width * i, width);
}
}
return surf;
}

byte *Animation::getPhaseEntry(uint phaseIndex) const {
return _data + READ_LE_UINT32(_data + 12) + phaseIndex * 8;
}

}

/* vim: set tabstop=4 noexpandtab: */
25 changes: 16 additions & 9 deletions engines/prince/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@

namespace Prince {

// FIXME: temp hack !!!
namespace Detail {
class Animation;
}

class Animation {
public:
Animation();
~Animation();
bool loadFromStream(Common::SeekableReadStream &stream);
//const Graphics::Surface *getSurface(uint16 frameIndex);

const Graphics::Surface *getSurface(uint16 frameIndex);
Animation();
Animation(byte *data, uint32 dataSize);
~Animation();
int16 getLoopCount() const;
int16 getBaseX() const;
int16 getBaseY() const;
uint getPhaseCount() const;
uint getFrameCount() const;
int16 getPhaseOffsetX(uint phaseIndex) const;
int16 getPhaseOffsetY(uint phaseIndex) const;
int16 getPhaseFrameIndex(uint phaseIndex) const;
Graphics::Surface *getFrame(uint frameIndex);

private:
Common::Array<Graphics::Surface *> _frameList;
Detail::Animation *_helper;
byte *_data;
uint32 _dataSize;
byte *getPhaseEntry(uint phaseIndex) const;
};

}
Expand Down
102 changes: 0 additions & 102 deletions engines/prince/detail/animation.cpp

This file was deleted.

51 changes: 0 additions & 51 deletions engines/prince/detail/animation.h

This file was deleted.

8 changes: 4 additions & 4 deletions engines/prince/hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ namespace Prince {
static const uint32 kMoveSetSize = 26;

Hero::Hero() : _number(0), _visible(false), _state(STAY), _middleX(0), _middleY(0)
, _boreNum(0), _currHeight(0), _moveDelay(0), _shadMinus(1) {
, _boreNum(0), _currHeight(0), _moveDelay(0), _shadMinus(1), _moveSetType(0), _frame(0) {
}

bool Hero::loadAnimSet(uint32 animSetNr) {
animSetNr = 6;
if (animSetNr > sizeof(heroSetTable)) {
return false;
}
Expand All @@ -63,8 +62,9 @@ bool Hero::loadAnimSet(uint32 animSetNr) {
}

const Graphics::Surface * Hero::getSurface() {
if (_moveSet[3]) {
return _moveSet[3]->getSurface(0);
if (_moveSet[_moveSetType]) {
int16 phaseFrameIndex = _moveSet[_moveSetType]->getPhaseFrameIndex(_frame);
return _moveSet[_moveSetType]->getFrame(phaseFrameIndex);
}
return NULL;
}
Expand Down
31 changes: 31 additions & 0 deletions engines/prince/hero.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@ class Hero {
DOWN = 4
};

enum MoveSet {
Move_SL,
Move_SR,
Move_SU,
Move_SD,
Move_ML,
Move_MR,
Move_MU,
Move_MD,
Move_TL,
Move_TR,
Move_TU,
Move_TD,
Move_MLU,
Move_MLD,
Move_MLR,
Move_MRU,
Move_MRD,
Move_MRL,
Move_MUL,
Move_MUR,
Move_MUD,
Move_MDL,
Move_MDR,
Move_MDU,
Move_BORED1,
Move_BORED2
};

Hero();

bool loadAnimSet(uint32 heroAnimNumber);
Expand All @@ -69,6 +98,8 @@ class Hero {
State _state;
int16 _middleX;
int16 _middleY;
int16 _moveSetType;
int16 _frame;

// Coords array of coordinates
// DirTab array of directions
Expand Down
1 change: 0 additions & 1 deletion engines/prince/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ MODULE_OBJS = \
decompress.o \
hero.o \
hero_set.o \
detail/animation.o \
cursor.o

# This module can be built as a plugin
Expand Down
Loading

0 comments on commit ebf3625

Please sign in to comment.