Skip to content

Commit

Permalink
AVALANCHE: Rename/move/implement getMe().
Browse files Browse the repository at this point in the history
  • Loading branch information
uruk committed Feb 4, 2014
1 parent 08e7b5a commit 29cd161
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
20 changes: 13 additions & 7 deletions engines/avalanche/ghostroom.cpp
Expand Up @@ -31,7 +31,6 @@
namespace Avalanche {

const int8 GhostRoom::kAdjustment[5] = { 7, 0, 7, 7, 7 };
const byte GhostRoom::kPlaneToUse[4] = { 2, 2, 2, 3 };
const byte GhostRoom::kWaveOrder[5] = { 5, 1, 2, 3, 4 };
const byte GhostRoom::kGlerkFade[26] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1 };
const byte GhostRoom::kGreldetFade[18] = { 1, 2, 3, 4, 5, 6, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1 };
Expand All @@ -53,12 +52,14 @@ GhostRoom::GhostRoom(AvalancheEngine *vm) {
_redGreldet = false;
}

void GhostRoom::plainGrab() {
warning("STUB: plainGrab()");
GhostRoom::~GhostRoom() {
for (int i = 0; i < 2; i++)
_eyes[i].free();
_exclamation.free();
}

void GhostRoom::getMe(void *p) {
warning("STUB: getMe()");
void GhostRoom::plainGrab() {
warning("STUB: plainGrab()");
}

void GhostRoom::getMeAargh(byte which) {
Expand All @@ -77,7 +78,7 @@ void GhostRoom::bigGreenEyes(byte how) {
warning("STUB: bigGreenEyes()");
}

GhostRoom::ChunkBlockType GhostRoom::readChunkBlock(Common::File &file) {
ChunkBlockType GhostRoom::readChunkBlock(Common::File &file) {
ChunkBlockType cb;
cb._flavour = (FlavourType)file.readByte();
cb._x = file.readSint16LE();
Expand All @@ -99,7 +100,7 @@ void GhostRoom::run() {

_file.seek(44);

// Initializing array.
// Initializing ghost's array.
for (int i = 0; i < 5; i++)
for (int j = 0; j < 2; j++)
for (int y = 0; y < 66; y++)
Expand All @@ -114,6 +115,11 @@ void GhostRoom::run() {
_file.read(_ghost[i][j][y], cb._xl / 8);
}

// Load some smaller pictures.
for (int i = 0; i < 2; i++)
_eyes[i] = _vm->_graphics->ghostLoadPicture(_file);
_exclamation = _vm->_graphics->ghostLoadPicture(_file);

warning("STUB: run()");
}

Expand Down
27 changes: 13 additions & 14 deletions engines/avalanche/ghostroom.h
Expand Up @@ -34,26 +34,27 @@
namespace Avalanche {
class AvalancheEngine;

enum FlavourType { ch_EGA, ch_BGI, ch_Natural, ch_Two, ch_One };

struct ChunkBlockType {
FlavourType _flavour;
int16 _x, _y;
int16 _xl, _yl;
int32 _size;
};

class GhostRoom {
public:
GhostRoom(AvalancheEngine *vm);
~GhostRoom();

void run();
ChunkBlockType readChunkBlock(Common::File &file);

private:
enum FlavourType { ch_EGA, ch_BGI, ch_Natural, ch_Two, ch_One };

struct ChunkBlockType {
FlavourType _flavour;
int16 _x, _y;
int16 _xl, _yl;
int32 _size;
};

AvalancheEngine *_vm;

static const int8 kAdjustment[5];
static const byte kPlaneToUse[4];
static const byte kWaveOrder[5];
static const byte kGlerkFade[26];
static const byte kGreldetFade[18];
Expand All @@ -64,8 +65,8 @@ class GhostRoom {
byte _ghost[5][2][66][26];
void *_memLevel;
byte _y, _yy, _bit, _xofs;
void *_eyes[2];
void *_exclamation;
Graphics::Surface _eyes[2];
Graphics::Surface _exclamation;
void *_aargh[6];
void *_bat[3];
GlerkType *_glerk;
Expand All @@ -82,12 +83,10 @@ class GhostRoom {
bool _redGreldet;

void plainGrab();
void getMe(void *p);
void getMeAargh(byte which);
void wait(uint16 howLong);
void doBat();
void bigGreenEyes(byte how);
ChunkBlockType readChunkBlock(Common::File &file);
};

} // End of namespace Avalanche
Expand Down
28 changes: 26 additions & 2 deletions engines/avalanche/graphics.cpp
Expand Up @@ -500,7 +500,7 @@ void GraphicManager::nimFree() {
_nimLogo.free();
}

void GraphicManager::ghostDrawPicture(byte ghostArr[2][66][26], uint16 destX, uint16 destY) {
void GraphicManager::ghostDrawGhost(byte ghostArr[2][66][26], uint16 destX, uint16 destY) {
const byte kPlaneToUse[4] = { 0, 0, 0, 1 };
// Constants from the original code.
uint16 height = 66;
Expand All @@ -527,6 +527,30 @@ void GraphicManager::ghostDrawPicture(byte ghostArr[2][66][26], uint16 destX, ui
ghostPic.free();
}

/**
* @remarks Originally called 'get_me' and was located in Ghostroom.
*/
Graphics::Surface GraphicManager::ghostLoadPicture(Common::File &file) {
ChunkBlockType cb = _vm->_ghostroom->readChunkBlock(file);

Graphics::Surface picture = loadPictureGraphic(file);

int bytesPerRow = (picture.w / 8);
if ((picture.w % 8) > 0)
bytesPerRow += 1;
int loadedBytes = picture.h * bytesPerRow * 4 + 4;
// * 4 is for the four planes, + 4 is for the reading of the width and the height at loadPictureGraphic's beginning.

int bytesToSkip = cb._size - loadedBytes;
file.skip(bytesToSkip);

return picture;
}

void GraphicManager::ghostDrawPicture(const Graphics::Surface &picture, uint16 destX, uint16 destY) {
drawPicture(_surface, picture, destX, destY);
}

/**
* This function mimics Pascal's getimage().
*/
Expand All @@ -537,7 +561,7 @@ Graphics::Surface GraphicManager::loadPictureGraphic(Common::File &file) {

Graphics::Surface picture; // We make a Surface object for the picture itself.
picture.create(width, height, Graphics::PixelFormat::createFormatCLUT8());

// Produce the picture. We read it in row-by-row, and every row has 4 planes.
for (int y = 0; y < height; y++) {
for (int8 plane = 3; plane >= 0; plane--) { // The planes are in the opposite way.
Expand Down
4 changes: 3 additions & 1 deletion engines/avalanche/graphics.h
Expand Up @@ -92,7 +92,9 @@ class GraphicManager {
void shiftScreen();

// Ghostroom's functions:
void ghostDrawPicture(byte ghostArr[2][66][26], uint16 destX, uint16 destY); // Very similar to loadPictureSign(). TODO: Unify the two later if possible.
void ghostDrawGhost(byte ghostArr[2][66][26], uint16 destX, uint16 destY); // Very similar to loadPictureSign(). TODO: Unify the two later if possible.
Graphics::Surface ghostLoadPicture(Common::File &file);
void ghostDrawPicture(const Graphics::Surface &picture, uint16 destX, uint16 destY);

void clearAlso();
void clearTextBar();
Expand Down

0 comments on commit 29cd161

Please sign in to comment.