PRINCE: hero's shadow drawing progress

This commit is contained in:
lukaslw 2014-05-11 13:57:52 +02:00
parent 6463c04b93
commit be565bf4f0
3 changed files with 222 additions and 99 deletions

View File

@ -27,15 +27,17 @@
#include "prince/animation.h"
#include "prince/resource.h"
#include "prince/prince.h"
#include "prince/graphics.h"
namespace Prince {
Hero::Hero(PrinceEngine *vm) : _vm(vm), _number(0), _visible(false), _state(MOVE), _middleX(0), _middleY(0)
Hero::Hero(PrinceEngine *vm, GraphicsMan *graph) : _vm(vm), _graph(graph)
, _number(0), _visible(false), _state(MOVE), _middleX(0), _middleY(0)
, _boreNum(1), _currHeight(0), _moveDelay(0), _shadMinus(0), _moveSetType(0)
, _lastDirection(DOWN), _destDirection(DOWN), _talkTime(0), _boredomTime(0), _phase(0)
, _specAnim(0), _drawX(0), _drawY(0), _randomSource("prince"), _zoomFactor(0), _scaleValue(0)
, _shadZoomFactor(0), _shadScaleValue(0), _shadowLineLen(0)
, _shadZoomFactor(0), _shadScaleValue(0), _shadowLineLen(0), _shadowDrawX(0), _shadowDrawY(0)
, _shadLastY(0)
{
_zoomBitmap = new Animation();
_shadowBitmap = new Animation();
@ -262,19 +264,32 @@ static void plot(int x, int y, int color, void *data) {
shadowLine->_shadowLineLen++;
}
Graphics::Surface *Hero::showHeroShadow(Graphics::Surface *heroFrame) {
void Hero::showHeroShadow() {
//Graphics::Surface *Hero::showHeroShadow() {
int16 phaseFrameIndex = _moveSet[_moveSetType]->getPhaseFrameIndex(_phase);
Graphics::Surface *heroFrame = _moveSet[_moveSetType]->getFrame(phaseFrameIndex);
int16 frameXSize = _moveSet[_moveSetType]->getFrameWidth(_phase);
int16 frameYSize = _moveSet[_moveSetType]->getFrameHeight(_phase);
Graphics::Surface *makeShadow = new Graphics::Surface();
makeShadow->create(frameXSize, frameYSize, Graphics::PixelFormat::createFormatCLUT8());
//Graphics::Surface *destShadow = new Graphics::Surface();
//destShadow->create(frameXSize, frameYSize, Graphics::PixelFormat::createFormatCLUT8());
/*
for (int y = 0; y < frameYSize; y++) {
byte *src = (byte *)destShadow->getBasePtr(0, y);
for (int x = 0; x < frameXSize; x++, src++) {
*src = 0xFF;
}
}
*/
for (int y = 0; y < frameYSize; y++) {
byte *dst = (byte *)makeShadow->getBasePtr(0, y);
byte *src = (byte *)heroFrame->getBasePtr(0, y);
byte *dst = (byte *)makeShadow->getBasePtr(0, y);
for (int x = 0; x < frameXSize; x++, dst++, src++) {
if (*dst == 0xFF) {
if (*src != 0xFF) {
*dst = kShadowColor;
} else {
*dst = *src;
@ -297,23 +312,26 @@ Graphics::Surface *Hero::showHeroShadow(Graphics::Surface *heroFrame) {
// ebx = _lightY
// eax = _lightX
int shadowDirection;
int shadDirection;
if (_lightY > destY) {
shadowDirection = 1;
shadDirection = 1;
} else {
shadowDirection = 0;
shadDirection = 0;
}
//int shadWallDown = 0;
int shadWallDown = 0;
_shadowLineLen = 0;
Graphics::drawLine(_lightX, _lightY, destX, destY, 0, &plot, this);
// sprShadow = shadowTable70
byte *sprShadow = (byte *)_graph->_shadowTable70;
// sprModulo = modulo of source Bitmap
int sprWidth = scaledX;
int sprHeight = scaledY;
int sprDestX = destX - _vm->_picWindowX;
int sprDestY = destY - _vm->_picWindowY;
int sprDestX = destX - _vm->_picWindowX; //test this
int sprDestY = destY - _vm->_picWindowY; //test this
_shadowDrawX = sprDestX; // to fix
_shadowDrawY = sprDestY;
int shadPosX = sprDestX;
int shadMinX = sprDestX;
@ -322,31 +340,36 @@ Graphics::Surface *Hero::showHeroShadow(Graphics::Surface *heroFrame) {
int shadPosY = sprDestY;
int shadMinY = sprDestY;
int shadMaxY = sprDestY;
// destY * kMaxPicWidth / 8 + destX / 8
int shadBitAddr = _shadowBitmap->getZoom(destY * kMaxPicWidth / 8 + destX / 8);
int shadBitAddr = destY * kMaxPicWidth / 8 + destX / 8; // for temp _shadowBitmap->getZoom()
int shadBitMask = 128 >> (destX % 8);
int shadZoomY2 = _shadScaleValue;
int shadZoomY = _scaleValue;
// lockscreen etc
//byte *destShadowStart = (byte *)destShadow->getBasePtr(0, 0); // need this?
byte *shadowStart = (byte *)makeShadow->getBasePtr(0, frameYSize - 1); // !TEST IT! esi, first pixel from last row of black hero
byte *background = (byte *)_graph->_frontScreen->getBasePtr(sprDestX, sprDestY); // !TEST IT! eax, pixel of background where shadow sprite starts
//byte *background = (byte *)_graph->_frontScreen->getBasePtr(sprDestX, sprDestY + frameYSize);
int diff = 0;
// banked2
byte *start = _shadowLine + 8;
byte *shadowLineStart = _shadowLine + 8;
// linear_loop
//for(int i = 0; i < ; i++) {
for(int i = 0; i < sprHeight; i++) {
int ebx16795 = shadPosY;
int sprModulo = 0;
int shadSkipX = 0;
int ebxOnStack;
//retry_line:
for (ebxOnStack = sprHeight; ebxOnStack > 0; ebxOnStack--) {
for (ebxOnStack = sprHeight - i; ebxOnStack > 0; ebxOnStack--) {
shadZoomY -= 100;
if (shadZoomY < 0 && _scaleValue != 10000) {
shadZoomY += _scaleValue;
// esi -= sprWidth
shadowStart -= sprWidth;
} else {
break; //to line_y_ok
}
@ -356,97 +379,190 @@ Graphics::Surface *Hero::showHeroShadow(Graphics::Surface *heroFrame) {
// koniec_bajki
}
//line_y_ok
int shadLastY = 0; //?
if (shadPosY >= 0 && shadPosY != shadLastY) {
shadLastY = shadPosY;
//if (shadPosY >= 0 && shadPosY != _shadLastY) {
if (shadPosY >= 0) {
//_shadLastY = shadPosY;
if (shadPosY < 480 && shadPosX < 640) {
if (shadPosX < 0) {
if (shadPosX < 0) { //?
shadSkipX = -1 * shadPosX;
//add eax, ebp
if (sprWidth > shadSkipX) { //?
//add esi, ebp
background += shadSkipX;
if (sprWidth > shadSkipX) {
shadowStart += shadSkipX;
shadBitAddr += shadSkipX / 8;
int ebp16844 = shadSkipX % 8;
if (ebp16844 != 0) {
//loop_rotate:
for (int k = 0; k < ebp16844; k++) {
//ror shaBitMask !
shadBitMask /= 2;
//ror(shadBitMask, 1)
if (shadBitMask == 1) {
shadBitMask = 128;
shadBitAddr++;
} else {
shadBitMask /= 2;
}
}
}
//draw_line1
if (shadPosX < shadMinX) {
shadMinX = shadPosX;
}
//bigger_x
if (shadPosX + sprWidth > shadMaxX) {
shadMaxX = shadPosX + sprWidth;
}
//smaller_x
if (shadPosY < shadMinY) {
shadMinY = shadPosY;
}
//bigger_y
if (shadPosY > shadMaxY) {
shadMaxY = shadPosY;
}
//smaller_y
//retry_line2
int ebxOnStack2;
for(ebxOnStack2 = ebxOnStack; ebxOnStack2 > 0; ebxOnStack2--) {
shadZoomY2 -= 100;
if (shadZoomY2 < 0 && _shadScaleValue != 10000) {
shadZoomY2 += _shadScaleValue;
// esi -= sprWidth
} else {
break; //to line_y_ok_2
}
}
if (ebxOnStack2 == 0) {
// esp += 4*4
// koniec_bajki
}
//line_y_ok_2:
// push esi
// push ecx
// int lineDestAddr = eax;
// edi = eax
// eax = shadBitMask
// push eax // push shadBitMask
// lineBitAddr = shadBitMask
// eax = shadBitAddr
// push eax
// LineBitAddr = eax
//copy_trans
//push eax, ebx, edx, ebp
int shadWDFlag = 0;
int shadZoomX = _scaleValue;
//ebx17061 = shadowTable70;
int ebp17062 = shadBitAddr;
int ah = shadBitMask;
//ct_loop:
shadZoomX -= 100;
if (shadZoomX < 0 && _scaleValue != 10000) {
// esi++;
shadZoomX += _scaleValue;
}
} else {
//skip_line //?
// no draw_line1
}
} else {
//x1_ok
if (shadPosX + sprWidth > 640) {
int ecx16861 = sprWidth - (shadPosX + sprWidth - 640);
sprModulo = shadPosX + sprWidth - 640;
} else {
//draw_line
int ecx16868 = sprWidth;
}
}
//draw_line1
if (shadPosX < shadMinX) {
shadMinX = shadPosX;
}
//bigger_x
if (shadPosX + sprWidth > shadMaxX) {
shadMaxX = shadPosX + sprWidth;
}
//smaller_x
if (shadPosY < shadMinY) {
shadMinY = shadPosY;
}
//bigger_y
if (shadPosY > shadMaxY) { //?
shadMaxY = shadPosY;
}
//smaller_y
//retry_line2
int ebxOnStack2;
for(ebxOnStack2 = ebxOnStack; ebxOnStack2 > 0; ebxOnStack2--) {
shadZoomY2 -= 100;
if (shadZoomY2 < 0 && _shadScaleValue != 10000) {
shadZoomY2 += _shadScaleValue;
shadowStart -= sprWidth;
} else {
break; //to line_y_ok_2
}
}
if (ebxOnStack2 == 0) {
// esp += 4*4
// koniec_bajki
}
//line_y_ok_2:
// push esi
// push ecx
// int lineDestAddr = eax;
// edi = eax
// eax = shadBitMask
// push eax // push shadBitMask
// lineBitAddr = shadBitMask
// eax = shadBitAddr
// push eax
// LineBitAddr = eax
//copy_trans
//push eax, ebx, edx, ebp
int shadWDFlag = 0;
int shadZoomX = _scaleValue;
//ct_loop:
for (int j = 0; j < sprWidth; j++) { //? ecx to check
shadZoomX -= 100;
if (shadZoomX < 0 && _scaleValue != 10000) {
shadowStart++;
shadZoomX += _scaleValue;
} else {
//point_ok:
if (*shadowStart == kShadowColor) {
if (shadBitMask != _shadowBitmap->getZoom(shadBitAddr)) { //tofix
if (shadWallDown == 0) {
if (shadBitMask != _shadowBitmap->getZoom(shadBitAddr + kShadowBitmapSize)) {
shadWDFlag = 1;
//shadow
*background = *(sprShadow + *background);
}
}
} else {
//shadow
*background = *(sprShadow + *background);
}
}
//ct_next
//ror(shadBitMask, 1)
if (shadBitMask == 1) {
shadBitMask = 128;
shadBitAddr++;
} else {
shadBitMask /= 2;
}
//okok
shadowStart++;
background++;
//destShadowStart++;
}
}
//byebyebye
if (shadWallDown == 0 && shadWDFlag != 0) {
//shadWall itp
//
}
//byebye
// pop ...
if (shadDirection != 0 && shadWallDown != 0) {
// push...
// krap2
// WALL_copy_trans
}
//next_line
//int ecx16965 = sprWidth;
if (*(shadowLineStart + 2) < *(shadowLineStart - 2)) {
//minus_y
shadBitAddr += kMaxPicWidth / 8;
shadPosY++;
//add eax, VESA_ScanLine
background = (byte *)_graph->_frontScreen->getBasePtr(sprDestX + diff, sprDestY + i);
} else if (*(shadowLineStart + 2) > *(shadowLineStart - 2)) {
shadBitAddr -= kMaxPicWidth / 8;
shadPosY--;
//sub eax, VESA_ScanLine
background = (byte *)_graph->_frontScreen->getBasePtr(sprDestX + diff, sprDestY - i);
}
//no_change_y
if (*shadowLineStart < *(shadowLineStart - 4)) {
//minus_x
shadPosX--;
//rol
if (shadBitMask == 128) {
shadBitMask = 1;
shadBitAddr--;
} else {
shadBitMask *= 2;
}
//eax--;
//background--;
diff--;
} else if (*shadowLineStart > *(shadowLineStart - 4)) {
shadPosX++;
//ror
if (shadBitMask == 1) {
shadBitMask = 128;
shadBitAddr++;
} else {
shadBitMask /= 2;
}
//background++;
diff++;
}
//no_change_x
shadowLineStart += 4;
shadowStart = (byte *)makeShadow->getBasePtr(0, frameYSize - 1 - i);
//background = (byte *)_graph->_frontScreen->getBasePtr(sprDestX, sprDestY + i);
}
}
//skip_line
//}
}
}
return makeShadow;
//return makeShadow;
//return destShadow;
}
void Hero::showHeroAnimFrame() {

View File

@ -34,6 +34,7 @@ namespace Prince {
class Animation;
class PrinceEngine;
class GraphicsMan;
class Hero {
public:
@ -44,8 +45,9 @@ public:
static const int16 kZoomBitmapWidth = kMaxPicWidth / kZoomStep;
static const int16 kNormalWidth = 640;
static const int16 kShadowLineArraySize = 2 * 1280 * 4;
static const int16 kShadowBitmapSize = kMaxPicWidth * kMaxPicHeight / 8;
static const uint8 kShadowColor = 191;
static const byte kShadowColor = 191;
enum State {
STAY = 0,
@ -96,7 +98,7 @@ public:
Move_BORED2
};
Hero(PrinceEngine *vm);
Hero(PrinceEngine *vm, GraphicsMan *graph);
~Hero();
Common::RandomSource _randomSource;
bool loadAnimSet(uint32 heroAnimNumber);
@ -119,13 +121,15 @@ public:
void showHeroAnimFrame();
void line(int x1, int y1, int x2, int y2);
void plotPoint(int x, int y);
Graphics::Surface *showHeroShadow(Graphics::Surface *heroFrame);
//Graphics::Surface *showHeroShadow();
void showHeroShadow();
void setShadowScale(int32 shadowScale);
void specialAnim();
void getState();
//private:
PrinceEngine *_vm;
GraphicsMan *_graph;
uint16 _number;
uint16 _visible;
int16 _state;
@ -143,7 +147,9 @@ public:
int32 _shadZoomFactor;
int32 _shadScaleValue;
int32 _shadowLineLen;
int16 _shadowDrawX;
int16 _shadowDrawY;
int16 _shadLastY;
// Coords array of coordinates
// DirTab array of directions

View File

@ -186,8 +186,8 @@ void PrinceEngine::init() {
_roomBmp = new Image::BitmapDecoder();
_mainHero = new Hero(this);
_secondHero = new Hero(this);
_mainHero = new Hero(this, _graph);
_secondHero = new Hero(this, _graph);
_mainHero->loadAnimSet(0);
}
@ -414,7 +414,6 @@ bool PrinceEngine::loadVoice(uint32 slot, uint32 sampleSlot, const Common::Strin
}
uint32 id = _voiceStream[sampleSlot]->readUint32LE();
//if (id != 0x46464952) {
if (id != MKTAG('F', 'F', 'I', 'R')) {
error("It's not RIFF file %s", streamName.c_str());
return false;
@ -422,7 +421,6 @@ bool PrinceEngine::loadVoice(uint32 slot, uint32 sampleSlot, const Common::Strin
_voiceStream[sampleSlot]->skip(0x20);
id = _voiceStream[sampleSlot]->readUint32LE();
//if (id != 0x61746164) {
if (id != MKTAG('a', 't', 'a', 'd')) {
error("No data section in %s id %04x", streamName.c_str(), id);
return false;
@ -642,10 +640,13 @@ void PrinceEngine::drawScreen() {
if (_mainHero->_visible) {
const Graphics::Surface *mainHeroSurface = _mainHero->getSurface();
//const Graphics::Surface *mainHeroShadow = _mainHero->showHeroShadow();
if (mainHeroSurface)
//_graph->drawTransparent(_mainHero->_middleX, _mainHero->_middleY, mainHeroSurface);
if (mainHeroSurface) {
_mainHero->showHeroShadow();
_graph->drawTransparent(_mainHero->_drawX, _mainHero->_drawY, mainHeroSurface);
//_graph->drawTransparent(_mainHero->_shadowDrawX, _mainHero->_shadowDrawY, mainHeroShadow);
}
}
playNextFrame();