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"
|
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() {
|
|
|
|
// Initialize backend
|
|
|
|
_system->beginGFXTransaction();
|
|
|
|
initCommonGFX(false);
|
|
|
|
_system->initSize(640, 480);
|
|
|
|
_system->endGFXTransaction();
|
|
|
|
|
|
|
|
_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-07-09 18:45:51 +00:00
|
|
|
{
|
2011-07-13 23:00:39 +00:00
|
|
|
// DEBUG: Dummy cursor
|
2011-07-09 18:45:51 +00:00
|
|
|
byte buffer[2*2];
|
|
|
|
memset(buffer, 255, 4);
|
|
|
|
CursorMan.replaceCursor(buffer, 2, 2, 0, 0, 0);
|
|
|
|
}
|
2011-07-08 19:09:33 +00:00
|
|
|
|
2011-06-24 15:36:35 +00:00
|
|
|
#if 0
|
2011-06-24 13:12:42 +00:00
|
|
|
BlbArchive *blb = new BlbArchive();
|
|
|
|
blb->open("m.blb");
|
|
|
|
delete blb;
|
2011-06-24 15:36:35 +00:00
|
|
|
#endif
|
|
|
|
|
2011-06-24 23:25:01 +00:00
|
|
|
#if 0
|
|
|
|
ResourceFileEntry *r = _res->findEntry(0x50A80517);
|
2011-06-24 15:36:35 +00:00
|
|
|
#endif
|
2011-06-24 13:12:42 +00:00
|
|
|
|
2011-06-24 23:25:01 +00:00
|
|
|
#if 0
|
|
|
|
int resourceHandle = _res->useResource(0x0CA04202);
|
|
|
|
debug("resourceHandle = %d", resourceHandle);
|
|
|
|
byte *data = _res->loadResource(resourceHandle);
|
|
|
|
bool rle;
|
|
|
|
NDimensions dimensions;
|
|
|
|
NUnknown unknown;
|
|
|
|
byte *palette, *pixels;
|
|
|
|
parseBitmapResource(data, &rle, &dimensions, &unknown, &palette, &pixels);
|
|
|
|
debug("%d, %d", dimensions.width, dimensions.height);
|
|
|
|
byte *rawpixels = new byte[dimensions.width * dimensions.height];
|
|
|
|
memset(rawpixels, 0, dimensions.width * dimensions.height);
|
|
|
|
debug("rle = %d", rle);
|
|
|
|
unpackSpriteRle(pixels, dimensions.width, dimensions.height, rawpixels, dimensions.width, false, false);
|
|
|
|
Common::DumpFile d;
|
|
|
|
d.open("dump.0");
|
|
|
|
d.write(rawpixels, dimensions.width * dimensions.height);
|
|
|
|
d.close();
|
|
|
|
delete[] rawpixels;
|
|
|
|
_res->unloadResource(resourceHandle);
|
|
|
|
_res->unuseResource(resourceHandle);
|
|
|
|
#endif
|
|
|
|
|
2011-07-01 10:25:55 +00:00
|
|
|
#if 0
|
2011-06-27 11:06:40 +00:00
|
|
|
{ // Create a new scope
|
|
|
|
SpriteResource r(this);
|
|
|
|
BaseSurface *surf = new BaseSurface(this, 0, 640, 480);
|
|
|
|
r.load(0x0CA04202);
|
2011-06-30 09:55:59 +00:00
|
|
|
debug("r: width = %d; height = %d", r.getDimensions().width, r.getDimensions().height);
|
2011-06-27 11:06:40 +00:00
|
|
|
surf->drawSpriteResource(r);
|
|
|
|
delete surf;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-07-01 13:20:46 +00:00
|
|
|
#if 0
|
2011-07-01 10:25:55 +00:00
|
|
|
{ // Create a new scope
|
|
|
|
AnimResource r(this);
|
|
|
|
r.load(0x000540B0);
|
|
|
|
}
|
|
|
|
#endif
|
2011-06-24 23:25:01 +00:00
|
|
|
|
2011-07-16 11:01:08 +00:00
|
|
|
#if 0
|
|
|
|
{ // Create a new scope
|
|
|
|
DataResource dataResource(this);
|
|
|
|
//dataResource.load(0x01801002);
|
|
|
|
//dataResource.load(0x84500132);
|
|
|
|
dataResource.load(0x81120132);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1
|
2011-07-27 18:02:30 +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();
|
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;
|
|
|
|
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;
|
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
|
|
|
|
2011-07-04 17:58:38 +00:00
|
|
|
//debug("millis %d", _system->getMillis());
|
2011-07-01 13:20:46 +00:00
|
|
|
_gameModule->handleUpdate();
|
2011-07-03 19:26:27 +00:00
|
|
|
_gameModule->draw();
|
2011-07-04 10:52:07 +00:00
|
|
|
_screen->wait();
|
|
|
|
_screen->update();
|
|
|
|
|
2011-07-09 18:45:51 +00:00
|
|
|
debug("---------------------------------------");
|
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;
|
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-06-22 22:58:51 +00:00
|
|
|
} // End of namespace Neverhood
|