Skip to content

Commit

Permalink
TOLTECS: Add a debug console
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegr committed Jan 2, 2013
1 parent 3cacade commit 69da727
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 22 deletions.
79 changes: 79 additions & 0 deletions engines/toltecs/console.cpp
@@ -0,0 +1,79 @@
/* 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 "gui/debugger.h"

#include "toltecs/console.h"
//#include "toltecs/palette.h"
#include "toltecs/resource.h"
//#include "toltecs/sound.h"
#include "toltecs/toltecs.h"

namespace Toltecs {

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

Console::~Console() {
}

bool Console::Cmd_Room(int argc, const char **argv) {
if (argc < 2) {
DebugPrintf("Current room number is %d\n", _vm->_sceneResIndex);
#if 0
DebugPrintf("Calling this command with the room number changes the room\n");
DebugPrintf("WARNING: It's a bad idea to warp to rooms with this, as the room object scripts are not loaded\n");
#endif
return true;
#if 0
} else {
int roomNum = atoi(argv[1]);

// sfClearPaletteFragments
_vm->_palette->clearFragments();

// sfLoadScene
_vm->_sound->stopAll();
_vm->_res->purgeCache();
_vm->loadScene(roomNum);
#endif
}

return false;
}

bool Console::Cmd_Dump(int argc, const char **argv) {
if (argc < 2) {
DebugPrintf("Usage: dump <resource number>\n");
return true;
}

int resNum = atoi(argv[1]);
_vm->_arc->dump(resNum);
DebugPrintf("Resource %d has been dumped to disk\n", resNum);

return true;
}

} // End of namespace Toltecs
45 changes: 45 additions & 0 deletions engines/toltecs/console.h
@@ -0,0 +1,45 @@
/* 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 TOLTECS_CONSOLE_H
#define TOLTECS_CONSOLE_H

#include "gui/debugger.h"

namespace Toltecs {

class ToltecsEngine;

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

private:
ToltecsEngine *_vm;

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

} // End of namespace Toltecs
#endif
1 change: 1 addition & 0 deletions engines/toltecs/module.mk
Expand Up @@ -2,6 +2,7 @@ MODULE := engines/toltecs

MODULE_OBJS = \
animation.o \
console.o \
detection.o \
menu.o \
microtiles.o \
Expand Down
9 changes: 2 additions & 7 deletions engines/toltecs/resource.cpp
Expand Up @@ -61,16 +61,11 @@ uint32 ArchiveReader::getResourceSize(uint resIndex) {
return _offsets[resIndex + 1] - _offsets[resIndex];
}

void ArchiveReader::dump(uint resIndex, const char *prefix) {
void ArchiveReader::dump(uint resIndex) {
int32 resourceSize = getResourceSize(resIndex);
byte *data = new byte[resourceSize];

Common::String fn;

if (prefix)
fn = Common::String::format("%s_%04X.0", prefix, resIndex);
else
fn = Common::String::format("%04X.0", resIndex);
Common::String fn = Common::String::format("toltecs_res.%03d", resIndex);

openResource(resIndex);
read(data, resourceSize);
Expand Down
2 changes: 1 addition & 1 deletion engines/toltecs/resource.h
Expand Up @@ -50,7 +50,7 @@ class ArchiveReader : public Common::File {
// Returns the size of the resource
uint32 getResourceSize(uint resIndex);

void dump(uint resIndex, const char *prefix = NULL);
void dump(uint resIndex);

protected:
uint32 *_offsets;
Expand Down
21 changes: 7 additions & 14 deletions engines/toltecs/toltecs.cpp
Expand Up @@ -39,6 +39,7 @@

#include "toltecs/toltecs.h"
#include "toltecs/animation.h"
#include "toltecs/console.h"
#include "toltecs/menu.h"
#include "toltecs/movie.h"
#include "toltecs/music.h"
Expand Down Expand Up @@ -126,6 +127,7 @@ Common::Error ToltecsEngine::run() {
_menuSystem = new MenuSystem(this);

_sound = new Sound(this);
_console = new Console(this);

_cfgText = ConfMan.getBool("subtitles");
_cfgVoices = !ConfMan.getBool("speech_mute");
Expand Down Expand Up @@ -179,6 +181,7 @@ Common::Error ToltecsEngine::run() {
_music->stopSequence();
_sound->stopAll();

delete _console;
delete _arc;
delete _res;
delete _screen;
Expand Down Expand Up @@ -218,7 +221,6 @@ void ToltecsEngine::requestLoadgame(int slotNum) {
}

void ToltecsEngine::loadScene(uint resIndex) {

Resource *sceneResource = _res->load(resIndex);
byte *scene = sceneResource->data;

Expand Down Expand Up @@ -253,13 +255,10 @@ void ToltecsEngine::loadScene(uint resIndex) {

_screen->_fullRefresh = true;
_screen->_renderQueue->clear();

}

void ToltecsEngine::updateScreen() {

_sound->updateSpeech();

_screen->updateShakeScreen();

// TODO: Set quit flag
Expand Down Expand Up @@ -292,7 +291,6 @@ void ToltecsEngine::updateScreen() {
_counter02 = (currUpdateTime - prevUpdateTime) / 13;
} while (_counter02 == 0);
prevUpdateTime = currUpdateTime;

}

void ToltecsEngine::drawScreen() {
Expand All @@ -313,14 +311,14 @@ void ToltecsEngine::drawScreen() {
_screen->_guiRefresh = false;
}

_console->onFrame();
_system->updateScreen();
_system->delayMillis(10);

updateCamera();
}

void ToltecsEngine::updateInput() {

Common::Event event;
Common::EventManager *eventMan = _system->getEventManager();
while (eventMan->pollEvent(event)) {
Expand All @@ -330,6 +328,9 @@ void ToltecsEngine::updateInput() {

//debug("key: flags = %02X; keycode = %d", _keyState.flags, _keyState.keycode);

if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_d)
_console->attach();

switch (event.kbd.keycode) {
case Common::KEYCODE_F5:
showMenu(kMenuIdSave);
Expand Down Expand Up @@ -411,9 +412,7 @@ void ToltecsEngine::updateInput() {
_mouseWaitForRelease = false;
_mouseButton = 0;
}

}

}

void ToltecsEngine::setGuiHeight(int16 guiHeight) {
Expand Down Expand Up @@ -481,7 +480,6 @@ void ToltecsEngine::scrollCameraRight(int16 delta) {
}

void ToltecsEngine::updateCamera() {

if (_cameraX != _newCameraX) {
_cameraX = _newCameraX;
_screen->_fullRefresh = true;
Expand All @@ -495,11 +493,9 @@ void ToltecsEngine::updateCamera() {
}

//debug(0, "ToltecsEngine::updateCamera() _cameraX = %d; _cameraY = %d", _cameraX, _cameraY);

}

void ToltecsEngine::talk(int16 slotIndex, int16 slotOffset) {

byte *scanData = _script->getSlotData(slotIndex) + slotOffset;

while (*scanData < 0xF0) {
Expand Down Expand Up @@ -529,11 +525,9 @@ void ToltecsEngine::talk(int16 slotIndex, int16 slotOffset) {
} else {
_screen->updateTalkText(slotIndex, slotOffset);
}

}

void ToltecsEngine::walk(byte *walkData) {

int16 xdelta, ydelta, v8, v10, v11;
int16 xstep, ystep;
ScriptWalk walkInfo;
Expand Down Expand Up @@ -616,7 +610,6 @@ void ToltecsEngine::walk(byte *walkData) {
WRITE_LE_UINT16(walkData + 14, walkInfo.xerror);
WRITE_LE_UINT16(walkData + 16, walkInfo.mulValue);
WRITE_LE_UINT16(walkData + 18, walkInfo.scaling);

}

int16 ToltecsEngine::findRectAtPoint(byte *rectData, int16 x, int16 y, int16 index, int16 itemSize,
Expand Down
2 changes: 2 additions & 0 deletions engines/toltecs/toltecs.h
Expand Up @@ -42,6 +42,7 @@ struct ToltecsGameDescription;

class AnimationPlayer;
class ArchiveReader;
class Console;
class Input;
class MenuSystem;
class MoviePlayer;
Expand Down Expand Up @@ -144,6 +145,7 @@ class ToltecsEngine : public ::Engine {

AnimationPlayer *_anim;
ArchiveReader *_arc;
Console *_console;
Input *_input;
MenuSystem *_menuSystem;
MoviePlayer *_moviePlayer;
Expand Down

0 comments on commit 69da727

Please sign in to comment.