Skip to content

Commit

Permalink
LILLIPUT: Some refactoring, fix a bug in fixx16x16Rect
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke authored and sev- committed Mar 28, 2018
1 parent 6dd3a10 commit 29b476f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
46 changes: 22 additions & 24 deletions engines/lilliput/lilliput.cpp
Expand Up @@ -289,7 +289,7 @@ bool LilliputEngine::hasFeature(EngineFeature f) const {
}

const char *LilliputEngine::getCopyrightString() const {
return "copyright S.L.Grand, Brainware, 1991";
return "copyright S.L.Grand, Brainware, 1991 - 1992";
}

GameType LilliputEngine::getGameType() const {
Expand All @@ -301,9 +301,9 @@ Common::Platform LilliputEngine::getPlatform() const {
}

void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
debugC(2, kDebugEngineTBC, "displayCharacter(%d, %d - %d, %d)", index, pos.x, pos.y, flags);
debugC(2, kDebugEngine, "displayCharacter(%d, %d - %d, %d)", index, pos.x, pos.y, flags);

byte *buf = _savedSurfaceGameArea1 + (pos.y << 8) + pos.x;
byte *buf = _savedSurfaceGameArea1 + (pos.y * 256) + pos.x;

byte *src = _bufferMen;
if (index < 0) {
Expand All @@ -314,7 +314,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
index -= 0xF0;
}

src += ((index & 0xFF) << 8) + (index >> 8);
src += (index * 256);

if ((flags & 2) == 0) {
for (int y = 0; y < 16; y++) {
Expand Down Expand Up @@ -342,11 +342,10 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point pos) {
debugC(2, kDebugEngine, "display16x16IndexedBuf(buf, %d, %d, %d)", index, pos.x, pos.y);

int index1 = ((index & 0xFF) << 8) + (index >> 8);
int index1 = index * 16 * 16;
byte *newBuf = &buf[index1];

int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
int index2 = pos.x + tmpVal + (tmpVal >> 2);
int index2 = pos.x + (pos.y * 320);

for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
Expand All @@ -369,8 +368,7 @@ void LilliputEngine::display16x16Buf(byte *buf, Common::Point pos) {
void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
debugC(2, kDebugEngine, "SaveSurfaceUnderMouseCursor(buf, %d, %d)", pos.x, pos.y);

int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
int index2 = pos.x + tmpVal + (tmpVal >> 2);
int index2 = pos.x + (pos.y * 320);

for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
Expand All @@ -380,12 +378,10 @@ void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
}
}

void LilliputEngine::fill16x16Rect(int var1, int var2, int var4) {
debugC(2, kDebugEngineTBC, "fill16x16Rect(%d, %d, %d)", var1, var2, var4);
void LilliputEngine::fill16x16Rect(byte col, Common::Point pos) {
debugC(2, kDebugEngineTBC, "fill16x16Rect(%d, %d - %d)", col, pos.x, pos.y);

int tmpVal = ((var4 >> 8) + (var4 & 0xFF));
int index = var2 + tmpVal + (tmpVal >> 2);
int col = var1 & 0xFF;
int index = pos.x + (pos.y * 320);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
((byte *)_mainSurface->getPixels())[index + j] = col;
Expand Down Expand Up @@ -421,7 +417,7 @@ void LilliputEngine::restoreSurfaceUnderMousePointer() {
}

void LilliputEngine::saveSurfaceGameArea() {
debugC(2, kDebugEngineTBC, "saveSurfaceGameArea()");
debugC(2, kDebugEngine, "saveSurfaceGameArea()");

restoreSurfaceUnderMousePointer();

Expand Down Expand Up @@ -467,17 +463,16 @@ void LilliputEngine::restoreSurfaceSpeech() {


void LilliputEngine::displayInterfaceHotspots() {
debugC(2, kDebugEngineTBC, "displayInterfaceHotspots()");
debugC(2, kDebugEngine, "displayInterfaceHotspots()");

if (_displayMap == 1)
return;

restoreSurfaceUnderMousePointer();

int index = 0;
int tmpVal;
for (index = 0; index < _word12F68_ERULES; index++) {
tmpVal = ((_scriptHandler->_array122E9[index] << 2) + (_scriptHandler->_array122E9[index] << 4)) & 0xFF;
for (int index = 0; index < _word12F68_ERULES; index++) {
tmpVal = _scriptHandler->_array122E9[index] * 20;
display16x16IndexedBuf(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
}

Expand Down Expand Up @@ -592,23 +587,26 @@ void LilliputEngine::displayFunction11(byte *buf) {
displayMousePointer();
}

void LilliputEngine::displayFunction12() {
debugC(1, kDebugEngineTBC, "displayFunction12()");
void LilliputEngine::initGameAreaDisplay() {
debugC(1, kDebugEngine, "initGameAreaDisplay()");

restoreSurfaceUnderMousePointer();

// display background
byte *tmpBuf = loadVGA("SCREEN.GFX", 320 * 200, true);
memcpy(_mainSurface->getPixels(), tmpBuf, 320 * 200);
_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
_system->updateScreen();

// display game area on top of background
saveSurfaceGameArea();
saveSurfaceSpeech();
displayInterfaceHotspots();
displayLandscape();
prepareGameArea();
displayGameArea();

// display mouse pointer on top of the rest
displayMousePointer();
free(tmpBuf);
}
Expand Down Expand Up @@ -760,7 +758,7 @@ void LilliputEngine::setNextDisplayCharacter(int var1) {
}

void LilliputEngine::prepareGameArea() {
debugC(2, kDebugEngineTBC, "prepareGameArea()");
debugC(2, kDebugEngine, "prepareGameArea()");

moveCharacters();
_currentDisplayCharacter = 0;
Expand Down Expand Up @@ -1006,7 +1004,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
paletteFadeOut();
_word15AC2 = 0;
sub130B6();
displayFunction12();
initGameAreaDisplay();
_scriptHandler->_heroismLevel = 0;
moveCharacters();
paletteFadeIn();
Expand Down Expand Up @@ -1284,7 +1282,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
}

void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
debugC(2, kDebugEngineTBC, "renderCharacters(buf, %d - %d)", pos.x, pos.y);
debugC(2, kDebugEngine, "renderCharacters(buf, %d - %d)", pos.x, pos.y);

if (_nextDisplayCharacterPos != pos)
return;
Expand Down
4 changes: 2 additions & 2 deletions engines/lilliput/lilliput.h
Expand Up @@ -219,7 +219,7 @@ class LilliputEngine : public Engine {
void display16x16IndexedBuf(byte *buf, int var1, Common::Point pos);
void display16x16Buf(byte *buf, Common::Point pos);
void SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos);
void fill16x16Rect(int var1, int var2, int var4);
void fill16x16Rect(byte col, Common::Point pos);
void displayMousePointer();
void restoreSurfaceUnderMousePointer();
void saveSurfaceGameArea();
Expand All @@ -228,7 +228,7 @@ class LilliputEngine : public Engine {
void displayLandscape();
void displayFunction10();
void displayFunction11(byte *buf);
void displayFunction12();
void initGameAreaDisplay();
void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
void displayGameArea();
void prepareGameArea();
Expand Down
15 changes: 7 additions & 8 deletions engines/lilliput/script.cpp
Expand Up @@ -1358,7 +1358,7 @@ Common::Point LilliputScript::getPosFromScript() {
}

void LilliputScript::sub130B6() {
debugC(1, kDebugScriptTBC, "sub130B6()");
debugC(1, kDebugScript, "sub130B6()");

assert(_vm->_word12F68_ERULES <= 20);
for (int i = 0; i < _vm->_word12F68_ERULES; i++) {
Expand Down Expand Up @@ -3174,7 +3174,7 @@ void LilliputScript::OC_sub1853B() {
_heroismLevel = 0;
sub130B6();

_vm->displayFunction12();
_vm->initGameAreaDisplay();

OC_PaletteFadeIn();
_byte12A09 = 0;
Expand Down Expand Up @@ -3228,22 +3228,21 @@ void LilliputScript::OC_sub186A1() {
debugC(1, kDebugScriptTBC, "OC_sub186A1()");

int var1 = getValue1();
int var2 = _currScript->readUint16LE();
int var3 = _currScript->readUint16LE();
int var4 = 16;
int posX = _currScript->readUint16LE();
int posY = _currScript->readUint16LE();
Common::Point pos = Common::Point(posX, posY);

_vm->fill16x16Rect(var4, var2, var3);
_vm->fill16x16Rect(16, pos);

int frame = _vm->_characterFrameArray[var1];

byte* buf = _vm->_bufferMen;

if (frame > 0xF0) {
buf = _vm->_bufferMen2;
frame -= 0xF0;
}

_vm->display16x16IndexedBuf(buf, frame, Common::Point(var2, var3));
_vm->display16x16IndexedBuf(buf, frame, pos);
}

void LilliputScript::OC_sub186E5_snd() {
Expand Down

0 comments on commit 29b476f

Please sign in to comment.