completly decoupled engine.h/.cpp from simon.h and scumm.h; removed some static variables from drawFlashlight() and made them members of class Scumm instead

svn-id: r5506
This commit is contained in:
Max Horn 2002-11-10 17:19:43 +00:00
parent 2965bd2708
commit da5a347d3e
6 changed files with 68 additions and 49 deletions

View File

@ -20,10 +20,9 @@
#include "stdafx.h"
#include "engine.h"
#include "gameDetector.h"
#include "config-file.h"
#include "scumm/scumm.h"
#include "simon/simon.h"
#include "gameDetector.h"
#include "timer.h"
#include "sound/mixer.h"
/* FIXME - BIG HACK for MidiEmu */
@ -85,21 +84,10 @@ Engine *Engine::createFromDetector(GameDetector *detector, OSystem *syst)
if (detector->_gameId >= GID_SIMON_FIRST && detector->_gameId <= GID_SIMON_LAST) {
// Simon the Sorcerer
detector->_gameId -= GID_SIMON_FIRST;
engine = new SimonState(detector, syst);
engine = Engine_SIMON_create(detector, syst);
} else {
// Some kind of Scumm game
if (detector->_features & GF_OLD_BUNDLE)
engine = new Scumm_v2(detector, syst);
else if (detector->_features & GF_OLD256)
engine = new Scumm_v3(detector, syst);
else if (detector->_features & GF_SMALL_HEADER) // this force loomCD as v4
engine = new Scumm_v4(detector, syst);
else if (detector->_features & GF_AFTER_V7)
engine = new Scumm_v7(detector, syst);
else if (detector->_features & GF_AFTER_V6) // this force SamnmaxCD as v6
engine = new Scumm_v6(detector, syst);
else
engine = new Scumm_v5(detector, syst);
engine = Engine_SCUMM_create(detector, syst);
}
return engine;

View File

@ -71,6 +71,10 @@ void CDECL warning(const char *s, ...);
void CDECL debug(int level, const char *s, ...);
void checkHeap();
/* Factory functions => no need to include the specific classes
* in this header => faster compile */
extern Engine *Engine_SIMON_create(GameDetector *detector, OSystem *syst);
extern Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst);
#endif

View File

