2011-06-22 22:58:51 +00:00
|
|
|
/* 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 "common/file.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "base/plugins.h"
|
|
|
|
#include "base/version.h"
|
|
|
|
#include "graphics/cursorman.h"
|
|
|
|
#include "engines/util.h"
|
|
|
|
#include "neverhood/neverhood.h"
|
2011-06-24 13:12:42 +00:00
|
|
|
#include "neverhood/blbarchive.h"
|
2011-07-05 14:46:10 +00:00
|
|
|
#include "neverhood/collisionman.h"
|
2011-07-01 13:20:46 +00:00
|
|
|
#include "neverhood/gamemodule.h"
|
2011-07-11 08:25:24 +00:00
|
|
|
#include "neverhood/gamevars.h"
|
2011-06-24 23:25:01 +00:00
|
|
|
#include "neverhood/graphics.h"
|
2011-06-24 15:36:35 +00:00
|
|
|
#include "neverhood/resourceman.h"
|
2011-06-27 11:06:40 +00:00
|
|
|
#include "neverhood/resource.h"
|
2011-07-03 12:09:48 +00:00
|
|
|
#include "neverhood/screen.h"
|
2012-09-20 13:28:20 +00:00
|
|
|
#include "neverhood/sound.h"
|
2011-07-05 14:22:18 +00:00
|
|
|
#include "neverhood/staticdata.h"
|
2011-06-22 22:58:51 +00:00
|
|
|
|
|
|
|
namespace Neverhood {
|
|
|
|
|
|
|
|
NeverhoodEngine::NeverhoodEngine(OSystem *syst, const NeverhoodGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
|
|
|
|
// Setup mixer
|
|
|
|
if (!_mixer->isReady()) {
|
|
|
|
warning("Sound initialization failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
|
|
|
|
|
|
|
_rnd = new Common::RandomSource("neverhood");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NeverhoodEngine::~NeverhoodEngine() {
|
|
|
|
delete _rnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error NeverhoodEngine::run() {
|
2011-08-21 23:39:45 +00:00
|
|
|
initGraphics(640, 480, true);
|
2011-06-22 22:58:51 +00:00
|
|
|
|
|
|
|
_isSaveAllowed = false;
|
|
|
|
|
2011-07-11 18:47:03 +00:00
|
|
|
_mouseX = 0;
|
|
|
|
_mouseY = 0;
|
|
|
|
|
|
|
|
_gameState.sceneNum = 0;
|
|
|
|
_gameState.field2 = 0;
|
|
|
|
|
2011-07-05 14:22:18 +00:00
|
|
|
_staticData = new StaticData();
|
|
|
|
_staticData->load("neverhood.dat");
|
|
|
|
|
2011-07-11 08:25:24 +00:00
|
|
|
_gameVars = new GameVars();
|
|
|
|
|
2011-07-03 12:09:48 +00:00
|
|
|
_screen = new Screen(this);
|
|
|
|
|
2011-06-24 23:25:01 +00:00
|
|
|
_res = new ResourceMan();
|
|
|
|
_res->addArchive("a.blb");
|
|
|
|
_res->addArchive("c.blb");
|
|
|
|
_res->addArchive("hd.blb");
|
|
|
|
_res->addArchive("i.blb");
|
|
|
|
_res->addArchive("m.blb");
|
|
|
|
_res->addArchive("s.blb");
|
|
|
|
_res->addArchive("t.blb");
|
|
|
|
|
2011-07-08 19:09:33 +00:00
|
|
|
CursorMan.showMouse(true);
|
|
|
|
|
2011-06-24 15:36:35 +00:00
|
|
|
#if 0
|
2011-10-21 09:13:49 +00:00
|
|
|
// TODO: This should probably be implemented as debug command later
|
|
|
|
dumpAllResources();
|
2011-07-16 11:01:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1
|
2011-07-27 18:02:30 +00:00
|
|
|
|
2012-09-20 13:28:20 +00:00
|
|
|
_soundMan = new SoundMan(this);
|
2012-09-22 00:55:40 +00:00
|
|
|
_audioResourceMan = new AudioResourceMan(this);
|
2012-09-20 13:28:20 +00:00
|
|
|
|
2011-07-05 14:46:10 +00:00
|
|
|
_collisionMan = new CollisionMan(this);
|
2011-07-01 13:20:46 +00:00
|
|
|
_gameModule = new GameModule(this);
|
2011-07-27 18:02:30 +00:00
|
|
|
|
|
|
|
_gameModule->startup();
|
2012-10-14 10:28:44 +00:00
|
|
|
|
|
|
|
uint32 nextFrameTime = 0;
|
2011-06-22 22:58:51 +00:00
|
|
|
|
2011-07-03 19:26:27 +00:00
|
|
|
// Preliminary main loop, needs some more work but works for testing
|
2011-07-06 19:56:15 +00:00
|
|
|
while (!shouldQuit()) {
|
2011-07-01 13:20:46 +00:00
|
|
|
Common::Event event;
|
|
|
|
Common::EventManager *eventMan = _system->getEventManager();
|
|
|
|
|
|
|
|
while (eventMan->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
_keyState = event.kbd.keycode;
|
2012-10-11 21:23:55 +00:00
|
|
|
switch (_keyState) {
|
2012-10-19 13:55:37 +00:00
|
|
|
case Common::KEYCODE_ESCAPE:
|
|
|
|
_gameModule->handleEscapeKey();
|
|
|
|
break;
|
2012-10-11 21:23:55 +00:00
|
|
|
case Common::KEYCODE_SPACE:
|
|
|
|
_gameModule->handleSpaceKey();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-07-01 13:20:46 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_KEYUP:
|
|
|
|
_keyState = Common::KEYCODE_INVALID;
|
|
|
|
break;
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
2011-07-11 12:21:56 +00:00
|
|
|
_gameModule->handleMouseMove(event.mouse.x, event.mouse.y);
|
2011-07-01 13:20:46 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2011-07-07 20:26:12 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
_gameModule->handleMouseDown(event.mouse.x, event.mouse.y);
|
|
|
|
break;
|
2012-10-12 19:19:24 +00:00
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
|
|
|
_gameModule->handleMouseUp(event.mouse.x, event.mouse.y);
|
|
|
|
break;
|
2011-07-01 13:20:46 +00:00
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
_system->quit();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-06-22 22:58:51 +00:00
|
|
|
}
|
2011-07-04 10:52:07 +00:00
|
|
|
|
2012-10-14 10:28:44 +00:00
|
|
|
if (_system->getMillis() >= nextFrameTime) {
|
2012-10-19 13:55:37 +00:00
|
|
|
_gameModule->checkMainMenu();
|
2012-10-14 10:28:44 +00:00
|
|
|
_gameModule->handleUpdate();
|
|
|
|
_gameModule->draw();
|
2012-10-17 20:49:43 +00:00
|
|
|
_screen->update();
|
2012-10-14 10:28:44 +00:00
|
|
|
nextFrameTime = _screen->getNextFrameTime();
|
2012-10-19 10:51:15 +00:00
|
|
|
//_gameVars->dumpVars();
|
2012-10-14 10:28:44 +00:00
|
|
|
};
|
|
|
|
|
2012-09-22 00:55:40 +00:00
|
|
|
_soundMan->update();
|
|
|
|
_audioResourceMan->update();
|
2012-10-17 20:49:43 +00:00
|
|
|
//_screen->update();
|
|
|
|
_system->updateScreen();
|
2012-10-14 10:28:44 +00:00
|
|
|
_system->delayMillis(10);
|
2011-07-04 10:52:07 +00:00
|
|
|
|
2011-08-02 10:56:16 +00:00
|
|
|
debug(0, "---------------------------------------");
|
2011-07-01 13:20:46 +00:00
|
|
|
|
2011-06-22 22:58:51 +00:00
|
|
|
}
|
2011-07-01 13:20:46 +00:00
|
|
|
|
|
|
|
delete _gameModule;
|
2011-07-05 14:46:10 +00:00
|
|
|
delete _collisionMan;
|
2012-09-20 13:28:20 +00:00
|
|
|
delete _soundMan;
|
2012-09-22 00:55:40 +00:00
|
|
|
delete _audioResourceMan;
|
2011-07-16 11:01:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-07-01 13:20:46 +00:00
|
|
|
delete _res;
|
2011-07-03 12:09:48 +00:00
|
|
|
delete _screen;
|
2011-07-05 14:22:18 +00:00
|
|
|
|
2011-07-11 08:25:24 +00:00
|
|
|
delete _gameVars;
|
2011-07-05 14:22:18 +00:00
|
|
|
delete _staticData;
|
2011-07-01 13:20:46 +00:00
|
|
|
|
|
|
|
debug("Ok.");
|
|
|
|
|
|
|
|
return Common::kNoError;
|
2011-06-22 22:58:51 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 19:03:09 +00:00
|
|
|
NPoint NeverhoodEngine::getMousePos() {
|
|
|
|
NPoint pt;
|
|
|
|
pt.x = _mouseX;
|
|
|
|
pt.y = _mouseY;
|
|
|
|
return pt;
|
|
|
|
}
|
2011-10-21 09:13:49 +00:00
|
|
|
|
|
|
|
void writeTga(const char *filename, byte *pixels, byte *palette, int16 width, int16 height) {
|
|
|
|
byte identsize = 0;
|
|
|
|
byte colourmaptype = 1;
|
|
|
|
byte imagetype = 1;
|
|
|
|
uint16 colourmapstart = 0;
|
|
|
|
uint16 colourmaplength = 256;
|
|
|
|
byte colourmapbits = 24;
|
|
|
|
uint16 xstart = 0;
|
|
|
|
uint16 ystart = 0;
|
|
|
|
byte bits = 8;
|
|
|
|
byte descriptor = 0x20;
|
|
|
|
Common::DumpFile tga;
|
|
|
|
tga.open(filename);
|
|
|
|
tga.writeByte(identsize);
|
|
|
|
tga.writeByte(colourmaptype);
|
|
|
|
tga.writeByte(imagetype);
|
|
|
|
tga.writeUint16LE(colourmapstart);
|
|
|
|
tga.writeUint16LE(colourmaplength);
|
|
|
|
tga.writeByte(colourmapbits);
|
|
|
|
tga.writeUint16LE(xstart);
|
|
|
|
tga.writeUint16LE(ystart);
|
|
|
|
tga.writeUint16LE(width);
|
|
|
|
tga.writeUint16LE(height);
|
|
|
|
tga.writeByte(bits);
|
|
|
|
tga.writeByte(descriptor);
|
|
|
|
tga.write(palette, 768);
|
|
|
|
tga.write(pixels, width * height);
|
|
|
|
tga.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NeverhoodEngine::dumpAllResources() {
|
|
|
|
|
|
|
|
PaletteResource paletteResource(this);
|
|
|
|
byte *vgaPalette = new byte[768];
|
2011-10-28 12:04:59 +00:00
|
|
|
//paletteResource.load(0x4086520E);
|
|
|
|
paletteResource.load(0x12C23307);
|
2011-10-21 09:13:49 +00:00
|
|
|
byte *srcpalette = paletteResource.palette();
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
vgaPalette[i * 3 + 2] = srcpalette[i * 4 + 0];
|
|
|
|
vgaPalette[i * 3 + 1] = srcpalette[i * 4 + 1];
|
|
|
|
vgaPalette[i * 3 + 0] = srcpalette[i * 4 + 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
for (int i = 0; i < 768; i++)
|
|
|
|
vgaPalette[i] <<= 2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint entriesCount = _res->getEntryCount();
|
|
|
|
debug("%d entries", entriesCount);
|
|
|
|
|
|
|
|
for (uint i = 0; i < entriesCount; i++) {
|
|
|
|
const ResourceFileEntry &entry = _res->getEntry(i);
|
2012-10-14 09:37:44 +00:00
|
|
|
int type = _res->getResourceTypeByHash(entry.archiveEntry->fileHash);
|
|
|
|
debug("hash: %08X; type: %d", entry.archiveEntry->fileHash, type);
|
2011-10-21 09:13:49 +00:00
|
|
|
if (type == 4) {
|
|
|
|
AnimResource anim(this);
|
2012-10-14 09:37:44 +00:00
|
|
|
anim.load(entry.archiveEntry->fileHash);
|
2011-10-21 09:13:49 +00:00
|
|
|
for (uint frameIndex = 0; frameIndex < anim.getFrameCount(); frameIndex++) {
|
|
|
|
const AnimFrameInfo &frameInfo = anim.getFrameInfo(frameIndex);
|
|
|
|
int16 width = (frameInfo.rect.width + 3) & 0xFFFC;
|
|
|
|
byte *pixels = new byte[width * frameInfo.rect.height];
|
|
|
|
memset(pixels, 0, width * frameInfo.rect.height);
|
|
|
|
anim.draw(frameIndex, pixels, width, false, false);
|
|
|
|
Common::String filename =
|
|
|
|
frameInfo.frameHash != 0
|
2012-10-14 09:37:44 +00:00
|
|
|
? Common::String::format("%08X_%03d_%08X.tga", entry.archiveEntry->fileHash, frameIndex, frameInfo.frameHash)
|
|
|
|
: Common::String::format("%08X_%03d.tga", entry.archiveEntry->fileHash, frameIndex);
|
2011-10-21 09:13:49 +00:00
|
|
|
writeTga(filename.c_str(), pixels, vgaPalette, width, frameInfo.rect.height);
|
|
|
|
delete[] pixels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] vgaPalette;
|
|
|
|
|
|
|
|
}
|
2011-07-14 19:03:09 +00:00
|
|
|
|
2011-06-22 22:58:51 +00:00
|
|
|
} // End of namespace Neverhood
|