Skip to content

Commit

Permalink
PRINCE: major code cleanup, flag handling rewritten in script
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Zbróg committed Nov 5, 2013
1 parent 4722d0e commit d6a76d9
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 174 deletions.
178 changes: 90 additions & 88 deletions engines/prince/debugger.cpp
Expand Up @@ -26,130 +26,132 @@
namespace Prince {

Debugger::Debugger(PrinceEngine *vm) : GUI::Debugger(), _vm(vm) {
DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit));
DCmd_Register("level", WRAP_METHOD(Debugger, Cmd_DebugLevel));
DCmd_Register("setflag", WRAP_METHOD(Debugger, Cmd_SetFlag));
DCmd_Register("getflag", WRAP_METHOD(Debugger, Cmd_GetFlag));
DCmd_Register("clearflag", WRAP_METHOD(Debugger, Cmd_ClearFlag));
DCmd_Register("viewflc", WRAP_METHOD(Debugger, Cmd_ViewFlc));
DCmd_Register("initroom", WRAP_METHOD(Debugger, Cmd_InitRoom));
DCmd_Register("changecursor", WRAP_METHOD(Debugger, Cmd_ChangeCursor));
DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit));
DCmd_Register("level", WRAP_METHOD(Debugger, Cmd_DebugLevel));
DCmd_Register("setflag", WRAP_METHOD(Debugger, Cmd_SetFlag));
DCmd_Register("getflag", WRAP_METHOD(Debugger, Cmd_GetFlag));
DCmd_Register("clearflag", WRAP_METHOD(Debugger, Cmd_ClearFlag));
DCmd_Register("viewflc", WRAP_METHOD(Debugger, Cmd_ViewFlc));
DCmd_Register("initroom", WRAP_METHOD(Debugger, Cmd_InitRoom));
DCmd_Register("changecursor", WRAP_METHOD(Debugger, Cmd_ChangeCursor));
}

static int strToInt(const char *s) {
if (!*s)
// No string at all
return 0;
else if (toupper(s[strlen(s) - 1]) != 'H')
// Standard decimal string
return atoi(s);

// Hexadecimal string
uint tmp = 0;
int read = sscanf(s, "%xh", &tmp);
if (read < 1)
error("strToInt failed on string \"%s\"", s);
return (int)tmp;
if (!*s)
// No string at all
return 0;
else if (toupper(s[strlen(s) - 1]) != 'H')
// Standard decimal string
return atoi(s);

// Hexadecimal string
uint tmp = 0;
int read = sscanf(s, "%xh", &tmp);
if (read < 1)
error("strToInt failed on string \"%s\"", s);
return (int)tmp;
}

bool Debugger::Cmd_DebugLevel(int argc, const char **argv) {
if (argc == 1) {
DebugPrintf("Debugging is currently set at level %d\n", gDebugLevel);
} else { // set level
gDebugLevel = atoi(argv[1]);
if (0 <= gDebugLevel && gDebugLevel < 11) {
DebugPrintf("Debug level set to level %d\n", gDebugLevel);
} else if (gDebugLevel < 0) {
DebugPrintf("Debugging is now disabled\n");
} else
DebugPrintf("Not a valid debug level (0 - 10)\n");
}

return true;
if (argc == 1) {
DebugPrintf("Debugging is currently set at level %d\n", gDebugLevel);
} else { // set level
gDebugLevel = atoi(argv[1]);
if (0 <= gDebugLevel && gDebugLevel < 11) {
DebugPrintf("Debug level set to level %d\n", gDebugLevel);
} else if (gDebugLevel < 0) {
DebugPrintf("Debugging is now disabled\n");
} else
DebugPrintf("Not a valid debug level (0 - 10)\n");
}

return true;
}

/*
* This command sets a flag
*/
bool Debugger::Cmd_SetFlag(int argc, const char **argv) {
// Check for a flag to set
if (argc != 2) {
DebugPrintf("Usage: %s <flag number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
//g_globals->setFlag(flagNum);
return true;
// Check for a flag to set
if (argc != 2) {
DebugPrintf("Usage: %s <flag number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
//g_globals->setFlag(flagNum);
return true;
}

/*
* This command gets the value of a flag
*/
bool Debugger::Cmd_GetFlag(int argc, const char **argv) {
// Check for an flag to display
if (argc != 2) {
DebugPrintf("Usage: %s <flag number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
//DebugPrintf("Value: %d\n", g_globals->getFlag(flagNum));
return true;
// Check for an flag to display
if (argc != 2) {
DebugPrintf("Usage: %s <flag number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
//DebugPrintf("Value: %d\n", g_globals->getFlag(flagNum));
return true;
}

/*
* This command clears a flag
*/
bool Debugger::Cmd_ClearFlag(int argc, const char **argv) {
// Check for a flag to clear
if (argc != 2) {
DebugPrintf("Usage: %s <flag number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
//g_globals->clearFlag(flagNum);
return true;
// Check for a flag to clear
if (argc != 2) {
DebugPrintf("Usage: %s <flag number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
//g_globals->clearFlag(flagNum);
return true;
}

/*
* This command starts new flc anim
*/
bool Debugger::Cmd_ViewFlc(int argc, const char **argv) {
// Check for a flag to clear
if (argc != 2) {
DebugPrintf("Usage: %s <anim number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
_vm->loadAnim(flagNum, false);
return true;
// Check for a flag to clear
if (argc != 2) {
DebugPrintf("Usage: %s <anim number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
_vm->loadAnim(flagNum, false);
return true;
}

bool Debugger::Cmd_InitRoom(int argc, const char **argv) {
// Check for a flag to clear
if (argc != 2) {
DebugPrintf("Usage: %s <anim number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
_vm->loadLocation(flagNum);
return true;
// Check for a flag to clear
if (argc != 2) {
DebugPrintf("Usage: %s <anim number>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
_vm->loadLocation(flagNum);
return true;
}

bool Debugger::Cmd_ChangeCursor(int argc, const char **argv) {
// Check for a flag to clear
if (argc != 2) {
DebugPrintf("Usage: %s <curId>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
_vm->changeCursor(flagNum);
return true;
// Check for a flag to clear
if (argc != 2) {
DebugPrintf("Usage: %s <curId>\n", argv[0]);
return true;
}

int flagNum = strToInt(argv[1]);
_vm->changeCursor(flagNum);
return true;
}

}

/* vim: set tabstop=4 noexpandtab: */
3 changes: 2 additions & 1 deletion engines/prince/debugger.h
Expand Up @@ -47,7 +47,8 @@ class Debugger : public GUI::Debugger {
PrinceEngine *_vm;
};


}

#endif

/* vim: set tabstop=4 noexpandtab: */
2 changes: 1 addition & 1 deletion engines/prince/prince.cpp
Expand Up @@ -357,7 +357,7 @@ void PrinceEngine::keyHandler(Common::Event event) {
scrollCameraRight(32);
break;
case Common::KEYCODE_ESCAPE:
_script->setFlag(Flags::ESCAPED2, 1);
_script->setFlagValue(Flags::ESCAPED2, 1);
break;
}
}
Expand Down

0 comments on commit d6a76d9

Please sign in to comment.