Skip to content

Commit

Permalink
NEVERHOOD: Add a debug console, together with a command to change rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegr committed Jun 9, 2013
1 parent 3dfe255 commit a14cb19
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 3 deletions.
58 changes: 58 additions & 0 deletions engines/neverhood/console.cpp
@@ -0,0 +1,58 @@
/* 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 "neverhood/console.h"
#include "gui/debugger.h"
#include "neverhood/neverhood.h"
#include "neverhood/gamemodule.h"

namespace Neverhood {

Console::Console(NeverhoodEngine *vm) : GUI::Debugger(), _vm(vm) {
DCmd_Register("room", WRAP_METHOD(Console, Cmd_Room));
}

Console::~Console() {
}

bool Console::Cmd_Room(int argc, const char **argv) {
int currentModule = _vm->_gameModule->getCurrentModuleNum();
int previousModule = _vm->_gameModule->getPreviousModuleNum();
int scene = _vm->gameState().sceneNum;

DebugPrintf("Current module: %d, previous module: %d, scene %d\n", currentModule, previousModule, scene);

if (argc != 3) {
DebugPrintf("Use room <module> <scene> to change rooms\n");
DebugPrintf("Modules are incremental by 100, from 1000 to 3000\n");
} else {
int module = atoi(argv[1]);
int scene = atoi(argv[2]);

_vm->gameState().sceneNum = scene;
_vm->_gameModule->createModule(module, -1);
}

return true;
}

} // End of namespace Neverhood
44 changes: 44 additions & 0 deletions engines/neverhood/console.h
@@ -0,0 +1,44 @@
/* 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 NEVERHOOD_CONSOLE_H
#define NEVERHOOD_CONSOLE_H

#include "gui/debugger.h"

namespace Neverhood {

class NeverhoodEngine;

class Console : public GUI::Debugger {
public:
Console(NeverhoodEngine *vm);
virtual ~Console(void);

private:
NeverhoodEngine *_vm;

bool Cmd_Room(int argc, const char **argv);
};

} // End of namespace Neverhood
#endif
5 changes: 4 additions & 1 deletion engines/neverhood/gamemodule.h
Expand Up @@ -55,6 +55,10 @@ class GameModule : public Module {
void initCubeSymbolsPuzzle();
void initCrystalColorsPuzzle();
uint32 getCurrRadioMusicFileHash();
int getCurrentModuleNum() { return _moduleNum; }
int getPreviousModuleNum() { return _moduleNum; }

void createModule(int moduleNum, int which);
protected:
int _moduleNum;
Entity *_prevChildObject;
Expand All @@ -64,7 +68,6 @@ class GameModule : public Module {
bool _canRequestMainMenu;
bool _mainMenuRequested;
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
void createModule(int moduleNum, int which);
void createModuleByHash(uint32 nameHash);
void updateModule();
void openMainMenu();
Expand Down
1 change: 1 addition & 0 deletions engines/neverhood/module.mk
Expand Up @@ -3,6 +3,7 @@ MODULE := engines/neverhood
MODULE_OBJS = \
background.o \
blbarchive.o \
console.o \
detection.o \
diskplayerscene.o \
entity.o \
Expand Down
16 changes: 15 additions & 1 deletion engines/neverhood/neverhood.cpp
Expand Up @@ -22,12 +22,18 @@

#include "common/file.h"
#include "common/config-manager.h"
#include "common/textconsole.h"

#include "base/plugins.h"
#include "base/version.h"

#include "graphics/cursorman.h"

#include "engines/util.h"

#include "neverhood/neverhood.h"
#include "neverhood/blbarchive.h"
#include "neverhood/console.h"
#include "neverhood/gamemodule.h"
#include "neverhood/gamevars.h"
#include "neverhood/graphics.h"
Expand Down Expand Up @@ -76,7 +82,8 @@ Common::Error NeverhoodEngine::run() {
_gameVars = new GameVars();
_screen = new Screen(this);
_res = new ResourceMan();

_console = new Console(this);

if (isDemo()) {
_res->addArchive("a.blb");
_res->addArchive("nevdemo.blb");
Expand Down Expand Up @@ -123,6 +130,7 @@ Common::Error NeverhoodEngine::run() {
delete _soundMan;
delete _audioResourceMan;

delete _console;
delete _res;
delete _screen;

Expand All @@ -140,6 +148,11 @@ void NeverhoodEngine::mainLoop() {
while (eventMan->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_KEYDOWN:
if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_d) {
// Open debugger console
_console->attach();
continue;
}
_gameModule->handleKeyDown(event.kbd.keycode);
_gameModule->handleAsciiKey(event.kbd.ascii);
break;
Expand Down Expand Up @@ -169,6 +182,7 @@ void NeverhoodEngine::mainLoop() {
_gameModule->checkRequests();
_gameModule->handleUpdate();
_gameModule->draw();
_console->onFrame();
_screen->update();
nextFrameTime = _screen->getNextFrameTime();
};
Expand Down
4 changes: 3 additions & 1 deletion engines/neverhood/neverhood.h
Expand Up @@ -48,6 +48,7 @@ class Screen;
class SoundMan;
class AudioResourceMan;
class StaticData;
class Console;
struct NPoint;

struct GameState {
Expand Down Expand Up @@ -86,7 +87,8 @@ class NeverhoodEngine : public ::Engine {
ResourceMan *_res;
GameModule *_gameModule;
StaticData *_staticData;

Console *_console;

SoundMan *_soundMan;
AudioResourceMan *_audioResourceMan;

Expand Down

0 comments on commit a14cb19

Please sign in to comment.