@ -612,26 +612,23 @@ void Scumm::moveMemInPalRes(int start, int end, byte direction)
void Scumm::drawFlashlight()
{
static byte *flashBuffer = NULL;
static int flashX, flashY, flashW, flashH;
int i, j, offset;
// Remove the flash light first if it was previously drawn
if (_flashlightIsDrawn) {
updateDirtyRect(0, flashX<<3, (flashX+flashW)<<3, flashY, flashY+flashH, 0x80000000);
updateDirtyRect(0, _flashlight.x<<3, (_flashlight.x+_flashlight.w)<<3, _flashlight.y, _flashlight.y+_flashlight.h, 0x80000000);
if (flashBuffer) {
if (_flashlight.buffer) {
offset = _realWidth - flashW*8;
i = flashH;
offset = _realWidth - _flashlight.w*8;
i = _flashlight.h;
do {
j = flashW*2;
j = _flashlight.w*2;
do {
*(uint32 *)flashBuffer = 0;
flashBuffer += 4;
*(uint32 *)_flashlight.buffer = 0;
_flashlight.buffer += 4;
} while (--j);
flashBuffer += offset;
_flashlight.buffer += offset;
} while (--i);
}
@ -643,50 +640,50 @@ void Scumm::drawFlashlight()
// Calculate the area of the flashlight
Actor *a = a = derefActorSafe(_vars[VAR_EGO], "drawFlashlight");
flashW = _flashlightXStrips;
flashH = _flashlightYStrips * 8;
flashX = a->x/8 - flashW/2 - _screenStartStrip;
flashY = a->y - flashH/2;
_flashlight.w = _flashlightXStrips;
_flashlight.h = _flashlightYStrips * 8;
_flashlight.x = a->x/8 - _flashlight.w/2 - _screenStartStrip;
_flashlight.y = a->y - _flashlight.h/2;
// Clip the flashlight at the borders
if (flashX < 0)
flashX = 0;
else if (flashX > gdi._numStrips - flashW)
flashX = gdi._numStrips - flashW;
if (flashY < 0)
flashY = 0;
else if (flashY > virtscr[0].height - flashH)
flashY = virtscr[0].height - flashH;
if (_flashlight.x < 0)
_flashlight.x = 0;
else if (_flashlight.x > gdi._numStrips - _flashlight.w)
_flashlight.x = gdi._numStrips - _flashlight.w;
if (_flashlight.y < 0)
_flashlight.y = 0;
else if (_flashlight.y > virtscr[0].height - _flashlight.h)
_flashlight.y = virtscr[0].height - _flashlight.h;
// Redraw any actors "under" the flashlight
for (i = flashX; i < flashX+flashW; i++) {
for (i = _flashlight.x; i < _flashlight.x+_flashlight.w; i++) {
gfxUsageBits[_screenStartStrip + i] |= 0x80000000;
virtscr[0].tdirty[i] = 0;
virtscr[0].bdirty[i] = virtscr[0].height;
}
byte *bgbak;
offset = flashY * _realWidth + virtscr[0].xstart + flashX * 8;
flashBuffer = virtscr[0].screenPtr + offset;
offset = _flashlight.y * _realWidth + virtscr[0].xstart + _flashlight.x * 8;
_flashlight.buffer = virtscr[0].screenPtr + offset;
bgbak = getResourceAddress(rtBuffer, 5) + offset;
blit(flashBuffer, bgbak, flashW*8, flashH);
blit(_flashlight.buffer, bgbak, _flashlight.w*8, _flashlight.h);
// Round the corners. To do so, we simply hard-code a set of nicely
// rounded corners.
int corner_data[] = { 8, 6, 4, 3, 2, 2, 1, 1 };
int minrow = 0;
int maxcol = flashW * 8 - 1;
int maxrow = (flashH - 1) * _realWidth;
int maxcol = _flashlight.w * 8 - 1;
int maxrow = (_flashlight.h - 1) * _realWidth;
for (i = 0; i < 8; i++, minrow += _realWidth, maxrow -= _realWidth) {
int d = corner_data[i];
for (j = 0; j < d; j++) {
flashBuffer[minrow + j] = 0;
flashBuffer[minrow + maxcol - j] = 0;
flashBuffer[maxrow + j] = 0;
flashBuffer[maxrow + maxcol - j] = 0;
_flashlight.buffer[minrow + j] = 0;
_flashlight.buffer[minrow + maxcol - j] = 0;
_flashlight.buffer[maxrow + j] = 0;
_flashlight.buffer[maxrow + maxcol - j] = 0;
}
}

View File

@ -714,6 +714,10 @@ public:
byte _newEffect, _switchRoomEffect2, _switchRoomEffect;
bool _doEffect;
struct {
int x, y, w, h;
byte *buffer;
} _flashlight;
uint16 _flashlightXStrips, _flashlightYStrips;
bool _flashlightIsDrawn;

View File

@ -51,6 +51,26 @@ void autosave(void * engine)
g_scumm->_doAutosave = true;
}
Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst)
{
Engine *engine;
if (detector->_features & GF_OLD_BUNDLE)
engine = new Scumm_v2(detector, syst);
else if (detector->_features & GF_OLD256)
engine = new Scumm_v3(detector, syst);
else if (detector->_features & GF_SMALL_HEADER) // this forces loomCD as v4
engine = new Scumm_v4(detector, syst);
else if (detector->_features & GF_AFTER_V7)
engine = new Scumm_v7(detector, syst);
else if (detector->_features & GF_AFTER_V6) // this forces SamnmaxCD as v6
engine = new Scumm_v6(detector, syst);
else
engine = new Scumm_v5(detector, syst);
return engine;
}
void Scumm::initRandSeeds()
{
_randSeed1 = 0xA943DE33;
@ -265,6 +285,7 @@ void Scumm::scummInit()
_vars[VAR_CURRENT_LIGHTS] = LIGHTMODE_actor_base | LIGHTMODE_actor_color | LIGHTMODE_screen;
_flashlightXStrips = 7;
_flashlightYStrips = 7;
_flashlight.buffer = NULL;
}
mouse.x = 104;

View File

@ -121,6 +121,11 @@ static const GameSpecificSettings simon2dos_settings = {
};
Engine *Engine_SIMON_create(GameDetector *detector, OSystem *syst)
{
return new SimonState(detector, syst);
}
SimonState::SimonState(GameDetector *detector, OSystem *syst)
: Engine(detector, syst)
{