diff --git a/engines/asylum/asylum.cpp b/engines/asylum/asylum.cpp index 61a70ff7fa4..bff73bd49f4 100644 --- a/engines/asylum/asylum.cpp +++ b/engines/asylum/asylum.cpp @@ -81,6 +81,7 @@ Common::Error AsylumEngine::go() { // ScummVM window alive until ESC is pressed. // This will facilitate drawing tests ;) bool end = false; + int updateCounter = 0; Common::EventManager *em = _system->getEventManager(); while (!end) { Common::Event ev; @@ -90,6 +91,14 @@ Common::Error AsylumEngine::go() { end = true; //if (ev.kbd.keycode == Common::KEYCODE_RETURN) } + if (ev.type == Common::EVENT_MOUSEMOVE) { + updateCounter++; + if(updateCounter>6){ + _screen->updateScreen(); + updateCounter = 0; + } + + } } _system->delayMillis(10); } @@ -100,11 +109,19 @@ Common::Error AsylumEngine::go() { void AsylumEngine::showMainMenu() { // eyes animation index table //const uint32 eyesTable[8] = {3, 5, 1, 7, 4, 8, 2, 6}; + PaletteBundle *pal = _resMgr->getPalette(1, 17); + GraphicResource *bg = _resMgr->getGraphic(1, 0)->getEntry(0); + GraphicResource *cur = _resMgr->getGraphic(1, 2)->getEntry(0); + + _system->setMouseCursor(cur->data, cur->width, cur->height, 1, 1, 0); + _system->setCursorPalette(pal->palette, 0, 768); + _system->showMouse(true); + _screen->setFrontBuffer( 0, 0, - SCREEN_WIDTH, SCREEN_DEPTH, - _resMgr->getGraphic("res.001",0).getEntry(0).data); - _screen->setPalette(_resMgr->getPalette("res.001", 17).data); + bg->width, bg->height, + bg->data); + _screen->setPalette(pal->palette); _screen->updateScreen(); } diff --git a/engines/asylum/asylum.h b/engines/asylum/asylum.h index e1275529c7a..fb18e1e14e6 100644 --- a/engines/asylum/asylum.h +++ b/engines/asylum/asylum.h @@ -24,7 +24,7 @@ #include "engines/engine.h" -#include "asylum/resourcemanager.h" +#include "asylum/resman.h" namespace Asylum { diff --git a/engines/asylum/bundles/bundle.cpp b/engines/asylum/bundles/bundle.cpp index 9c0c6ede6bb..02757fed6fa 100644 --- a/engines/asylum/bundles/bundle.cpp +++ b/engines/asylum/bundles/bundle.cpp @@ -21,29 +21,86 @@ #include "common/file.h" #include "asylum/bundles/bundle.h" -#include "asylum/offsets.h" namespace Asylum { Bundle::Bundle() { size = 0; numEntries = 0; + offset = 0; } -Bundle::Bundle(Common::String filename, uint32 index) { - loadRaw(filename, index); +Bundle::Bundle(uint8 fileNum) { + Common::File* file = new Common::File; + Common::String filename = parseFilename(fileNum); + + id = fileNum; + + // load the file + if (!file || !file->open(filename)) { + printf("Failed to load file %s", filename.c_str()); + }else{ + // set the filesize + size = file->size(); + + // read the entry count + file->read( &numEntries, 4 ); + + // create the resource item array and + // set the item offset for each entry + for (uint8 i = 0; i < numEntries; i++) { + Bundle *bun = new Bundle; + file->read(&bun->offset, 4); + bun->initialized = false; + entries.push_back(bun); + } + + // set the last entry's offset to the filesize + entries[numEntries - 1]->offset = size - file->pos(); + + // calculate each entry's size based on the offset + // information + for (uint8 j = 0; j < numEntries; j++) { + if (entries[j]->offset == 0) { + entries[j]->size = 0; + continue; + } + + entries[j]->size = getNextValidOffset(j+1) - entries[j]->offset; + } + + /* Skip population phase + // populate the data + for (uint8 k = 0; k < numEntries; k++) { + if (entries[k].size > 0) { + entries[k].data = (uint8*)malloc(entries[k].size); + file->seek(entries[k].offset, SEEK_SET); + file->read(entries[k].data, entries[k].size); + } + + // DEBUGGING + // Dump bundles to file + //char fn[20]; + //sprintf(fn, "RES000-0%02d.DAT", k); + //entries[k].save(Common::String(fn)); + } + */ + } + + file->close(); + file = NULL; } -int Bundle::loadRaw(Common::String filename, uint32 index) { +void Bundle::loadRawRecord(Common::String filename, uint32 index, uint32 length) { + Common::File *file = new Common::File; if (!file || !file->open(filename)) { printf("Failed to load file %s", filename.c_str()); - return -1; } - uint32 offset = res001[index][0]; - size = res001[index][1]; + offset = index; + size = length; data = (uint8*)malloc(size); file->seek(offset, SEEK_SET); @@ -53,8 +110,28 @@ int Bundle::loadRaw(Common::String filename, uint32 index) { file = NULL; update(); +} - return 0; +void Bundle::setEntry(uint32 index, Bundle* value) { + value->initialized = true; + entries[index] = value; +} + +Common::String Bundle::parseFilename(uint8 fileNum) { + char filename[20]; + sprintf(filename, RESMASK, fileNum); + + return Common::String(filename); +} + +uint32 Bundle::getNextValidOffset(uint8 index) { + for (uint8 i = index; i < numEntries; i++) { + if (entries[i]->offset != 0) { + return entries[i]->offset; + } + } + + return size; } } // end of namespace Asylum diff --git a/engines/asylum/bundles/bundle.h b/engines/asylum/bundles/bundle.h index 593be66b028..1946c424a0f 100644 --- a/engines/asylum/bundles/bundle.h +++ b/engines/asylum/bundles/bundle.h @@ -33,22 +33,33 @@ namespace Asylum { +#define RESMASK "res.0%02d" + class Bundle { public: Bundle(); - Bundle(Common::String filename, uint32 index); + Bundle(uint8 fileNum); virtual ~Bundle() {} - Common::String id; - uint32 size; - uint32 numEntries; - Common::Array entries; + uint8* getData() { return data; } + Bundle* getEntry(uint32 index) { return entries[index]; } + void setEntry(uint32 index, Bundle* value); + + uint8 id; + uint32 size; + uint32 offset; + uint32 numEntries; + bool initialized; + - uint8* getData() { return data; } protected: - int loadRaw(Common::String filename, uint32 index); + Common::Array entries; + Common::String parseFilename(uint8 fileNum); + void loadRawRecord(Common::String filename, uint32 index, uint32 length); + uint32 getNextValidOffset(uint8 index); virtual void update(){} + uint8 *data; private: diff --git a/engines/asylum/bundles/graphicbundle.cpp b/engines/asylum/bundles/graphicbundle.cpp index 9b0ee7d1dc5..4495243ec6c 100644 --- a/engines/asylum/bundles/graphicbundle.cpp +++ b/engines/asylum/bundles/graphicbundle.cpp @@ -23,8 +23,8 @@ namespace Asylum { -GraphicBundle::GraphicBundle(Common::String filename, uint32 index) { - loadRaw(filename, index); +GraphicBundle::GraphicBundle(uint8 fileNum, uint32 index, uint32 length) { + loadRawRecord(parseFilename(fileNum), index, length); } void GraphicBundle::update() { @@ -65,12 +65,12 @@ void GraphicBundle::update() { gra->data = (uint8*)malloc(gra->size - 16); memcpy(gra->data, data + pos, gra->size - 16); - entries.push_back(*gra); + entries.push_back(gra); } } -GraphicResource GraphicBundle::getEntry(uint32 index) { - return (GraphicResource)entries[index]; +GraphicResource* GraphicBundle::getEntry(uint32 index) { + return (GraphicResource*)entries[index]; } } // end of namespace Asylum diff --git a/engines/asylum/bundles/graphicbundle.h b/engines/asylum/bundles/graphicbundle.h index f826e207dab..847bde44ba0 100644 --- a/engines/asylum/bundles/graphicbundle.h +++ b/engines/asylum/bundles/graphicbundle.h @@ -30,14 +30,14 @@ namespace Asylum { class GraphicBundle: public Bundle { public: GraphicBundle() {} - GraphicBundle(Common::String filename, uint32 index); + GraphicBundle(uint8 fileNum, uint32 index, uint32 length); ~GraphicBundle() {} - Common::Array entries; - GraphicResource getEntry(uint32 index); + GraphicResource* getEntry(uint32 index); protected: void update(); + Common::Array entries; private: uint32 _tagValue; diff --git a/engines/asylum/bundles/palettebundle.cpp b/engines/asylum/bundles/palettebundle.cpp new file mode 100644 index 00000000000..d3ad90ca494 --- /dev/null +++ b/engines/asylum/bundles/palettebundle.cpp @@ -0,0 +1,34 @@ +/* + * PaletteBundle.cpp + * + * Created on: 9-Jun-2009 + * Author: alex + */ + +#include "asylum/bundles/palettebundle.h" + +namespace Asylum { + +PaletteBundle::PaletteBundle(uint8 fileNum, uint32 index, uint32 length) { + loadRawRecord(parseFilename(fileNum), index, length); +} + +void PaletteBundle::update() { + +} + +uint8* PaletteBundle::getPalette(uint8 brightness) { + // palettes always start from offset 32 + memcpy(palette, data+32, sizeof(uint8)*256*3); + + for (int i = 0; i < 256; i++) { + *p++ = *palette++ * brightness; + *p++ = *palette++ * brightness; + *p++ = *palette++ * brightness; + *p++ = 0; + } + + return palette; +} + +} // end of namespace Asylum diff --git a/engines/asylum/bundles/palettebundle.h b/engines/asylum/bundles/palettebundle.h new file mode 100644 index 00000000000..4d6141630e6 --- /dev/null +++ b/engines/asylum/bundles/palettebundle.h @@ -0,0 +1,31 @@ +/* + * PaletteBundle.h + * + * Created on: 9-Jun-2009 + * Author: alex + */ + +#ifndef PALETTEBUNDLE_H_ +#define PALETTEBUNDLE_H_ + +#include "asylum/bundles/bundle.h" + +namespace Asylum { + +class PaletteBundle: public Bundle { +public: + PaletteBundle() {} + PaletteBundle(uint8 fileNum, uint32 index, uint32 length); + + ~PaletteBundle() {} + + uint8* getPalette(uint8 brightness); + +protected: + uint8 palette[256*3]; + void update(); +}; + +} + +#endif /* PALETTEBUNDLE_H_ */ diff --git a/engines/asylum/module.mk b/engines/asylum/module.mk index ea661e57760..d49906dcb9f 100644 --- a/engines/asylum/module.mk +++ b/engines/asylum/module.mk @@ -1,16 +1,15 @@ MODULE := engines/asylum MODULE_OBJS := \ - bundles/bundle.o \ - bundles/graphicbundle.o \ - resources/resource.o \ - resources/graphic.o \ - resources/palette.o \ asylum.o \ detection.o \ - resourcemanager.o \ - screen.o - + resman.o \ + screen.o \ + bundles/bundle.o \ + bundles/graphicbundle.o \ + bundles/palettebundle.o \ + resources/resource.o \ + resources/graphic.o # This module can be built as a plugin ifeq ($(ENABLE_ASYLUM), DYNAMIC_PLUGIN) diff --git a/engines/asylum/resman.cpp b/engines/asylum/resman.cpp new file mode 100644 index 00000000000..4a9fa65a287 --- /dev/null +++ b/engines/asylum/resman.cpp @@ -0,0 +1,66 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "asylum/resman.h" + +namespace Asylum { + +GraphicBundle* ResourceManager::getGraphic(uint8 fileNum, uint32 offset) { + Bundle *bun = getBundle(fileNum); + Bundle *ent = bun->getEntry(offset); + + if(!ent->initialized){ + GraphicBundle *gra = new GraphicBundle(fileNum, ent->offset, ent->size); + bun->setEntry(offset, gra); + } + + return (GraphicBundle*)bun->getEntry(offset); +} + +PaletteBundle* ResourceManager::getPalette(uint8 fileNum, uint32 offset) { + Bundle *bun = getBundle(fileNum); + Bundle *ent = bun->getEntry(offset); + if(!ent->initialized){ + PaletteBundle *pal = new PaletteBundle(fileNum, ent->offset, ent->size); + bun->setEntry(offset, pal); + } + + return (PaletteBundle*)bun->getEntry(offset); +} + +Bundle* ResourceManager::getBundle(uint8 fileNum) { + // first check if the bundle exists in the cache + Bundle* bun = NULL; + + for (uint32 i = 0; i < _bundleCache.size(); i++) { + if (_bundleCache[i].id == fileNum ){ + *bun = _bundleCache[i]; + } + } + + if(!bun) { + bun = new Bundle(fileNum); + } + + return bun; +} + +} // end of namespace Asylum diff --git a/engines/asylum/resman.h b/engines/asylum/resman.h new file mode 100644 index 00000000000..73aa3de06c0 --- /dev/null +++ b/engines/asylum/resman.h @@ -0,0 +1,52 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef ASYLUM_RESOURCEMANAGER_H_ +#define ASYLUM_RESOURCEMANAGER_H_ + +#include "common/str.h" +#include "common/array.h" + +#include "asylum/bundles/bundle.h" +#include "asylum/bundles/graphicbundle.h" +#include "asylum/bundles/palettebundle.h" + +namespace Asylum { + +class ResourceManager { +public: + ResourceManager() {}; + ~ResourceManager() {}; + + GraphicBundle* getGraphic(uint8 fileNum, uint32 offset); + PaletteBundle* getPalette(uint8 fileNum, uint32 offset); + +private: + Common::Array _bundleCache; + + Bundle* getBundle(uint8 fileNum); + +}; // end of class ResourceManager + + +} // end of namespace Asylum + +#endif diff --git a/engines/asylum/resources/resource.cpp b/engines/asylum/resources/resource.cpp index d6bd5ecb090..c97bc1dd081 100644 --- a/engines/asylum/resources/resource.cpp +++ b/engines/asylum/resources/resource.cpp @@ -24,8 +24,9 @@ namespace Asylum { Resource::Resource() { - size = 0; - offset = 0; + size = 0; + offset = 0; + initialized = false; } int Resource::save(Common::String filename) { diff --git a/engines/asylum/resources/resource.h b/engines/asylum/resources/resource.h index 328cd8b52e5..50436f7fa50 100644 --- a/engines/asylum/resources/resource.h +++ b/engines/asylum/resources/resource.h @@ -37,6 +37,7 @@ public: uint32 size; uint32 offset; uint8* data; + bool initialized; }; // end of class Resource diff --git a/engines/asylum/screen.h b/engines/asylum/screen.h index 471ec47b6ff..f9130330223 100644 --- a/engines/asylum/screen.h +++ b/engines/asylum/screen.h @@ -31,7 +31,7 @@ class OSystem; #define SCREEN_DEPTH 480 #define PAL_SIZE 256 -#define BRIGHTNESS 7 +#define BRIGHTNESS 6 namespace Asylum {