- modifies loadBitmap not to crash if a image isn't found

- starts to clean up the engine initalisation code

svn-id: r22308
This commit is contained in:
Johannes Schickel 2006-05-03 13:40:21 +00:00
parent 1d6a1bf157
commit 96fd5e1fbc
6 changed files with 82 additions and 45 deletions

View File

@ -287,11 +287,7 @@ KyraEngine_v1::KyraEngine_v1(OSystem *system)
:KyraEngine(system) {
}
KyraEngine_v2::KyraEngine_v2(OSystem *system)
:KyraEngine(system) {
}
int KyraEngine::init() {
int KyraEngine_v1::setupGameFlags() {
// Detect game features based on MD5. Again brutally ripped from Gobliins.
uint8 md5sum[16];
char md5str[32 + 1];
@ -361,6 +357,18 @@ int KyraEngine::init() {
return -1;
}
return 0;
}
KyraEngine_v2::KyraEngine_v2(OSystem *system)
:KyraEngine(system) {
}
int KyraEngine::init() {
if (setupGameFlags()) {
return -1;
}
// Setup mixer
if (!_mixer->isReady()) {
warning("Sound initialization failed.");
@ -382,13 +390,6 @@ int KyraEngine::init() {
Common::addSpecialDebugLevel(kDebugLevelSequence, "Sequence", "Sequence debug level");
Common::addSpecialDebugLevel(kDebugLevelMovie, "Movie", "Movie debug level");
_system->beginGFXTransaction();
initCommonGFX(false);
//for debug reasons (see Screen::updateScreen)
//_system->initSize(640, 200);
_system->initSize(320, 200);
_system->endGFXTransaction();
// for now we prefer Adlib over native MIDI
int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB/* | MDT_PREFER_MIDI*/);
@ -432,6 +433,7 @@ int KyraEngine::init() {
assert(_res);
_screen = new Screen(this, _system);
assert(_screen);
assert(_screen->init());
_sprites = new Sprites(this, _system);
assert(_sprites);
_seq = new SeqPlayer(this, _system);
@ -442,6 +444,7 @@ int KyraEngine::init() {
assert(*_animator);
_text = new TextDisplayer(_screen);
assert(_text);
_staticres = new StaticResource(this);
assert(_staticres);
assert(_staticres->init());

View File

@ -247,6 +247,8 @@ public:
KyraEngine(OSystem *system);
~KyraEngine();
virtual int setupGameFlags() = 0;
void errorString(const char *buf_input, char *buf_output);
@ -987,15 +989,19 @@ protected:
};
class KyraEngine_v1 : public KyraEngine {
public:
KyraEngine_v1(OSystem *system);
~KyraEngine_v1();
public:
KyraEngine_v1(OSystem *system);
~KyraEngine_v1();
int setupGameFlags();
};
class KyraEngine_v2 : public KyraEngine {
public:
KyraEngine_v2(OSystem *system);
~KyraEngine_v2();
public:
KyraEngine_v2(OSystem *system);
~KyraEngine_v2();
int setupGameFlags() { return 0; }
int go();
};

View File

@ -397,16 +397,24 @@ void KyraEngine::loadBitmap(const char *filename, int tempPage, int dstPage, uin
debugC(9, kDebugLevelMain, "KyraEngine::loadBitmap('%s', %d, %d, %p)", filename, tempPage, dstPage, (void *)palData);
uint32 fileSize;
uint8 *srcData = _res->fileData(filename, &fileSize);
assert(srcData);
if (!srcData) {
warning("coudln't load bitmap: '%s'", filename);
return;
}
uint8 compType = srcData[2];
uint32 imgSize = READ_LE_UINT32(srcData + 4);
uint16 palSize = READ_LE_UINT16(srcData + 8);
if (palData && palSize) {
debugC(9, kDebugLevelMain,"Loading a palette of size %i from %s", palSize, filename);
memcpy(palData, srcData + 10, palSize);
}
uint8 *srcPtr = srcData + 10 + palSize;
uint8 *dstData = _screen->getPagePtr(dstPage);
switch (compType) {
case 0:
memcpy(dstData, srcPtr, imgSize);
@ -421,7 +429,8 @@ void KyraEngine::loadBitmap(const char *filename, int tempPage, int dstPage, uin
error("Unhandled bitmap compression %d", compType);
break;
}
delete[] srcData;
delete [] srcData;
}
} // end of namespace Kyra

View File

@ -32,6 +32,44 @@ namespace Kyra {
Screen::Screen(KyraEngine *vm, OSystem *system)
: _system(system), _vm(vm) {
}
Screen::~Screen() {
for (int pageNum = 0; pageNum < SCREEN_PAGE_NUM; pageNum += 2) {
free(_pagePtrs[pageNum]);
_pagePtrs[pageNum] = _pagePtrs[pageNum + 1] = 0;
}
for (int f = 0; f < ARRAYSIZE(_fonts); ++f) {
delete[] _fonts[f].fontData;
_fonts[f].fontData = NULL;
}
free(_currentPalette);
free(_screenPalette);
free(_decodeShapeBuffer);
free(_animBlockPtr);
for (int i = 0; i < 3; ++i) {
free(_palettes[i]);
}
delete [] _bitBlitRects;
for (int i = 0; i < ARRAYSIZE(_saveLoadPage); ++i) {
delete [] _saveLoadPage[i];
_saveLoadPage[i] = 0;
}
free(_unkPtr1);
free(_unkPtr2);
}
bool Screen::init() {
debugC(9, kDebugLevelScreen, "Screen::init()");
_system->beginGFXTransaction();
_vm->initCommonGFX(false);
//for debug reasons (see Screen::updateScreen)
//_system->initSize(640, 200);
_system->initSize(320, 200);
_system->endGFXTransaction();
_curPage = 0;
for (int pageNum = 0; pageNum < SCREEN_PAGE_NUM; pageNum += 2) {
uint8 *pagePtr = (uint8 *)malloc(SCREEN_PAGE_SIZE);
@ -78,32 +116,8 @@ Screen::Screen(KyraEngine *vm, OSystem *system)
memset(_unkPtr1, 0, getRectSize(1, 144));
_unkPtr2 = (uint8*)malloc(getRectSize(1, 144));
memset(_unkPtr2, 0, getRectSize(1, 144));
}
Screen::~Screen() {
for (int pageNum = 0; pageNum < SCREEN_PAGE_NUM; pageNum += 2) {
free(_pagePtrs[pageNum]);
_pagePtrs[pageNum] = _pagePtrs[pageNum + 1] = 0;
}
for (int f = 0; f < ARRAYSIZE(_fonts); ++f) {
delete[] _fonts[f].fontData;
_fonts[f].fontData = NULL;
}
free(_currentPalette);
free(_screenPalette);
free(_decodeShapeBuffer);
free(_animBlockPtr);
for (int i = 0; i < 3; ++i) {
free(_palettes[i]);
}
delete [] _bitBlitRects;
for (int i = 0; i < ARRAYSIZE(_saveLoadPage); ++i) {
delete [] _saveLoadPage[i];
_saveLoadPage[i] = 0;
}
free(_unkPtr1);
free(_unkPtr2);
return true;
}
void Screen::updateScreen() {

View File

@ -89,6 +89,8 @@ public:
Screen(KyraEngine *vm, OSystem *system);
~Screen();
bool init();
void updateScreen();
uint8 *getPagePtr(int pageNum);
void clearPage(int pageNum);

View File

@ -750,6 +750,8 @@ void KyraEngine::loadButtonShapes() {
}
void KyraEngine::loadMainScreen(int page) {
_screen->clearPage(page);
if ((_features & GF_ENGLISH) && (_features & GF_TALKIE))
loadBitmap("MAIN_ENG.CPS", page, page, 0);
else if(_features & GF_FRENCH)
@ -765,6 +767,7 @@ void KyraEngine::loadMainScreen(int page) {
uint8 *_pageSrc = _screen->getPagePtr(page);
uint8 *_pageDst = _screen->getPagePtr(0);
memcpy(_pageDst, _pageSrc, 320*200);
}