Added experimental debug feature: variables influencing the rendering that can be set via console using the 'set' command. The implementation is still partial. Leveraging on this, the engine can now selectively display the current background mask instead of the background itself.

svn-id: r30808
This commit is contained in:
Nicola Mettifogo 2008-02-06 14:05:08 +00:00
parent 715e33d63d
commit 246fbfd1e4
5 changed files with 103 additions and 3 deletions

View File

@ -45,6 +45,7 @@ Debugger::Debugger(Parallaction *vm)
DCmd_Register("localflags", WRAP_METHOD(Debugger, Cmd_LocalFlags));
DCmd_Register("locations", WRAP_METHOD(Debugger, Cmd_Locations));
DCmd_Register("gfxobjects", WRAP_METHOD(Debugger, Cmd_GfxObjects));
DCmd_Register("set", WRAP_METHOD(Debugger, Cmd_Set));
}
@ -204,5 +205,15 @@ bool Debugger::Cmd_GfxObjects(int argc, const char **argv) {
return true;
}
bool Debugger::Cmd_Set(int argc, const char** argv) {
if (argc < 3) {
DebugPrintf("set <var name> <value>\n");
} else {
_vm->_gfx->setVar(Common::String(argv[1]), atoi(argv[2]));
}
return true;
}
} // namespace Parallaction

View File

@ -28,6 +28,8 @@ protected:
bool Cmd_GlobalFlags(int argc, const char **argv);
bool Cmd_Locations(int argc, const char **argv);
bool Cmd_GfxObjects(int argc, const char **argv);
bool Cmd_GfxFeature(int argc, const char** argv);
bool Cmd_Set(int argc, const char** argv);
};
} // End of namespace Parallaction

View File

@ -32,6 +32,40 @@
namespace Parallaction {
typedef Common::HashMap<Common::String, int32, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> VarMap;
VarMap _vars;
void Gfx::registerVar(const Common::String &name, int32 initialValue) {
if (_vars.contains(name)) {
warning("Variable '%s' already registered, ignoring initial value.\n", name.c_str());
} else {
_vars.setVal(name, initialValue);
}
}
void Gfx::setVar(const Common::String &name, int32 value) {
if (!_vars.contains(name)) {
warning("Variable '%s' doesn't exist, skipping assignment.\n", name.c_str());
} else {
_vars.setVal(name, value);
}
}
int32 Gfx::getVar(const Common::String &name) {
int32 v = 0;
if (!_vars.contains(name)) {
warning("Variable '%s' doesn't exist, returning default value.\n", name.c_str());
} else {
v = _vars.getVal(name);
}
return v;
}
#define LABEL_TRANSPARENT_COLOR 0xFF
#define BALLOON_TRANSPARENT_COLOR 2
@ -348,14 +382,51 @@ void Gfx::clearScreen() {
g_system->clearScreen();
}
void Gfx::beginFrame() {
int32 oldBackgroundMode = _varBackgroundMode;
_varBackgroundMode = getVar("background_mode");
if (oldBackgroundMode != _varBackgroundMode) {
switch (_varBackgroundMode) {
case 1:
_bitmapMask.free();
break;
case 2:
_bitmapMask.create(_backgroundInfo.width, _backgroundInfo.height, 1);
byte *data = (byte*)_bitmapMask.pixels;
for (uint y = 0; y < _bitmapMask.h; y++) {
for (uint x = 0; x < _bitmapMask.w; x++) {
*data++ = _backgroundInfo.mask.getValue(x, y);
}
}
break;
}
}
}
void Gfx::updateScreen() {
// background may not cover the whole screen, so adjust bulk update size
uint w = MIN(_vm->_screenWidth, (int32)_backgroundInfo.width);
uint h = MIN(_vm->_screenHeight, (int32)_backgroundInfo.height);
// TODO: add displacement to source to handle scrolling in BRA
g_system->copyRectToScreen((const byte*)_backgroundInfo.bg.pixels, _backgroundInfo.bg.pitch, _backgroundInfo.x, _backgroundInfo.y, w, h);
byte *backgroundData;
uint16 backgroundPitch;
switch (_varBackgroundMode) {
case 1:
backgroundData = (byte*)_backgroundInfo.bg.pixels;
backgroundPitch = _backgroundInfo.bg.pitch;
break;
case 2:
backgroundData = (byte*)_bitmapMask.pixels;
backgroundPitch = _bitmapMask.pitch;
break;
}
g_system->copyRectToScreen(backgroundData, backgroundPitch, _backgroundInfo.x, _backgroundInfo.y, w, h);
// TODO: transform objects coordinates to be drawn with scrolling
Graphics::Surface *surf = g_system->lockScreen();
@ -785,6 +856,9 @@ Gfx::Gfx(Parallaction* vm) :
_font = NULL;
registerVar("background_mode", 1);
_varBackgroundMode = 1;
return;
}
@ -1035,5 +1109,4 @@ void Gfx::setBackground(uint type, const char* name, const char* mask, const cha
}
} // namespace Parallaction

View File

@ -512,6 +512,11 @@ public:
Gfx(Parallaction* vm);
virtual ~Gfx();
void beginFrame();
void registerVar(const Common::String &name, int32 initialValue);
void setVar(const Common::String &name, int32 value);
int32 getVar(const Common::String &name);
void clearScreen();
void updateScreen();
@ -530,6 +535,10 @@ protected:
Common::Point _hbCirclePos;
int _hbCircleRadius;
// frame data stored in programmable variables
int32 _varBackgroundMode;
Graphics::Surface _bitmapMask;
protected:
static int16 _dialogueBalloonX[5];
@ -594,3 +603,4 @@ protected:

View File

@ -253,12 +253,16 @@ void Parallaction::runGame() {
changeLocation(_location._name);
}
_gfx->beginFrame();
if (_inputMode == kInputModeGame) {
runScripts();
walk();
drawAnimations();
}
// change this to endFrame?
updateView();
}