diff options
-rw-r--r-- | saga/actionmap.cpp | 5 | ||||
-rw-r--r-- | saga/actor.cpp | 108 | ||||
-rw-r--r-- | saga/actor.h | 8 | ||||
-rw-r--r-- | saga/animation.cpp | 21 | ||||
-rw-r--r-- | saga/animation.h | 4 | ||||
-rw-r--r-- | saga/console.cpp | 525 | ||||
-rw-r--r-- | saga/console.h | 92 | ||||
-rw-r--r-- | saga/cvar.cpp | 483 | ||||
-rw-r--r-- | saga/cvar.h | 85 | ||||
-rw-r--r-- | saga/cvar_mod.h | 88 | ||||
-rw-r--r-- | saga/events.cpp | 14 | ||||
-rw-r--r-- | saga/expr.cpp | 390 | ||||
-rw-r--r-- | saga/expr.h | 37 | ||||
-rw-r--r-- | saga/game.cpp | 20 | ||||
-rw-r--r-- | saga/ihnm_introproc.cpp | 1 | ||||
-rw-r--r-- | saga/input.cpp | 67 | ||||
-rw-r--r-- | saga/interface.cpp | 3 | ||||
-rw-r--r-- | saga/ite_introproc.cpp | 3 | ||||
-rw-r--r-- | saga/module.mk | 2 | ||||
-rw-r--r-- | saga/objectmap.cpp | 7 | ||||
-rw-r--r-- | saga/render.cpp | 9 | ||||
-rw-r--r-- | saga/render.h | 1 | ||||
-rw-r--r-- | saga/saga.cpp | 47 | ||||
-rw-r--r-- | saga/scene.cpp | 83 | ||||
-rw-r--r-- | saga/scene.h | 8 | ||||
-rw-r--r-- | saga/script.cpp | 45 | ||||
-rw-r--r-- | saga/script.h | 7 | ||||
-rw-r--r-- | saga/sfuncs.cpp | 20 | ||||
-rw-r--r-- | saga/sthread.cpp | 14 |
29 files changed, 313 insertions, 1884 deletions
diff --git a/saga/actionmap.cpp b/saga/actionmap.cpp index c5b4e945eb..e6d467dce9 100644 --- a/saga/actionmap.cpp +++ b/saga/actionmap.cpp @@ -24,7 +24,6 @@ /* Action map module */ #include "saga/saga.h" -#include "saga/cvar_mod.h" #include "saga/gfx.h" #include "saga/console.h" @@ -182,10 +181,10 @@ int ActionMap::draw(SURFACE *ds, int color) { } void ActionMap::info(void) { - _vm->_console->print("%d exits loaded.\n", _nExits); + _vm->_console->DebugPrintf("%d exits loaded.\n\n", _nExits); for (int i = 0; i < _nExits; i++) { - _vm->_console->print ("Action %d: Exit to: %d", i, _exitsTbl[i].exitScene); + _vm->_console->DebugPrintf("Action %d: Exit to: %d\n", i, _exitsTbl[i].exitScene); } } diff --git a/saga/actor.cpp b/saga/actor.cpp index f1337a1cb6..4e1d9e2d63 100644 --- a/saga/actor.cpp +++ b/saga/actor.cpp @@ -26,7 +26,6 @@ #include "saga/gfx.h" #include "saga/game_mod.h" -#include "saga/cvar_mod.h" #include "saga/console.h" #include "saga/rscfile_mod.h" #include "saga/script.h" @@ -44,12 +43,6 @@ namespace Saga { static int zCompare(const void *elem1, const void *elem2); -static void CF_actor_add(int argc, char *argv[], void *refCon); -static void CF_actor_del(int argc, char *argv[], void *refCon); -static void CF_actor_move(int argc, char *argv[], void *refCon); -static void CF_actor_moverel(int argc, char *argv[], void *refCon); -static void CF_actor_seto(int argc, char *argv[], void *refCon); -static void CF_actor_setact(int argc, char *argv[], void *refCon); ACTIONTIMES ActionTDeltas[] = { { ACTION_IDLE, 80 }, @@ -57,17 +50,6 @@ ACTIONTIMES ActionTDeltas[] = { { ACTION_SPEAK, 200 } }; -int Actor::reg() { - CVAR_RegisterFunc(CF_actor_add, "actor_add", "<Actor id> <lx> <ly>", CVAR_NONE, 3, 3, this); - CVAR_RegisterFunc(CF_actor_del, "actor_del", "<Actor id>", CVAR_NONE, 1, 1, this); - CVAR_RegisterFunc(CF_actor_move, "actor_move", "<Actor id> <lx> <ly>", CVAR_NONE, 3, 3, this); - CVAR_RegisterFunc(CF_actor_moverel, "actor_moverel", "<Actor id> <lx> <ly>", CVAR_NONE, 3, 3, this); - CVAR_RegisterFunc(CF_actor_seto, "actor_seto", "<Actor id> <Orientation>", CVAR_NONE, 2, 2, this); - CVAR_RegisterFunc(CF_actor_setact, "actor_setact", "<Actor id> <Action #>", CVAR_NONE, 2, 2, this); - - return SUCCESS; -} - Actor::Actor(SagaEngine *vm) : _vm(vm), _initialized(false) { int i; @@ -1028,116 +1010,86 @@ int Actor::StoA(Point *actor, const Point screen) { return SUCCESS; } -static void CF_actor_add(int argc, char *argv[], void *refCon) { +void Actor::CF_actor_add(int argc, const char **argv) { ACTOR actor; - if (argc < 3) - return; - - actor.id = (uint16) atoi(argv[0]); + actor.id = (uint16) atoi(argv[1]); - actor.a_pt.x = atoi(argv[1]); - actor.a_pt.y = atoi(argv[2]); + actor.a_pt.x = atoi(argv[2]); + actor.a_pt.y = atoi(argv[3]); - ((Actor *)refCon)->addActor(&actor); - - return; + addActor(&actor); } -static void CF_actor_del(int argc, char *argv[], void *refCon) { +void Actor::CF_actor_del(int argc, const char **argv) { int id; - if (argc < 0) - return; - - id = atoi(argv[0]); + id = atoi(argv[1]); - ((Actor *)refCon)->deleteActor(id); - - return; + deleteActor(id); } -static void CF_actor_move(int argc, char *argv[], void *refCon) { +void Actor::CF_actor_move(int argc, const char **argv) { int id; Point move_pt; - if (argc < 2) - return; - - id = atoi(argv[0]); + id = atoi(argv[1]); - move_pt.x = atoi(argv[1]); - move_pt.y = atoi(argv[2]); + move_pt.x = atoi(argv[2]); + move_pt.y = atoi(argv[3]); - ((Actor *)refCon)->move(id, &move_pt); - - return; + move(id, &move_pt); } -static void CF_actor_moverel(int argc, char *argv[], void *refCon) { +void Actor::CF_actor_moverel(int argc, const char **argv) { int id; Point move_pt; - if (argc < 3) - return; - - id = atoi(argv[0]); + id = atoi(argv[1]); - move_pt.x = atoi(argv[1]); - move_pt.y = atoi(argv[2]); + move_pt.x = atoi(argv[2]); + move_pt.y = atoi(argv[3]); - ((Actor *)refCon)->moveRelative(id, &move_pt); - - return; + moveRelative(id, &move_pt); } -static void CF_actor_seto(int argc, char *argv[], void *refCon) { +void Actor::CF_actor_seto(int argc, const char **argv) { int id; int orient; - if (argc < 2) - return; - - id = atoi(argv[0]); - orient = atoi(argv[1]); + id = atoi(argv[1]); + orient = atoi(argv[2]); - ((Actor *)refCon)->setOrientation(id, orient); - - return; + setOrientation(id, orient); } -static void CF_actor_setact(int argc, char *argv[], void *refCon) { +void Actor::CF_actor_setact(int argc, const char **argv) { int index = 0; int action_n = 0; ACTOR *actor; - if (argc < 2) - return; - - index = atoi(argv[0]); - action_n = atoi(argv[1]); + index = atoi(argv[1]); + action_n = atoi(argv[2]); - actor = ((Actor *)refCon)->lookupActor(index); + actor = lookupActor(index); if (actor == NULL) { - _vm->_console->print("Invalid actor index."); - + _vm->_console->DebugPrintf("Invalid actor index.\n"); return; } if ((action_n < 0) || (action_n >= actor->action_ct)) { - _vm->_console->print("Invalid action number."); - + _vm->_console->DebugPrintf("Invalid action number.\n"); return; } - _vm->_console->print("Action frame counts: %d %d %d %d.", + _vm->_console->DebugPrintf("Action frame counts: %d %d %d %d.\n", actor->act_tbl[action_n].dir[0].frame_count, actor->act_tbl[action_n].dir[1].frame_count, actor->act_tbl[action_n].dir[2].frame_count, actor->act_tbl[action_n].dir[3].frame_count); - ((Actor *)refCon)->setAction(index, action_n, ACTION_LOOP); + setAction(index, action_n, ACTION_LOOP); } } // End of namespace Saga diff --git a/saga/actor.h b/saga/actor.h index 6a24646603..a1a6b7cafc 100644 --- a/saga/actor.h +++ b/saga/actor.h @@ -186,10 +186,16 @@ struct ACTIONTIMES { class Actor { public: - int reg(); Actor(SagaEngine *vm); ~Actor(); + void CF_actor_add(int argc, const char **argv); + void CF_actor_del(int argc, const char **argv); + void CF_actor_move(int argc, const char **argv); + void CF_actor_moverel(int argc, const char **argv); + void CF_actor_seto(int argc, const char **argv); + void CF_actor_setact(int argc, const char **argv); + int direct(int msec); int create(int actor_id, int x, int y); diff --git a/saga/animation.cpp b/saga/animation.cpp index 7dde34908b..7768ad2294 100644 --- a/saga/animation.cpp +++ b/saga/animation.cpp @@ -25,7 +25,6 @@ #include "saga/saga.h" #include "saga/gfx.h" -#include "saga/cvar_mod.h" #include "saga/console.h" #include "saga/game_mod.h" #include "saga/events.h" @@ -35,13 +34,6 @@ namespace Saga { -static void CF_anim_info(int argc, char *argv[], void *refCon); - -int Anim::reg() { - CVAR_RegisterFunc(CF_anim_info, "anim_info", NULL, CVAR_NONE, 0, 0, this); - return SUCCESS; -} - Anim::Anim(SagaEngine *vm) : _vm(vm) { int i; @@ -915,29 +907,22 @@ int Anim::getFrameOffset(const byte *resdata, size_t resdata_len, uint16 find_fr return SUCCESS; } -void Anim::animInfo(int argc, char *argv[]) { +void Anim::animInfo() { uint16 anim_ct; uint16 i; uint16 idx; - (void)(argc); - (void)(argv); - anim_ct = _anim_count; - _vm->_console->print("There are %d animations loaded:", anim_ct); + _vm->_console->DebugPrintf("There are %d animations loaded:\n", anim_ct); for (idx = 0, i = 0; i < anim_ct; idx++, i++) { while (_anim_tbl[idx] == NULL) { idx++; } - _vm->_console->print("%02d: Frames: %u Flags: %u", i, _anim_tbl[idx]->n_frames, _anim_tbl[idx]->flags); + _vm->_console->DebugPrintf("%02d: Frames: %u Flags: %u\n", i, _anim_tbl[idx]->n_frames, _anim_tbl[idx]->flags); } } -static void CF_anim_info(int argc, char *argv[], void *refCon) { - ((Anim *)refCon)->animInfo(argc, argv); -} - } // End of namespace Saga diff --git a/saga/animation.h b/saga/animation.h index d6a2627303..4f41d8c75a 100644 --- a/saga/animation.h +++ b/saga/animation.h @@ -94,9 +94,9 @@ enum ANIM_FLAGS { class Anim { public: - int reg(void); Anim(SagaEngine *vm); ~Anim(void); + int load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id_p); int freeId(uint16 anim_id); int play(uint16 anim_id, int vector_time); @@ -105,7 +105,7 @@ public: int clearFlag(uint16 anim_id, uint16 flag); int setFrameTime(uint16 anim_id, int time); int reset(void); - void animInfo(int argc, char *argv[]); + void animInfo(void); private: int getNumFrames(const byte *anim_resource, size_t anim_resource_len, uint16 *n_frames); diff --git a/saga/console.cpp b/saga/console.cpp index a22e9aa1ea..d16ad84972 100644 --- a/saga/console.cpp +++ b/saga/console.cpp @@ -24,442 +24,211 @@ // Console module #include "saga/saga.h" -#include "saga/gfx.h" -#include "saga/font.h" -#include "saga/cvar_mod.h" -#include "saga/events.h" +#include "saga/actor.h" +#include "saga/animation.h" +#include "saga/scene.h" +#include "saga/script.h" #include "saga/console.h" -namespace Saga { - -int Console::reg() { - CVAR_Register_I(&_resize, "con_h", NULL, CVAR_NONE, 12, CON_DEFAULTPOS); - CVAR_Register_I(&_droptime, "con_droptime", NULL, CVAR_NONE, 0, 5000); - CVAR_Register_I(&_lineMax, "con_lines", NULL, CVAR_NONE, 5, 5000); - return SUCCESS; -} +#include "common/debugger.cpp" -Console::Console(SagaEngine *vm) : _vm(vm) { - memset(&_scrollback, 0, sizeof(_scrollback)); - memset(&_history, 0, sizeof(_history)); - - _resize = CON_DEFAULTPOS; - _droptime = CON_DROPTIME; - - _active = false; - _yMax = CON_DEFAULTPOS; - _lineMax = CON_DEFAULTLINES; - _histMax = CON_DEFAULTCMDS; - _histPos = 0; - _linePos = 0; - _yPos = 0; - _prompt = NULL; - _promptW = 0; - *_inputBuf = 0; - _inputPos = 0; -} +namespace Saga { -Console::~Console() { - debug(0, "~Console(): Deleting console scrollback and command history."); +Console::Console(SagaEngine *vm) : Common::Debugger<Console>() { + _vm = vm; - deleteScroll(&_scrollback); - deleteScroll(&_history); -} + DCmd_Register("continue", &Console::Cmd_Exit); + DCmd_Register("exit", &Console::Cmd_Exit); + DCmd_Register("quit", &Console::Cmd_Exit); + DCmd_Register("help", &Console::Cmd_Help); -int Console::activate() { - EVENT con_event; + // CVAR_Register_I(&_soundEnabled, "sound", NULL, CVAR_CFG, 0, 1); + // CVAR_Register_I(&_musicEnabled, "music", NULL, CVAR_CFG, 0, 1); - if (_active) { - return FAILURE; - } + // Actor commands + DCmd_Register("actor_add", &Console::Cmd_ActorAdd); + DCmd_Register("actor_del", &Console::Cmd_ActorDel); + DCmd_Register("actor_move", &Console::Cmd_ActorMove); + DCmd_Register("actor_moverel", &Console::Cmd_ActorMoveRel); + DCmd_Register("actor_seto", &Console::Cmd_ActorSetO); + DCmd_Register("actor_setact", &Console::Cmd_ActorSetAct); - con_event.type = CONTINUOUS_EVENT; - con_event.code = CONSOLE_EVENT | NODESTROY; - con_event.op = EVENT_ACTIVATE; - con_event.time = 0; - con_event.duration = _droptime; + // Animation commands + DCmd_Register("anim_info", &Console::Cmd_AnimInfo); - _vm->_events->queue(&con_event); + // Game stuff - _active = true; +#if 0 + // Register "g_language" cfg cvar + strncpy(GameModule.game_language, "us", MAXPATH); - return SUCCESS; -} + CVAR_Register_S(GameModule.game_language, "g_language", NULL, CVAR_CFG, GAME_LANGSTR_LIMIT); -int Console::deactivate() { - EVENT con_event; + // Register "g_skipintro" cfg cvar + CVAR_Register_I(&GameModule.g_skipintro, "g_skipintro", NULL, CVAR_CFG, 0, 1); +#endif - if (!_active) { - return FAILURE; - } + // Scene commands + DCmd_Register("scene_change", &Console::Cmd_SceneChange); + DCmd_Register("scene_info", &Console::Cmd_SceneInfo); + DCmd_Register("action_info", &Console::Cmd_ActionInfo); + DCmd_Register("object_info", &Console::Cmd_ObjectInfo); + // CVAR_Register_I(&_sceneNumber, "scene", NULL, CVAR_READONLY, 0, 0); - con_event.type = CONTINUOUS_EVENT; - con_event.code = CONSOLE_EVENT | NODESTROY; - con_event.op = EVENT_DEACTIVATE; - con_event.time = 0; - con_event.duration = _droptime; - - _vm->_events->queue(&con_event); - - return SUCCESS; + // Script commands + DCmd_Register("script_info", &Console::Cmd_ScriptInfo); + DCmd_Register("script_exec", &Console::Cmd_ScriptExec); + DCmd_Register("script_togglestep", &Console::Cmd_ScriptToggleStep); +// CVAR_RegisterFunc(CF_script_info, "script_info", NULL, CVAR_NONE, 0, 0, this); +// CVAR_RegisterFunc(CF_script_exec, "script_exec", "<Script number>", CVAR_NONE, 1, 1, this); +// CVAR_RegisterFunc(CF_script_togglestep, "script_togglestep", NULL, CVAR_NONE, 0, 0, this); } -bool Console::isActive(void) { - return _active; +Console::~Console() { } -// Responsible for processing character input to the console and maintaining -// the console input buffer. -// Input buffer is processed by EXPR_Parse on enter. -// High ASCII characters are ignored. -int Console::type(int in_char) { - int input_pos = _inputPos; - const char *expr; - int expr_len; - int result; - //char *lvalue; - - char *rvalue = NULL; - CVAR_P con_cvar = NULL; - - const char *expr_err; - const char *err_str; - - if (_yPos != _yMax) { - // Ignore keypress until console fully down - return SUCCESS; - } - - if ((in_char > 127) || (!in_char)) { - // Ignore non-ascii codes - return SUCCESS; - } - - switch (in_char) { - case '\r': - expr = _inputBuf; - _vm->_console->print("> %s", _inputBuf); - expr_len = strlen(_inputBuf); - result = EXPR_Parse(&expr, &expr_len, &con_cvar, &rvalue); - _vm->_console->addLine(&_history, _histMax, _inputBuf); - memset(_inputBuf, 0, CON_INPUTBUF_LEN); - _inputPos = 0; - _histPos = 0; - if (result != SUCCESS) { - EXPR_GetError(&expr_err); - _vm->_console->print("Parse error: %s", expr_err); - break; - } - - if (rvalue == NULL) { - CVAR_Print(con_cvar); - break; - } - - if (CVAR_IsFunc(con_cvar)) { - CVAR_Exec(con_cvar, rvalue); - } else if (CVAR_SetValue(con_cvar, rvalue) != SUCCESS) { - CVAR_GetError(&err_str); - _vm->_console->print("Illegal assignment: %s.", err_str); - } - break; - case '\b': - _inputBuf[input_pos] = 0; - if (input_pos > 0) { - _inputPos--; - _inputBuf[_inputPos] = 0; - } - break; - default: - if (input_pos < CON_INPUTBUF_LEN) { - _inputBuf[input_pos] = (char)in_char; - _inputPos++; - } - break; - } - - if (rvalue) - free(rvalue); - - return SUCCESS; +void Console::preEnter() { } -int Console::draw(SURFACE *ds) { - int line_y; - CONSOLE_LINE *walk_ptr; - CONSOLE_LINE *start_ptr; - int txt_fgcolor; - int txt_shcolor; - Rect fill_rect; - int i; - - if (!_active) { - return FAILURE; - } - - if (_resize != _yMax) { - _yMax = _resize; - _yPos = _resize; - } - - fill_rect.top = 0; - fill_rect.left = 0; - fill_rect.bottom = _yPos + 1; - fill_rect.right = ds->w; - - drawRect(ds, &fill_rect, _vm->_gfx->matchColor(CONSOLE_BGCOLOR)); - txt_fgcolor = _vm->_gfx->matchColor(CONSOLE_TXTCOLOR); - txt_shcolor = _vm->_gfx->matchColor(CONSOLE_TXTSHADOW); - - _vm->_font->draw(SMALL_FONT_ID, ds, ">", 1, 2, _yPos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW); - _vm->_font->draw(SMALL_FONT_ID, ds, _inputBuf, strlen(_inputBuf), - 10, _yPos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW); - - line_y = _yPos - (CON_INPUT_H + CON_LINE_H); - start_ptr = _scrollback.head; - - for (i = 0; i < _linePos; i++) { - if (start_ptr->next) { - start_ptr = start_ptr->next; - } else { - break; - } - } - - for (walk_ptr = start_ptr; walk_ptr; walk_ptr = walk_ptr->next) { - _vm->_font->draw(SMALL_FONT_ID, ds, walk_ptr->str_p, walk_ptr->str_len, 2, line_y, txt_fgcolor, txt_shcolor, FONT_SHADOW); - line_y -= CON_LINE_H; - if (line_y < -CON_LINE_H) - break; - } - - return SUCCESS; +void Console::postEnter() { } -int Console::print(const char *fmt_str, ...) { - char vsstr_p[CON_PRINTFLIMIT + 1]; - va_list argptr; - int ret_val; - - va_start(argptr, fmt_str); - ret_val = vsprintf(vsstr_p, fmt_str, argptr); - _vm->_console->addLine(&_scrollback, _lineMax, vsstr_p); - debug(0, vsstr_p); - va_end(argptr); - _linePos = 0; - - return ret_val; +bool Console::Cmd_Exit(int argc, const char **argv) { + _detach_now = true; + return false; } -int Console::cmdUp() { - CONSOLE_LINE *start_ptr = _history.head; - int i; +bool Console::Cmd_Help(int argc, const char **argv) { + // console normally has 39 line width + // wrap around nicely + int width = 0, size, i; - if (!start_ptr) { - return SUCCESS; - } + DebugPrintf("Commands are:\n"); + for (i = 0 ; i < _dcmd_count ; i++) { + size = strlen(_dcmds[i].name) + 1; - if (_histPos < _history.lines) { - _histPos++; - } + if ((width + size) >= 39) { + DebugPrintf("\n"); + width = size; + } else + width += size; - for (i = 1; (i < _histPos); i++) { - if (start_ptr->next) { - start_ptr = start_ptr->next; - } else { - break; - } + DebugPrintf("%s ", _dcmds[i].name); } - memset(_inputBuf, 0, CON_INPUTBUF_LEN); - strcpy(_inputBuf, start_ptr->str_p); - _inputPos = start_ptr->str_len - 1; - - debug(0, "History pos: %d/%d", _histPos, _history.lines); + width = 0; - return SUCCESS; -} + DebugPrintf("\n\nVariables are:\n"); + for (i = 0 ; i < _dvar_count ; i++) { + size = strlen(_dvars[i].name) + 1; -int Console::cmdDown(void) { - CONSOLE_LINE *start_ptr = _history.head; - int i; - - if (_histPos == 1) { - debug(0, "Erased input buffer."); - memset(_inputBuf, 0, CON_INPUTBUF_LEN); - _inputPos = 0; - _histPos--; - return SUCCESS; - } else if (_histPos) { - _histPos--; - } else { - return SUCCESS; - } + if ((width + size) >= 39) { + DebugPrintf("\n"); + width = size; + } else + width += size; - for (i = 1; i < _histPos; i++) { - if (start_ptr->next) { - start_ptr = start_ptr->next; - } else { - break; - } + DebugPrintf("%s ", _dvars[i].name); } - memset(_inputBuf, 0, CON_INPUTBUF_LEN); - strcpy(_inputBuf, start_ptr->str_p); - _inputPos = start_ptr->str_len - 1; - - debug(0, "History pos: %d/%d", _histPos, _history.lines); + DebugPrintf("\n"); - return SUCCESS; + return true; } -int Console::pageUp() { - int n_lines; - n_lines = (_yMax - CON_INPUT_H) / CON_LINE_H; - - if (_linePos < (_scrollback.lines - n_lines)) { - _linePos += n_lines; - } - - debug(0, "Line pos: %d", _linePos); - return SUCCESS; +bool Console::Cmd_ActorAdd(int argc, const char **argv) { + if (argc != 4) + DebugPrintf("Usage: %s <Actor id> <lx> <ly>\n", argv[0]); + else + _vm->_actor->CF_actor_add(argc, argv); + return true; } -int Console::pageDown() { - int n_lines; - n_lines = (_yMax - CON_INPUT_H) / CON_LINE_H; - - if (_linePos > n_lines) { - _linePos -= n_lines; - } else { - _linePos = 0; - } - - return SUCCESS; +bool Console::Cmd_ActorDel(int argc, const char **argv) { + if (argc != 2) + DebugPrintf("Usage: %s <Actor id>\n", argv[0]); + else + _vm->_actor->CF_actor_del(argc, argv); + return true; } -int Console::dropConsole(double percent) { - SURFACE *back_buf; - - if (percent > 1.0) { - percent = 1.0; - } - - back_buf = _vm->_gfx->getBackBuffer(); - _vm->_console->setDropPos(percent); - _vm->_console->draw(back_buf); - - return SUCCESS; +bool Console::Cmd_ActorMove(int argc, const char **argv) { + if (argc != 4) + DebugPrintf("Usage: %s <Actor id> <lx> <ly>\n", argv[0]); + else + _vm->_actor->CF_actor_move(argc, argv); + return true; } -int Console::raiseConsole(double percent) { - SURFACE *back_buf; - - if (percent >= 1.0) { - percent = 1.0; - _active = false; - } - - back_buf = _vm->_gfx->getBackBuffer(); - _vm->_console->setDropPos(1.0 - percent); - _vm->_console->draw(back_buf); - - return SUCCESS; +bool Console::Cmd_ActorMoveRel(int argc, const char **argv) { + if (argc != 4) + DebugPrintf("Usage: %s <Actor id> <lx> <ly>\n", argv[0]); + else + _vm->_actor->CF_actor_moverel(argc, argv); + return true; } -int Console::setDropPos(double percent) { - double exp_percent; - - if (percent > 1.0) - percent = 1.0; - if (percent < 0.0) - percent = 0.0; - - exp_percent = percent * percent; - _yPos = (int)(_yMax * exp_percent); - - return SUCCESS; +bool Console::Cmd_ActorSetO(int argc, const char **argv) { + if (argc != 3) + DebugPrintf("Usage: %s <Actor id> <Orientation>\n", argv[0]); + else + _vm->_actor->CF_actor_seto(argc, argv); + return true; } -int Console::addLine(CON_SCROLLBACK *scroll, int line_max, const char *constr_p) { - int constr_len; - char *newstr_p; - CONSOLE_LINE *newline_p; - int del_lines; - int i; - - constr_len = strlen(constr_p) + 1; - newstr_p = (char *)malloc(constr_len); - if (newstr_p == NULL) { - return MEM; - } - - newline_p = (CONSOLE_LINE *)malloc(sizeof(CONSOLE_LINE)); - if (newline_p == NULL) { - return MEM; - } - newline_p->next = NULL; - newline_p->prev = NULL; - - strcpy(newstr_p, constr_p); - newline_p->str_p = newstr_p; - newline_p->str_len = constr_len; - - if (scroll->head == NULL) { - scroll->head = newline_p; - scroll->tail = newline_p; - } else { - scroll->head->prev = newline_p; - newline_p->next = scroll->head; - scroll->head = newline_p; - } - - scroll->lines++; - - if (scroll->lines > line_max) { - del_lines = scroll->lines - line_max; - - for (i = 0; i < del_lines; i++) { - _vm->_console->deleteLine(scroll); - } - } - - return SUCCESS; +bool Console::Cmd_ActorSetAct(int argc, const char **argv) { + if (argc != 3) + DebugPrintf("Usage: %s <Actor id> <Action #>\n", argv[0]); + else + _vm->_actor->CF_actor_setact(argc, argv); + return true; } -int Console::deleteLine(CON_SCROLLBACK *scroll) { - CONSOLE_LINE *temp_p = scroll->tail; +bool Console::Cmd_AnimInfo(int argc, const char **argv) { + _vm->_anim->animInfo(); + return true; +} - if (temp_p->prev == NULL) { - scroll->head = NULL; - scroll->tail = NULL; - } else { - temp_p->prev->next = NULL; - scroll->tail = temp_p->prev; - } +bool Console::Cmd_SceneChange(int argc, const char **argv) { + if (argc != 2) + DebugPrintf("Usage: %s <Scene number>\n", argv[0]); + else + _vm->_scene->sceneChangeCmd(argc, argv); + return true; +} - if (temp_p->str_p) - free(temp_p->str_p); - free(temp_p); - scroll->lines--; +bool Console::Cmd_SceneInfo(int argc, const char **argv) { + _vm->_scene->sceneInfoCmd(); + return true; +} - return SUCCESS; +bool Console::Cmd_ActionInfo(int argc, const char **argv) { + _vm->_scene->CF_actioninfo(); + return true; } -int Console::deleteScroll(CON_SCROLLBACK * scroll) { - CONSOLE_LINE *walk_ptr; - CONSOLE_LINE *temp_ptr; +bool Console::Cmd_ObjectInfo(int argc, const char **argv) { + _vm->_scene->CF_objectinfo(); + return true; +} - for (walk_ptr = scroll->head; walk_ptr; walk_ptr = temp_ptr) { +bool Console::Cmd_ScriptInfo(int argc, const char **argv) { + _vm->_script->scriptInfo(); + return true; +} - if (walk_ptr->str_p) - free(walk_ptr->str_p); - temp_ptr = walk_ptr->next; - free(walk_ptr); - } +bool Console::Cmd_ScriptExec(int argc, const char **argv) { + if (argc != 2) + DebugPrintf("Usage: %s <Script number>\n", argv[0]); + else + _vm->_script->scriptExec(argc, argv); + return true; +} - return SUCCESS; +bool Console::Cmd_ScriptToggleStep(int argc, const char **argv) { + _vm->_script->CF_script_togglestep(); + return true; } } // End of namespace Saga diff --git a/saga/console.h b/saga/console.h index c6b99c2a7e..ad522a7af3 100644 --- a/saga/console.h +++ b/saga/console.h @@ -26,83 +26,43 @@ #ifndef SAGA_CONSOLE_H_ #define SAGA_CONSOLE_H_ -namespace Saga { - -#define CON_INPUTBUF_LEN 80 - -#define CONSOLE_BGCOLOR 0x00A0A0A0UL -#define CONSOLE_TXTCOLOR 0x00FFFFFFUL -#define CONSOLE_TXTSHADOW 0x00202020UL - -struct CONSOLE_LINE { - CONSOLE_LINE *next; - CONSOLE_LINE *prev; - char *str_p; - int str_len; -}; +#include "common/debugger.h" -struct CON_SCROLLBACK { - CONSOLE_LINE *head; - CONSOLE_LINE *tail; - int lines; -}; +namespace Saga { -#define CON_DEFAULTPOS 136 -#define CON_DEFAULTLINES 100 -#define CON_DEFAULTCMDS 10 -#define CON_DROPTIME 400 -#define CON_PRINTFLIMIT 1024 -#define CON_LINE_H 10 -#define CON_INPUT_H 10 - -class Console { - public: - int reg(void); +class Console : public Common::Debugger<Console> { +public: Console(SagaEngine *vm); ~Console(void); - int activate(void); - int deactivate(void); - bool isActive(void); +protected: + virtual void preEnter(); + virtual void postEnter(); - int type(int in_char); - int draw(SURFACE *ds); - int print(const char *fmt_str, ...); +private: + bool Cmd_Exit(int argc, const char **argv); + bool Cmd_Help(int argc, const char **argv); - int cmdUp(void); - int cmdDown(void); - int pageUp(void); - int pageDown(void); + bool Cmd_ActorAdd(int argc, const char **argv); + bool Cmd_ActorDel(int argc, const char **argv); + bool Cmd_ActorMove(int argc, const char **argv); + bool Cmd_ActorMoveRel(int argc, const char **argv); + bool Cmd_ActorSetO(int argc, const char **argv); + bool Cmd_ActorSetAct(int argc, const char **argv); - int dropConsole(double percent); - int raiseConsole(double percent); + bool Cmd_AnimInfo(int argc, const char **argv); - private: - int addLine(CON_SCROLLBACK *scroll, int line_max, const char *constr_p); - int deleteLine(CON_SCROLLBACK *scroll); - int deleteScroll(CON_SCROLLBACK *scroll); - int setDropPos(double percent); + bool Cmd_SceneChange(int argc, const char **argv); + bool Cmd_SceneInfo(int argc, const char **argv); + bool Cmd_ActionInfo(int argc, const char **argv); + bool Cmd_ObjectInfo(int argc, const char **argv); - private: - SagaEngine *_vm; + bool Cmd_ScriptInfo(int argc, const char **argv); + bool Cmd_ScriptExec(int argc, const char **argv); + bool Cmd_ScriptToggleStep(int argc, const char **argv); - CON_SCROLLBACK _scrollback; - CON_SCROLLBACK _history; - - int _resize; - int _droptime; - - bool _active; - int _yMax; - int _lineMax; - int _histMax; - int _histPos; - int _linePos; - int _yPos; - char *_prompt; - int _promptW; - char _inputBuf[CON_INPUTBUF_LEN + 1]; - int _inputPos; +private: + SagaEngine *_vm; }; } // End of namespace Saga diff --git a/saga/cvar.cpp b/saga/cvar.cpp deleted file mode 100644 index d4793209f2..0000000000 --- a/saga/cvar.cpp +++ /dev/null @@ -1,483 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - * - */ - -// Configuration Variable Module -#include "saga/saga.h" -#include "saga/gfx.h" - -#include "saga/console.h" - -#include "saga/cvar_mod.h" -#include "saga/cvar.h" - -namespace Saga { - -CVAR *CVHashTbl[CVAR_HASHLEN]; - -static const char *CVAR_ErrMsg[] = { - "No Error", - "Not implememented.", - "Memory allocation failed", - "Value overflowed while parsing", - "Invalid numeric constant", - "Value overflows destination type", - "Assignment of negative value to unsigned variable", - "Value outside of specified bounds", - "Invalid string literal", - "Invalid type for assignment", - "Variable is read-only", - "Not a valid function" -}; - -enum CVAR_Errors { - CVERR_NONE, - CVERR_NOTIMPL, - CVERR_MEM, - CVERR_PARSEOVERFLOW, - CVERR_INVALID, - CVERR_DESTOVERFLOW, - CVERR_SIGN, - CVERR_BOUND, - CVERR_STRING, - CVERR_TYPE, - CVERR_READONLY, - CVERR_NOTFUNC -}; - -static enum CVAR_Errors CVAR_ErrorState; - -//Returns the appropriate cvar error string -int CVAR_GetError(const char **err_str) { - *err_str = CVAR_ErrMsg[CVAR_ErrorState]; - return CVAR_ErrorState; -} -// Frees the cvar hash table -int CVAR_Shutdown() { - CVAR *walk_ptr; - CVAR *temp_ptr; - int i; - - debug(0, "CVAR_Shutdown(): Deleting cvar hash table."); - - for (i = 0; i < CVAR_HASHLEN; i++) { - for (walk_ptr = CVHashTbl[i]; walk_ptr; walk_ptr = temp_ptr) { - temp_ptr = walk_ptr->next; - free(walk_ptr); - } - } - - return SUCCESS; -} - -// Returns hash index for string 'str'. -// Cannot fail. -unsigned int CVAR_HashString(const char *str) { - unsigned int index; - - for (index = 0; *str != '\0'; str++) { - index = *str + 31 * index; - } - - return index % CVAR_HASHLEN; -} - -// Adds a copy of the given cvar into the hash table. -// Returns SUCCESS if cvar was added, MEM if allocation failed. -int CVAR_Add(int index, CVAR *cvar) { - CVAR *new_cvar; - CVAR *temp_ptr; - - new_cvar = (CVAR *)malloc(sizeof(CVAR)); - - if (new_cvar == NULL) { - CVAR_ErrorState = CVERR_MEM; - return MEM; - } - - memcpy(new_cvar, cvar, sizeof(CVAR)); - - if (CVHashTbl[index] == NULL) { - CVHashTbl[index] = new_cvar; - new_cvar->next = NULL; - } else { - temp_ptr = CVHashTbl[index]; - CVHashTbl[index] = new_cvar; - new_cvar->next = temp_ptr; - } - - CVAR_ErrorState = CVERR_NONE; - return SUCCESS; -} - -// Attempts to execute the specified console function with the given argument -// string. -// Returns FAILURE if cvar_func is not a valid console function -int CVAR_Exec(CVAR_P cvar_func, char *value) { - int cf_argc = 0; - char **cf_argv = NULL; - int max_args; - - if (cvar_func->type != CVAR_FUNC) { - CVAR_ErrorState = CVERR_NOTFUNC; - return FAILURE; - } - - cf_argc = EXPR_GetArgs(value, &cf_argv); - - if (cf_argc < cvar_func->t.func.min_args) { - _vm->_console->print("Too few arguments to function."); - if (cf_argv) - free(cf_argv); - return FAILURE; - } - - max_args = cvar_func->t.func.max_args; - if ((max_args > -1) && (cf_argc > max_args)) { - _vm->_console->print("Too many arguments to function."); - if (cf_argv) - free(cf_argv); - return FAILURE; - } - - // Call function - (cvar_func->t.func.func_p) (cf_argc, cf_argv, cvar_func->refCon); - - if (cf_argv) - free(cf_argv); - - return SUCCESS; -} - -// Attempts to assign the value contained in the string 'value' to cvar. -// Returns FAILURE if there was an error parsing 'value' -int CVAR_SetValue(CVAR_P cvar, char *value) { - long int int_param; - unsigned long uint16_param; - - char *end_p; - ptrdiff_t scan_len; - int value_len; - - value_len = strlen(value); - - if (cvar->flags & CVAR_READONLY) { - CVAR_ErrorState = CVERR_READONLY; - return FAILURE; - } - - switch (cvar->type) { - case CVAR_INT: - int_param = strtol(value, &end_p, 10); - if ((int_param == LONG_MIN) || (int_param == LONG_MAX)) { - CVAR_ErrorState = CVERR_PARSEOVERFLOW; - return FAILURE; - } - scan_len = end_p - value; - - if (int_param == 0) { - if (!scan_len || value[scan_len - 1] != '0') { - // strtol() returned 0, but string isn't "0". Invalid. - CVAR_ErrorState = CVERR_INVALID; - return FAILURE; - } - } - - if (scan_len != value_len) { - // Entire string wasn't converted...Invalid - CVAR_ErrorState = CVERR_INVALID; - return FAILURE; - } - - if ((int_param < CV_INTMIN) || (int_param > CV_INTMAX)) { - // Overflows destination type - CVAR_ErrorState = CVERR_DESTOVERFLOW; - return FAILURE; - } - - // Ignore bounds if equal - if (cvar->t.i.lbound != cvar->t.i.ubound) { - if ((int_param < cvar->t.i.lbound) || (int_param > cvar->t.i.ubound)) { - // Value is outside of cvar bounds - CVAR_ErrorState = CVERR_BOUND; - return FAILURE; - } - } - - *(cvar->t.i.var_p) = (cv_int_t) int_param; - -#ifdef CVAR_TRACE - debug(2, "Set cvar to value %ld.\n", int_param); -#endif - - break; - case CVAR_UINT: - if (*value == '-') { - CVAR_ErrorState = CVERR_SIGN; - return FAILURE; - } - - uint16_param = strtoul(value, &end_p, 10); - if (uint16_param == ULONG_MAX) { - CVAR_ErrorState = CVERR_PARSEOVERFLOW; - return FAILURE; - } - - scan_len = end_p - value; - if (uint16_param == 0) { - if (!scan_len || value[scan_len - 1] != '0') { - // strtol() returned 0, but string isn't "0". Invalid. - CVAR_ErrorState = CVERR_INVALID; - return FAILURE; - } - } - - if (scan_len != value_len) { - // Entire string wasn't converted...Invalid - CVAR_ErrorState = CVERR_INVALID; - return FAILURE; - } - - if (uint16_param > CV_UINTMAX) { - // Overflows destination type - CVAR_ErrorState = CVERR_DESTOVERFLOW; - return FAILURE; - } - - // Ignore bounds if equal - if (cvar->t.ui.lbound != cvar->t.ui.ubound) { - if ((uint16_param < cvar->t.ui.lbound) || (uint16_param > cvar->t.ui.ubound)) { - // Value is outside cvar bounds - CVAR_ErrorState = CVERR_BOUND; - return FAILURE; - } - } - - *(cvar->t.ui.var_p) = (cv_uint16_t) uint16_param; -#ifdef CVAR_TRACE - debug(2, "Set cvar to value %lu.\n", uint16_param); -#endif - break; - case CVAR_FLOAT: - CVAR_ErrorState = CVERR_NOTIMPL; - return FAILURE; - break; - case CVAR_STRING: - if (strrchr(value, '\"') != NULL) { - CVAR_ErrorState = CVERR_STRING; - return FAILURE; - } - strncpy(cvar->t.s.var_str, value, cvar->t.s.ubound); - if (cvar->t.s.ubound < value_len) { - cvar->t.s.var_str[cvar->t.s.ubound] = 0; - } -#ifdef CVAR_TRACE - debug(2, "Set cvar to value \"%s\".\n", cvar->t.s.var_str); -#endif - break; - default: - CVAR_ErrorState = CVERR_TYPE; - return FAILURE; - break; - } - CVAR_ErrorState = CVERR_NONE; - return SUCCESS; -} - -// Given a cvar name this function returns a pointer to the appropriate -// cvar structure or NULL if no match was found. -CVAR_P CVAR_Find(const char *var_str) { - CVAR *walk_ptr; - int hash; - - hash = CVAR_HashString(var_str); -#ifdef CVAR_TRACE - debug(2, "Performing lookup on hash bucket %d.\n", hash); -#endif - walk_ptr = CVHashTbl[hash]; - while (walk_ptr != NULL) { - if (strcmp(var_str, walk_ptr->name) == 0) { - return walk_ptr; - } - walk_ptr = walk_ptr->next; - } - - return NULL; -} - -int CVAR_IsFunc(CVAR_P cvar_func) { - if (cvar_func->type == CVAR_FUNC) - return 1; - else - return 0; -} - -// Registers a console function 'cvar' -// (could think of a better place to put these...?) -int CVAR_RegisterFunc(cv_func_t func, const char *func_name, - const char *func_argstr, uint16 flags, int min_args, int max_args, void *refCon) { - CVAR new_cvar; - int hash; - - new_cvar.name = func_name; - new_cvar.type = CVAR_FUNC; - new_cvar.section = NULL; - new_cvar.refCon = refCon; - new_cvar.flags = flags; - new_cvar.t.func.func_p = func; - new_cvar.t.func.func_argstr = func_argstr; - new_cvar.t.func.min_args = min_args; - new_cvar.t.func.max_args = max_args; - hash = CVAR_HashString(func_name); - -#ifdef CVAR_TRACE - debug(2, "Added FUNC cvar to hash bucket %d.\n", hash); -#endif - - return CVAR_Add(hash, &new_cvar); -} - -// Registers an integer type cvar. -int CVAR_Register_I(cv_int_t * var_p, const char *var_name, - const char *section, uint16 flags, cv_int_t lbound, cv_int_t ubound) { - - CVAR new_cvar; - int hash; - - new_cvar.name = var_name; - new_cvar.type = CVAR_INT; - new_cvar.section = section; - new_cvar.flags = flags; - new_cvar.t.i.var_p = var_p; - new_cvar.t.i.lbound = lbound; - new_cvar.t.i.ubound = ubound; - hash = CVAR_HashString(var_name); - -#ifdef CVAR_TRACE - debug(2, "Added INT cvar to hash bucket %d.\n", hash); -#endif - - return CVAR_Add(hash, &new_cvar); -} - -// Registers an unsigned integer type cvar. -int CVAR_Register_UI(cv_uint16_t * var_p, const char *var_name, - const char *section, uint16 flags, cv_uint16_t lbound, cv_uint16_t ubound) { - CVAR new_cvar; - int hash; - - new_cvar.name = var_name; - new_cvar.type = CVAR_UINT; - new_cvar.section = section; - new_cvar.flags = flags; - new_cvar.t.ui.var_p = var_p; - new_cvar.t.ui.lbound = lbound; - new_cvar.t.ui.ubound = ubound; - hash = CVAR_HashString(var_name); - -#ifdef CVAR_TRACE - debug(2, "Added UNSIGNED INT ccvar to hash bucket %d.\n", hash); -#endif - - return CVAR_Add(hash, &new_cvar); -} - -// Registers a floating point type cvar. -int CVAR_Register_F(cv_float_t * var_p, const char *var_name, - const char *section, uint16 flags, cv_float_t lbound, cv_float_t ubound) { - CVAR new_cvar; - int hash; - - new_cvar.name = var_name; - new_cvar.type = CVAR_FLOAT; - new_cvar.section = section; - new_cvar.flags = flags; - new_cvar.t.f.var_p = var_p; - new_cvar.t.f.lbound = lbound; - new_cvar.t.f.ubound = ubound; - hash = CVAR_HashString(var_name); - -#ifdef CVAR_TRACE - debug(2, "Added FLOAT cvar to hash bucket %d.\n", hash); -#endif - - return CVAR_Add(hash, &new_cvar); -} - -// Registers a string type cvar. Storage must be provided in var_p for 'ubound' -// characters plus 1 for NUL char. -int CVAR_Register_S(cv_char_t * var_str, const char *var_name, const char *section, uint16 flags, int ubound) { - CVAR new_cvar; - int hash; - - new_cvar.name = var_name; - new_cvar.type = CVAR_STRING; - new_cvar.section = section; - new_cvar.flags = flags; - new_cvar.t.s.var_str = var_str; - new_cvar.t.s.ubound = ubound; - hash = CVAR_HashString(var_name); - -#ifdef CVAR_TRACE - debug(2, "Added UNSIGNED INT var to hash bucket %d.\n", hash); -#endif - - return CVAR_Add(hash, &new_cvar); -} - -// Displays the value and type of the given cvar to the console. -int CVAR_Print(CVAR_P con_cvar) { - switch (con_cvar->type) { - - case CVAR_INT: - _vm->_console->print("\"%s\"(i) = %d", con_cvar->name, *(con_cvar->t.i.var_p)); - break; - - case CVAR_UINT: - _vm->_console->print("\"%s\"(ui) = %u", con_cvar->name, *(con_cvar->t.ui.var_p)); - break; - - case CVAR_FLOAT: - _vm->_console->print("\"%s\"(ui) = %f", con_cvar->name, *(con_cvar->t.f.var_p)); - break; - - case CVAR_STRING: - _vm->_console->print("\"%s\"(s) = \"%s\"", con_cvar->name, con_cvar->t.s.var_str); - break; - - case CVAR_FUNC: - if (con_cvar->t.func.func_argstr) { - _vm->_console->print("\"%s\"(func) Args: %s", con_cvar->name, con_cvar->t.func.func_argstr); - } else { - _vm->_console->print("\"%s\"(func) No arguments.", con_cvar->name); - } - break; - - default: - _vm->_console->print("Invalid variable type.\n"); - break; - } - - return SUCCESS; -} - -} // End of namespace Saga diff --git a/saga/cvar.h b/saga/cvar.h deleted file mode 100644 index 3f0fe48300..0000000000 --- a/saga/cvar.h +++ /dev/null @@ -1,85 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - * - */ - -// Configuration Variable Module - -#ifndef SAGA_CVAR_H_ -#define SAGA_CVAR_H_ - -namespace Saga { - -#define CVAR_HASHLEN 32 - -struct SUBCVAR_INT { - cv_int_t *var_p; - cv_int_t ubound; - cv_int_t lbound; -}; - -struct SUBCVAR_UINT { - cv_uint16_t *var_p; - cv_uint16_t ubound; - cv_uint16_t lbound; - -}; - -struct SUBCVAR_FLOAT { - cv_float_t *var_p; - cv_float_t ubound; - cv_float_t lbound; -}; - -struct SUBCVAR_STRING { - cv_char_t *var_str; - int ubound; -}; - -struct SUBCVAR_FUNC { - cv_func_t func_p; - const char *func_argstr; - int min_args; - int max_args; -}; - -struct CVAR { - int type; - const char *name; - const char *section; - uint16 flags; - void *refCon; - - union { - SUBCVAR_INT i; - SUBCVAR_UINT ui; - SUBCVAR_FLOAT f; - SUBCVAR_STRING s; - SUBCVAR_FUNC func; - } t; - - CVAR *next; - -}; - -} // End of namespace Saga - -#endif diff --git a/saga/cvar_mod.h b/saga/cvar_mod.h deleted file mode 100644 index b428a9c0b2..0000000000 --- a/saga/cvar_mod.h +++ /dev/null @@ -1,88 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - * - */ - -// Configuration variable module public header file - -#ifndef SAGA_CVAR_MOD_H_ -#define SAGA_CVAR_MOD_H_ - -namespace Saga { - -// Modify these to change base cvar types -#define CV_INTMAX INT_MAX -#define CV_INTMIN INT_MIN - -#define CV_UINTMAX UINT_MAX -typedef int cv_int_t; -typedef unsigned int cv_uint16_t; -typedef float cv_float_t; -typedef char cv_char_t; -typedef void (*cv_func_t) (int cv_argc, char *cv_argv[], void *refCon); -/******************************************/ - -typedef struct CVAR *CVAR_P; // opaque typedef - -enum CVAR_TYPES { - CVAR_INVALID, - CVAR_INT, - CVAR_UINT, - CVAR_FLOAT, - CVAR_STRING, - CVAR_FUNC -}; - -enum CVAR_FLAGS { - CVAR_NONE, - CVAR_READONLY, - CVAR_LBOUND, - CVAR_UBOUND, - CVAR_CFG, - CVAR_SECTION -}; - -#define CVAR_BOUNDED ( CVAR_LBOUND | CVAR_UBOUND ) - -int CVAR_Shutdown(); -CVAR_P CVAR_Find(const char *var_str); -int CVAR_SetValue(CVAR_P cvar, char *r_value); -int CVAR_Print(CVAR_P con_cvar); -int CVAR_GetError(const char **err_str); -int CVAR_IsFunc(CVAR_P cvar_func); -int CVAR_Exec(CVAR_P cvar_func, char *r_value); -int CVAR_RegisterFunc(cv_func_t func, const char *func_name, - const char *func_argstr, uint16 flags, int min_args, int max_args, void *refCon); -int CVAR_Register_I(cv_int_t * var_p, const char *var_name, - const char *section, uint16 flags, cv_int_t lbound, cv_int_t ubound); -int CVAR_Register_UI(cv_uint16_t * var_p, const char *var_name, - const char *section, uint16 flags, cv_uint16_t lbound, cv_uint16_t ubound); -int CVAR_Register_F(cv_float_t * var_p, const char *var_name, - const char *section, uint16 flags, cv_float_t lbound, cv_float_t ubound); -int CVAR_Register_S(cv_char_t * var_str, const char *var_name, const char *section, uint16 flags, int ubound); -int EXPR_Parse(const char **exp_pp, int *len, CVAR_P * expr_cvar, char **rvalue); -char *EXPR_ReadString(const char **string_p, int *len, int term_char); -int EXPR_GetError(const char **err_str); -int EXPR_GetArgs(char *cmd_str, char ***expr_argv); - -} // End of namespace Saga - -#endif diff --git a/saga/events.cpp b/saga/events.cpp index f377b444d1..f1bbdcc564 100644 --- a/saga/events.cpp +++ b/saga/events.cpp @@ -198,18 +198,6 @@ int Events::handleContinuous(EVENT *event) { break; } break; - case CONSOLE_EVENT: - switch (event->op) { - case EVENT_ACTIVATE: - _vm->_console->dropConsole(event_pc); - break; - case EVENT_DEACTIVATE: - _vm->_console->raiseConsole(event_pc); - break; - default: - break; - } - break; default: break; @@ -398,7 +386,7 @@ int Events::handleOneShot(EVENT *event) { sthread = _vm->_script->SThreadCreate(); if (sthread == NULL) { - _vm->_console->print("Thread creation failed."); + _vm->_console->DebugPrintf("Thread creation failed.\n"); break; } diff --git a/saga/expr.cpp b/saga/expr.cpp deleted file mode 100644 index ea744a1c4f..0000000000 --- a/saga/expr.cpp +++ /dev/null @@ -1,390 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - * - */ - -// Expression parsing module, and string handling functions - -// EXPR_ParseArgs() lifted wholesale from SDL win32 initialization code by Sam Lantinga - -#include "saga/saga.h" -#include "saga/cvar_mod.h" -#include "saga/expr.h" - -namespace Saga { - -static const char *EXPR_ErrMsg[] = { - "Invalid error state.", - "No Error", - "Memory allocation failed", - "Illegal variable name", - "Expected \'=\' or \'(\' in expression", - "Expected \'(\' in function call", - "Illegal \'(\', identifier is not function", - "Expected a value to assign", - "Unterminated string literal", - "Unmatched parenthesis in function call", - "Error reading value string", - "Expected a number or boolean", - "Unknown variable or function" -}; - -enum EXPR_Errors { - EXERR_ASSERT, - EXERR_NONE, - EXERR_MEM, - EXERR_ILLEGAL, - EXERR_EXPR, - EXERR_FUNC, - EXERR_NOTFUNC, - EXERR_RVALUE, - EXERR_LITERAL, - EXERR_PAREN, - EXERR_STRING, - EXERR_NUMBER, - EXERR_NOTFOUND -}; - -static enum EXPR_Errors EXPR_ErrorState; - -// Returns the appropriate expression parser error string given an error code. -int EXPR_GetError(const char **err_str) { - *err_str = EXPR_ErrMsg[EXPR_ErrorState]; - return EXPR_ErrorState; -} - -// Parses an interactive expression. -// Sets 'expCVAR' to the cvar/cfunction identifier input by the user, and -// 'rvalue' to the corresponding rvalue ( in an expression ) or argument string -// ( in a function call ). -// -// Memory pointed to by rvalue after return must be explicitly freed by the -// caller. -int EXPR_Parse(const char **exp_pp, int *len, CVAR_P *expCVAR, char **rvalue) { - int i; - int in_char; - int equ_offset = 0; - int rvalue_offset; - - char *lvalue_str; - int lvalue_len; - char *rvalue_str; - int rvalue_len; - - const char *scan_p; - int scan_len; - const char *expr_p; - int expr_len; - int test_char = '\0'; - int have_func = 0; - - CVAR_P lvalue_cvar; - - expr_p = *exp_pp; - expr_len = strlen(*exp_pp); - scan_p = *exp_pp; - scan_len = expr_len; - - //*lvalue = NULL; - *rvalue = NULL; - - EXPR_ErrorState = EXERR_ASSERT; - - for (i = 0; i <= scan_len; i++, scan_p++) { - in_char = *scan_p; - if ((i == 0) && isdigit(in_char)) { - // First character of a valid identifier cannot be a digit - EXPR_ErrorState = EXERR_ILLEGAL; - return FAILURE; - } - - // If we reach a character that isn't valid in an identifier... - if ((!isalnum(in_char)) && ((in_char != '_'))) { - - // then eat remaining whitespace, if any - equ_offset = strspn(scan_p, EXPR_WHITESPACE); - test_char = scan_p[equ_offset]; - // and test for the only valid characters after an identifier - if ((test_char != '=') && (test_char != '\0') && (test_char != '(')) { - if ((equ_offset == 0) && ((scan_p - expr_p) != expr_len)) { - EXPR_ErrorState = EXERR_ILLEGAL; - } else { - EXPR_ErrorState = EXERR_EXPR; - } - return FAILURE; - } - break; - } - } - - lvalue_len = (scan_p - expr_p); - lvalue_str = (char *)malloc(lvalue_len + 1); - - if (lvalue_str == NULL) { - EXPR_ErrorState = EXERR_MEM; - return FAILURE; - } - - strncpy(lvalue_str, expr_p, lvalue_len); - lvalue_str[lvalue_len] = 0; - - // We now have the lvalue, so attempt to find it - lvalue_cvar = CVAR_Find(lvalue_str); - if (lvalue_cvar == NULL) { - EXPR_ErrorState = EXERR_NOTFOUND; - return FAILURE; - } - if (lvalue_str) { - free(lvalue_str); - lvalue_str = NULL; - } - - // Skip parsed character, if any - scan_p += equ_offset + 1; - scan_len = (scan_p - expr_p); - - // Check if the 'cvar' is really a function - have_func = CVAR_IsFunc(lvalue_cvar); - - if (test_char == '(') { - if (have_func) { - rvalue_str = EXPR_ReadString(&scan_p, &rvalue_len, ')'); - if (rvalue_str != NULL) { - // Successfully read string - //CON_Print("Read function parameters \"%s\".", rvalue_str); - *expCVAR = lvalue_cvar; - *rvalue = rvalue_str; - - scan_len = (scan_p - expr_p); - - *exp_pp = scan_p; - *len -= scan_len; - - EXPR_ErrorState = EXERR_NONE; - return SUCCESS; - } else { - EXPR_ErrorState = EXERR_PAREN; - return FAILURE; - } - } else { - EXPR_ErrorState = EXERR_NOTFUNC; - return FAILURE; - } - } - - // Eat more whitespace - rvalue_offset = strspn(scan_p, EXPR_WHITESPACE); - - if (rvalue_offset + i == expr_len) { - // Only found single lvalue - *expCVAR = lvalue_cvar; - *exp_pp = scan_p; - *len -= scan_len; - return SUCCESS; - } - - scan_p += rvalue_offset; - scan_len = (scan_p - expr_p) + 1; - - in_char = *scan_p; - in_char = toupper(in_char); - - switch (in_char) { - case '\"': - scan_p++; - scan_len--; - rvalue_str = EXPR_ReadString(&scan_p, &rvalue_len, '\"'); - if (rvalue_str != NULL) { - // Successfully read string - break; - } else { - EXPR_ErrorState = EXERR_LITERAL; - return FAILURE; - } - break; - -#if 0 - case 'Y': // Y[es] - case 'T': // T[rue] - break; - case 'N': // N[o] - case 'F': // F[alse] - break; -#endif - default: - - if (isdigit(in_char) || (in_char == '-') || (in_char == '+')) { - rvalue_str = EXPR_ReadString(&scan_p, &rvalue_len, 0); - if (rvalue_str != NULL) { - // Successfully read string - break; - } else { - EXPR_ErrorState = EXERR_STRING; - return FAILURE; - } - } else { - EXPR_ErrorState = EXERR_NUMBER; - return FAILURE; - } - break; - } - - *expCVAR = lvalue_cvar; - *rvalue = rvalue_str; - - scan_len = (scan_p - expr_p); - - *exp_pp = scan_p; - *len -= scan_len; - - EXPR_ErrorState = EXERR_NONE; - return SUCCESS; - -} - -// Reads in a string of characters from '*string_p' until 'term_char' is -// encountered. If 'term_char' == 0, the function reads characters until -// whitespace is encountered. -// Upon reading a string, the function modifies *string_p and len based on -// the number of characters read. -char *EXPR_ReadString(const char **string_p, int *len, int term_char) { - int string_len; - char *str_p = NULL; - char *term_p; - const char *scan_p; - int in_char; - - if (term_char > 0) { - term_p = (char *)strchr(*string_p, term_char); - if (term_p == NULL) { - return NULL; - } - - string_len = (int)(term_p - *string_p); - str_p = (char *)malloc(string_len + 1); - - if (str_p == NULL) { - return NULL; - } - - strncpy(str_p, *string_p, string_len); - str_p[string_len] = 0; - - *string_p += (string_len + 1); /* Add 1 for terminating char */ - *len -= (string_len + 1); - } else { - scan_p = *string_p; - string_len = 0; - - while (scan_p) { - in_char = *scan_p++; - if (!isspace(in_char)) { - string_len++; - } else if (string_len) { - str_p = (char *)malloc(string_len + 1); - if (str_p == NULL) { - return NULL; - } - - strncpy(str_p, *string_p, string_len); - str_p[string_len] = 0; - *string_p += string_len; - *len -= string_len; - break; - } else { - return NULL; - } - } - - } - - return str_p; -} - -// Parses the string 'cmd_str' into argc/argv format, returning argc. -// The resulting argv pointers point into the 'cmd_str' string, so any argv -// entries should not be used after cmd_str is deallocated. -// -// Memory pointed to by expr_argv must be explicitly freed by the caller. -int EXPR_GetArgs(char *cmd_str, char ***expr_argv) { - int expr_argc; - - expr_argc = EXPR_ParseArgs(cmd_str, NULL); - *expr_argv = (char **)malloc((expr_argc + 1) * sizeof(**expr_argv)); - - if (expr_argv == NULL) { - return FAILURE; - } - - EXPR_ParseArgs(cmd_str, *expr_argv); - - return expr_argc; -} - -int EXPR_ParseArgs(char *cmd_str, char **argv) { - char *bufp; - int argc; - - argc = 0; - for (bufp = cmd_str; *bufp;) { - // Skip leading whitespace - while (isspace(*bufp)) { - ++bufp; - } - // Skip over argument - if (*bufp == '"') { - ++bufp; - if (*bufp) { - if (argv) { - argv[argc] = bufp; - } - ++argc; - } - // Skip over word - while (*bufp && (*bufp != '"')) { - ++bufp; - } - } else { - if (*bufp) { - if (argv) { - argv[argc] = bufp; - } - ++argc; - } - // Skip over word - while (*bufp && !isspace(*bufp)) { - ++bufp; - } - } - if (*bufp) { - if (argv) { - *bufp = '\0'; - } - ++bufp; - } - } - if (argv) { - argv[argc] = NULL; - } - return (argc); -} - -} // End of namespace Saga diff --git a/saga/expr.h b/saga/expr.h deleted file mode 100644 index f003ff04a6..0000000000 --- a/saga/expr.h +++ /dev/null @@ -1,37 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - * -*/ - -// Expression parsing module header file - -#ifndef SAGA_EXPR_H_ -#define SAGA_EXPR_H_ - -namespace Saga { - -#define EXPR_WHITESPACE " \n " - -int EXPR_ParseArgs(char *cmd_str, char **argv); - -} // End of namespace Saga - -#endif diff --git a/saga/game.cpp b/saga/game.cpp index 18874a96cf..f19b80ee05 100644 --- a/saga/game.cpp +++ b/saga/game.cpp @@ -30,7 +30,6 @@ #include "backends/fs/fs.h" #include "saga/rscfile_mod.h" -#include "saga/cvar_mod.h" #include "saga/interface.h" #include "saga/scene.h" @@ -296,25 +295,6 @@ GAMEDESC GameDescs[] = { static GAMEMODULE GameModule; -int GAME_Register() { - return SUCCESS; - - // Register "g_language" cfg cvar - strncpy(GameModule.game_language, "us", MAXPATH); - - if (CVAR_Register_S(GameModule.game_language, "g_language", - NULL, CVAR_CFG, GAME_LANGSTR_LIMIT) != SUCCESS) { - return FAILURE; - } - - // Register "g_skipintro" cfg cvar - if (CVAR_Register_I(&GameModule.g_skipintro, "g_skipintro", NULL, CVAR_CFG, 0, 1) != SUCCESS) { - return FAILURE; - } - - return SUCCESS; -} - int GAME_Init() { uint16 game_n; diff --git a/saga/ihnm_introproc.cpp b/saga/ihnm_introproc.cpp index f3b6154c6a..6e3ea07e46 100644 --- a/saga/ihnm_introproc.cpp +++ b/saga/ihnm_introproc.cpp @@ -28,7 +28,6 @@ #include "saga/gfx.h" #include "saga/animation.h" -#include "saga/cvar_mod.h" #include "saga/events.h" #include "saga/rscfile_mod.h" #include "saga/sndres.h" diff --git a/saga/input.cpp b/saga/input.cpp index 37f764eee4..8a427e38f5 100644 --- a/saga/input.cpp +++ b/saga/input.cpp @@ -38,76 +38,51 @@ int SagaEngine::processInput() { Point imousePt; while (g_system->pollEvent(event)) { - int in_char; - switch (event.event_code) { case OSystem::EVENT_KEYDOWN: - if (_vm->_console->isActive()) { - in_char = event.kbd.ascii; - switch (event.kbd.keycode) { - case 96: // backquote - _vm->_console->deactivate(); - break; - case 280: // page up - _vm->_console->pageUp(); - break; - case 281: // page down - _vm->_console->pageDown(); - break; - case 273: // up - case 264: // keypad up - _vm->_console->cmdUp(); - break; - case 274: // down - case 258: // keypad down - _vm->_console->cmdDown(); - break; - default: - if (in_char) { - _vm->_console->type(in_char); - } - break; - } - break; + if (event.kbd.flags == OSystem::KBD_CTRL) { + if (event.kbd.keycode == 'd') + _console->attach(); } - switch (event.kbd.keycode) { - case 96: // back quote - _vm->_console->activate(); + case '#': + case '`': + case '~': + _console->attach(); break; - case 114: // r - _vm->_interface->draw(); + case 'r': + _interface->draw(); break; case 282: // F1 - _vm->_render->toggleFlag(RF_SHOW_FPS); + _render->toggleFlag(RF_SHOW_FPS); break; case 283: // F2 - _vm->_render->toggleFlag(RF_PALETTE_TEST); + _render->toggleFlag(RF_PALETTE_TEST); break; case 284: // F3 - _vm->_render->toggleFlag(RF_TEXT_TEST); + _render->toggleFlag(RF_TEXT_TEST); break; case 285: // F4 - _vm->_render->toggleFlag(RF_OBJECTMAP_TEST); + _render->toggleFlag(RF_OBJECTMAP_TEST); break; case 9: // Tab - _vm->_script->SThreadDebugStep(); + _script->SThreadDebugStep(); break; // Actual game keys case 32: // space - _vm->_actor->skipDialogue(); + _actor->skipDialogue(); break; case 19: // pause - case 112: // p - _vm->_render->toggleFlag(RF_RENDERPAUSE); + case 'p': + _render->toggleFlag(RF_RENDERPAUSE); break; case 27: // Esc // Skip to next scene skip target - if (!_vm->_interface->getMode() == kPanelNone) // FIXME: hack - _vm->_script->SThreadAbortAll(); + if (!_interface->getMode() == kPanelNone) // FIXME: hack + _script->SThreadAbortAll(); else - _vm->_scene->skipScene(); + _scene->skipScene(); break; default: break; @@ -117,7 +92,7 @@ int SagaEngine::processInput() { _mousePos.x = event.mouse.x; _mousePos.y = event.mouse.y; imousePt = _mousePos; - _vm->_interface->update(imousePt, UPDATE_MOUSECLICK); + _interface->update(imousePt, UPDATE_MOUSECLICK); break; case OSystem::EVENT_MOUSEMOVE: _mousePos.x = event.mouse.x; diff --git a/saga/interface.cpp b/saga/interface.cpp index 4ae40ece9f..b3c0044caf 100644 --- a/saga/interface.cpp +++ b/saga/interface.cpp @@ -26,7 +26,6 @@ #include "saga/gfx.h" #include "saga/game_mod.h" -#include "saga/cvar_mod.h" #include "saga/actor.h" #include "saga/console.h" #include "saga/font.h" @@ -144,6 +143,7 @@ static INTERFACE_BUTTON IHNM_c_buttons[] = { }; int Interface::registerLang(void) { +#if 0 size_t i; for (i = 0; i < ARRAYSIZE(I_VerbData); i++) { @@ -156,6 +156,7 @@ int Interface::registerLang(void) { assert(CVAR_Find(I_VerbData[i].verb_cvar) != NULL); } +#endif return SUCCESS; } diff --git a/saga/ite_introproc.cpp b/saga/ite_introproc.cpp index adb9df7446..7050a4b196 100644 --- a/saga/ite_introproc.cpp +++ b/saga/ite_introproc.cpp @@ -29,7 +29,6 @@ #include "saga/yslib.h" #include "saga/animation.h" -#include "saga/cvar_mod.h" #include "saga/events.h" #include "saga/font.h" #include "saga/game_mod.h" @@ -150,6 +149,7 @@ int Scene::ITEStartProc() { } int Scene::ITEIntroRegisterLang() { +#if 0 size_t i; for (i = 0; i < ARRAYSIZE(IntroDiag); i++) { @@ -160,6 +160,7 @@ int Scene::ITEIntroRegisterLang() { return FAILURE; } } +#endif return SUCCESS; } diff --git a/saga/module.mk b/saga/module.mk index 67425fbb83..c19128e950 100644 --- a/saga/module.mk +++ b/saga/module.mk @@ -6,9 +6,7 @@ MODULE_OBJS := \ saga/actordata.o \ saga/animation.o \ saga/console.o \ - saga/cvar.o \ saga/events.o \ - saga/expr.o \ saga/font.o \ saga/font_map.o \ saga/game.o \ diff --git a/saga/objectmap.cpp b/saga/objectmap.cpp index 32d377d45f..c5fe9782d7 100644 --- a/saga/objectmap.cpp +++ b/saga/objectmap.cpp @@ -29,7 +29,6 @@ #include "saga/saga.h" #include "saga/gfx.h" -#include "saga/cvar_mod.h" #include "saga/console.h" #include "saga/font.h" #include "saga/objectmap.h" @@ -345,11 +344,11 @@ int ObjectMap::hitTest(const Point& imousePt) { void ObjectMap::info(void) { int i; - _vm->_console->print("%d objects loaded.", _nObjects); + _vm->_console->DebugPrintf("%d objects loaded.\n", _nObjects); for (i = 0; i < _nObjects; i++) { - _vm->_console->print("%s:", _names[i]); - _vm->_console->print("%d. verb: %d, flags: %X, name_i: %d, scr_n: %d, ca_ct: %d", i, + _vm->_console->DebugPrintf("%s:\n", _names[i]); + _vm->_console->DebugPrintf("%d. verb: %d, flags: %X, name_i: %d, scr_n: %d, ca_ct: %d\n", i, _objectMaps[i].defaultVerb, _objectMaps[i].flags, _objectMaps[i].objectNum, diff --git a/saga/render.cpp b/saga/render.cpp index c015329b0b..80e7d3526c 100644 --- a/saga/render.cpp +++ b/saga/render.cpp @@ -26,8 +26,6 @@ #include "saga/gfx.h" #include "saga/actor.h" -#include "saga/console.h" -#include "saga/cvar_mod.h" #include "saga/font.h" #include "saga/game_mod.h" #include "saga/interface.h" @@ -44,10 +42,6 @@ namespace Saga { const char *test_txt = "The quick brown fox jumped over the lazy dog. She sells sea shells down by the sea shore."; -int Render::reg(void) { - return SUCCESS; -} - Render::Render(SagaEngine *vm, OSystem *system) { _vm = vm; _system = system; @@ -182,9 +176,6 @@ int Render::drawScene() { drawPalette(backbuf_surface); } - // Draw console - _vm->_console->draw(backbuf_surface); - _system->copyRectToScreen((byte *)backbuf_surface->pixels, backbuf_surface->w, 0, 0, backbuf_surface->w, backbuf_surface->h); diff --git a/saga/render.h b/saga/render.h index b798cc31c2..8d58eba292 100644 --- a/saga/render.h +++ b/saga/render.h @@ -51,7 +51,6 @@ struct BUFFER_INFO { class Render { public: - int reg(void); Render(SagaEngine *vm, OSystem *system); ~Render(void); bool initialized(); diff --git a/saga/saga.cpp b/saga/saga.cpp index be8e405e0d..3e04e64a76 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -38,7 +38,6 @@ #include "saga/actor.h" #include "saga/animation.h" #include "saga/console.h" -#include "saga/cvar_mod.h" #include "saga/events.h" #include "saga/font.h" #include "saga/game_mod.h" @@ -89,14 +88,13 @@ namespace Saga { #define MAX_TIME_DELTA 100 -static void CF_quitfunc(int argc, char *argv[], void *refCon); -static void CF_testfunc(int argc, char *argv[], void *refCon); - SagaEngine *_vm = NULL; SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst) : Engine(syst) { + _console = NULL; + // The Linux version of Inherit the Earth puts all data files in an // 'itedata' sub-directory, except for voices.rsc File::addDefaultDirectory(_gameDataPath + "itedata/"); @@ -129,16 +127,6 @@ int SagaEngine::init(GameDetector &detector) { _soundEnabled = 1; _musicEnabled = 1; - _console = new Console(this); - - CVAR_RegisterFunc(CF_testfunc, "testfunc", "foo [ optional foo ]", CVAR_NONE, 0, -1, this); - - CVAR_Register_I(&_soundEnabled, "sound", NULL, CVAR_CFG, 0, 1); - - CVAR_Register_I(&_musicEnabled, "music", NULL, CVAR_CFG, 0, 1); - - CVAR_RegisterFunc(CF_quitfunc, "quit", NULL, CVAR_NONE, 0, 0, this); - // Add some default directories // Win32 demo & full game File::addDefaultDirectory("graphics"); @@ -186,6 +174,9 @@ int SagaEngine::init(GameDetector &detector) { GAME_GetDisplayInfo(&disp_info); _gfx = new Gfx(_system, disp_info.logical_w, disp_info.logical_h, detector); + // Graphics driver should be initialized before console + _console = new Console(this); + // Graphics should be initialized before music int midiDriver = MidiDriver::detectMusicDriver(MDT_NATIVE | MDT_ADLIB | MDT_PREFER_NATIVE); bool native_mt32 = (ConfMan.getBool("native_mt32") || (midiDriver == MD_MT32)); @@ -221,15 +212,6 @@ int SagaEngine::init(GameDetector &detector) { debug(0, "Sound disabled."); } - // Register engine modules - _console->reg(); // Register console cvars first - GAME_Register(); - _scene->reg(); - _actor->reg(); - _script->reg(); - _render->reg(); - _anim->reg(); - return 0; } @@ -246,6 +228,9 @@ int SagaEngine::go() { uint32 currentTicks; for (;;) { + if (_console->isAttached()) + _console->onFrame(); + if (_render->getFlags() & RF_RENDERPAUSE) { // Freeze time while paused _previousTicks = _system->getMillis(); @@ -280,7 +265,6 @@ void SagaEngine::shutdown() { delete _sprite; delete _font; delete _console; - CVAR_Shutdown(); delete _events; delete _palanim; @@ -297,19 +281,4 @@ void SagaEngine::shutdown() { _system->quit(); } -static void CF_quitfunc(int argc, char *argv[], void *refCon) { - ((SagaEngine *)refCon)->shutdown(); - exit(0); -} - -static void CF_testfunc(int argc, char *argv[], void *refCon) { - int i; - - _vm->_console->print("Test function invoked: Got %d arguments.", argc); - - for (i = 0; i < argc; i++) { - _vm->_console->print("Arg %d: %s", i, argv[i]); - } -} - } // End of namespace Saga diff --git a/saga/scene.cpp b/saga/scene.cpp index 7496029950..b001752730 100644 --- a/saga/scene.cpp +++ b/saga/scene.cpp @@ -29,7 +29,6 @@ #include "saga/game_mod.h" #include "saga/animation.h" #include "saga/console.h" -#include "saga/cvar_mod.h" #include "saga/interface.h" #include "saga/events.h" #include "saga/actionmap.h" @@ -47,23 +46,6 @@ namespace Saga { -static void CF_scenechange(int argc, char *argv[], void *refCon); -static void CF_sceneinfo(int argc, char *argv[], void *refCon); -static void CF_actioninfo(int argc, char *argv[], void *refCon); -static void CF_objectinfo(int argc, char *argv[], void *refCon); - - -int Scene::reg() { - CVAR_Register_I(&_sceneNumber, "scene", NULL, CVAR_READONLY, 0, 0); - CVAR_RegisterFunc(CF_scenechange, "scene_change", "<Scene number>", CVAR_NONE, 1, 1, this); - CVAR_RegisterFunc(CF_sceneinfo, "scene_info", NULL, CVAR_NONE, 0, 0, this); - CVAR_RegisterFunc(CF_actioninfo, - "action_info", NULL, CVAR_NONE, 0, 0, this); - CVAR_RegisterFunc(CF_objectinfo, "object_info", NULL, CVAR_NONE, 0, 0, this); - - return SUCCESS; -} - Scene::Scene(SagaEngine *vm) : _vm(vm), _initialized(false) { GAME_SCENEDESC gs_desc; byte *scene_lut_p; @@ -904,72 +886,53 @@ int Scene::endScene() { return SUCCESS; } -void Scene::sceneChangeCmd(int argc, char *argv[]) { +void Scene::sceneChangeCmd(int argc, const char **argv) { int scene_num = 0; - if ((argc == 0) || (argc > 1)) { - return; - } - - scene_num = atoi(argv[0]); + scene_num = atoi(argv[1]); if ((scene_num < 1) || (scene_num > _sceneMax)) { - _vm->_console->print("Invalid scene number."); + _vm->_console->DebugPrintf("Invalid scene number.\n"); return; } clearSceneQueue(); if (changeScene(scene_num) == SUCCESS) { - _vm->_console->print("Scene changed."); + _vm->_console->DebugPrintf("Scene changed.\n"); } else { - _vm->_console->print("Couldn't change scene!"); + _vm->_console->DebugPrintf("Couldn't change scene!\n"); } } -static void CF_scenechange(int argc, char *argv[], void *refCon) { - ((Scene *)refCon)->sceneChangeCmd(argc, argv); -} - -void Scene::sceneInfoCmd(int argc, char *argv[]) { - const char *fmt = "%-20s %d"; - - _vm->_console->print(fmt, "Scene number:", _sceneNumber); - _vm->_console->print(fmt, "Descriptor R#:", _sceneResNum); - _vm->_console->print("-------------------------"); - _vm->_console->print(fmt, "Flags:", _desc.flags); - _vm->_console->print(fmt, "Resource list R#:", _desc.resListRN); - _vm->_console->print(fmt, "End slope:", _desc.endSlope); - _vm->_console->print(fmt, "Begin slope:", _desc.beginSlope); - _vm->_console->print(fmt, "Script resource:", _desc.scriptNum); - _vm->_console->print(fmt, "Scene script:", _desc.sceneScriptNum); - _vm->_console->print(fmt, "Start script:", _desc.startScriptNum); - _vm->_console->print(fmt, "Music R#", _desc.musicRN); -} - -static void CF_sceneinfo(int argc, char *argv[], void *refCon) { - ((Scene *)refCon)->sceneInfoCmd(argc, argv); +void Scene::sceneInfoCmd() { + const char *fmt = "%-20s %d\n"; + + _vm->_console->DebugPrintf(fmt, "Scene number:", _sceneNumber); + _vm->_console->DebugPrintf(fmt, "Descriptor R#:", _sceneResNum); + _vm->_console->DebugPrintf("-------------------------\n"); + _vm->_console->DebugPrintf(fmt, "Flags:", _desc.flags); + _vm->_console->DebugPrintf(fmt, "Resource list R#:", _desc.resListRN); + _vm->_console->DebugPrintf(fmt, "End slope:", _desc.endSlope); + _vm->_console->DebugPrintf(fmt, "Begin slope:", _desc.beginSlope); + _vm->_console->DebugPrintf(fmt, "Script resource:", _desc.scriptNum); + _vm->_console->DebugPrintf(fmt, "Scene script:", _desc.sceneScriptNum); + _vm->_console->DebugPrintf(fmt, "Start script:", _desc.startScriptNum); + _vm->_console->DebugPrintf(fmt, "Music R#", _desc.musicRN); } int Scene::SC_defaultScene(int param, SCENE_INFO *scene_info, void *refCon) { return ((Scene *)refCon)->defaultScene(param, scene_info); } -static void CF_actioninfo(int argc, char *argv[], void *refCon) { - (void)(argc); - (void)(argv); - - ((Scene *)refCon)->_actionMap->info(); +void Scene::CF_actioninfo() { + _actionMap->info(); } -static void CF_objectinfo(int argc, char *argv[], void *refCon) { - (void)(argc); - (void)(argv); - - ((Scene *)refCon)->_objectMap->info(); +void Scene::CF_objectinfo() { + _objectMap->info(); } - int Scene::defaultScene(int param, SCENE_INFO *scene_info) { EVENT event; EVENT *q_event; diff --git a/saga/scene.h b/saga/scene.h index f300339b58..b4124573a4 100644 --- a/saga/scene.h +++ b/saga/scene.h @@ -214,7 +214,9 @@ class Scene { public: Scene(SagaEngine *vm); ~Scene(); - int reg(); + + void CF_actioninfo(); + void CF_objectinfo(); int startScene(); int nextScene(); @@ -235,8 +237,8 @@ class Scene { bool initialized() { return _initialized; } - void sceneInfoCmd(int argc, char *argv[]); - void sceneChangeCmd(int argc, char *argv[]); + void sceneInfoCmd(); + void sceneChangeCmd(int argc, const char **argv); int getSceneLUT(int num); int currentSceneNumber() { return _sceneNumber; } diff --git a/saga/script.cpp b/saga/script.cpp index 09e28fb58e..beb3173d12 100644 --- a/saga/script.cpp +++ b/saga/script.cpp @@ -29,24 +29,11 @@ #include "saga/rscfile_mod.h" #include "saga/game_mod.h" #include "saga/console.h" -#include "saga/cvar_mod.h" #include "saga/script.h" namespace Saga { -static void CF_script_info(int argc, char *argv[], void *refCon); -static void CF_script_exec(int argc, char *argv[], void *refCon); -static void CF_script_togglestep(int argc, char *argv[], void *refCon); - -int Script::reg() { - CVAR_RegisterFunc(CF_script_info, "script_info", NULL, CVAR_NONE, 0, 0, this); - CVAR_RegisterFunc(CF_script_exec, "script_exec", "<Script number>", CVAR_NONE, 1, 1, this); - CVAR_RegisterFunc(CF_script_togglestep, "script_togglestep", NULL, CVAR_NONE, 0, 0, this); - - return SUCCESS; -} - // Initializes the scripting module. // Loads script resource look-up table, initializes script data system Script::Script() { @@ -496,7 +483,7 @@ VOICE_LUT *Script::loadVoiceLUT(const byte *voicelut_p, size_t voicelut_len, SCR return voice_lut; } -void Script::scriptInfo(int argc, char *argv[]) { +void Script::scriptInfo() { uint32 n_entrypoints; uint32 i; char *name_ptr; @@ -511,51 +498,39 @@ void Script::scriptInfo(int argc, char *argv[]) { n_entrypoints = currentScript()->bytecode->n_entrypoints; - _vm->_console->print("Current script contains %d entrypoints:", n_entrypoints); + _vm->_console->DebugPrintf("Current script contains %d entrypoints:\n", n_entrypoints); for (i = 0; i < n_entrypoints; i++) { name_ptr = (char *)currentScript()->bytecode->bytecode_p + currentScript()->bytecode->entrypoints[i].name_offset; - _vm->_console->print("%lu: %s", i, name_ptr); + _vm->_console->DebugPrintf("%lu: %s\n", i, name_ptr); } } -void Script::scriptExec(int argc, char *argv[]) { +void Script::scriptExec(int argc, const char **argv) { uint16 ep_num; - if (argc < 1) { - return; - } - - ep_num = atoi(argv[0]); + ep_num = atoi(argv[1]); if (_dbg_thread == NULL) { - _vm->_console->print("Creating debug thread..."); + _vm->_console->DebugPrintf("Creating debug thread...\n"); _dbg_thread = SThreadCreate(); if (_dbg_thread == NULL) { - _vm->_console->print("Thread creation failed."); + _vm->_console->DebugPrintf("Thread creation failed.\n"); return; } } if (ep_num >= currentScript()->bytecode->n_entrypoints) { - _vm->_console->print("Invalid entrypoint."); + _vm->_console->DebugPrintf("Invalid entrypoint.\n"); return; } SThreadExecute(_dbg_thread, ep_num); } -void CF_script_info(int argc, char *argv[], void *refCon) { - ((Script *)refCon)->scriptInfo(argc, argv); -} - -void CF_script_exec(int argc, char *argv[], void *refCon) { - ((Script *)refCon)->scriptExec(argc, argv); -} - -void CF_script_togglestep(int argc, char *argv[], void *refCon) { - ((Script *)refCon)->_dbg_singlestep = !((Script *)refCon)->_dbg_singlestep; +void Script::CF_script_togglestep() { + _dbg_singlestep = !_dbg_singlestep; } } // End of namespace Saga diff --git a/saga/script.h b/saga/script.h index b45c64e6fd..6777393c55 100644 --- a/saga/script.h +++ b/saga/script.h @@ -186,7 +186,8 @@ public: Script(); ~Script(); - int reg(void); + void CF_script_togglestep(); + int loadScript(int scriptNum); int freeScript(); SCRIPT_BYTECODE *loadBytecode(byte *bytecode_p, size_t bytecode_len); @@ -201,8 +202,8 @@ public: SCRIPT_DATABUF *dataBuffer(int idx) { return _dataBuf[idx]; } YS_DL_LIST *threadList() { return _threadList; } - void scriptInfo(int argc, char *argv[]); - void scriptExec(int argc, char *argv[]); + void scriptInfo(); + void scriptExec(int argc, const char **argv); protected: bool _initialized; diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp index 398d075e13..ade1c34114 100644 --- a/saga/sfuncs.cpp +++ b/saga/sfuncs.cpp @@ -219,7 +219,7 @@ int Script::SF_actorWalkTo(SCRIPTFUNC_PARAMS) { actor_id = _vm->_sdata->readWordS(actor_parm); actor_idx = _vm->_actor->getActorIndex(actor_id); if (actor_idx < 0) { - _vm->_console->print(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.", actor_id); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.\n", actor_id); return FAILURE; } @@ -262,7 +262,7 @@ int Script::SF_setFacing(SCRIPTFUNC_PARAMS) { orientation = _vm->_sdata->readWordS(orient_parm); actor_idx = _vm->_actor->getActorIndex(actor_id); if (actor_idx < 0) { - _vm->_console->print(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.", actor_id); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.\n", actor_id); return FAILURE; } @@ -468,7 +468,7 @@ int Script::SF_startAnim(SCRIPTFUNC_PARAMS) { anim_id = _vm->_sdata->readWordS(anim_id_parm); if (_vm->_anim->play(anim_id, 0) != SUCCESS) { - _vm->_console->print(S_WARN_PREFIX "SF.26: Anim::play() failed. Anim id: %u\n", anim_id); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.26: Anim::play() failed. Anim id: %u\n", anim_id); return FAILURE; } @@ -495,7 +495,7 @@ int Script::SF_actorWalkToAsync(SCRIPTFUNC_PARAMS) { actor_id = _vm->_sdata->readWordS(actor_parm); actor_idx = _vm->_actor->getActorIndex(actor_id); if (actor_idx < 0) { - _vm->_console->print(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.", + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.08: Actor id 0x%X not found.\n", actor_id); return FAILURE; } @@ -551,7 +551,7 @@ int Script::SF_moveTo(SCRIPTFUNC_PARAMS) { if (!_vm->_actor->actorExists(actor_id)) { result = _vm->_actor->create(actor_id, pt.x, pt.y); if (result != SUCCESS) { - _vm->_console->print(S_WARN_PREFIX "SF.30: Couldn't create actor 0x%X.", actor_id); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.30: Couldn't create actor 0x%X.\n", actor_id); return FAILURE; } } else { @@ -646,7 +646,7 @@ int Script::SF_actorWalk(SCRIPTFUNC_PARAMS) { actor_idx = _vm->_actor->getActorIndex(_vm->_sdata->readWordS(actor_parm)); if (actor_idx < 0) { - _vm->_console->print(S_WARN_PREFIX "SF.36: Actor id 0x%X not found.", (int)actor_parm); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.36: Actor id 0x%X not found.\n", (int)actor_parm); return FAILURE; } @@ -688,7 +688,7 @@ int Script::SF_cycleActorFrames(SCRIPTFUNC_PARAMS) { actor_idx = _vm->_actor->getActorIndex(actor_id); if (_vm->_actor->setAction(actor_idx, action, ACTION_NONE) != SUCCESS) { - _vm->_console->print(S_WARN_PREFIX "SF.37: Actor::setAction() failed."); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.37: Actor::setAction() failed.\n"); return FAILURE; } @@ -720,7 +720,7 @@ int Script::SF_setFrame(SCRIPTFUNC_PARAMS) { actor_idx = _vm->_actor->getActorIndex(actor_id); if (_vm->_actor->setAction(actor_idx, action, ACTION_NONE) != SUCCESS) { - _vm->_console->print(S_WARN_PREFIX "SF.38: Actor::setAction() failed."); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.38: Actor::setAction() failed.\n"); return FAILURE; } @@ -768,7 +768,7 @@ int Script::SF_linkAnim(SCRIPTFUNC_PARAMS) { anim_id2 = _vm->_sdata->readWordU(anim2_parm); if (_vm->_anim->link(anim_id1, anim_id2) != SUCCESS) { - _vm->_console->print(S_WARN_PREFIX "SF.41: Anim::link() failed. (%u->%u)\n", anim_id1, anim_id2); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.41: Anim::link() failed. (%u->%u)\n", anim_id1, anim_id2); return FAILURE; } @@ -824,7 +824,7 @@ int Script::SF_placeActor(SCRIPTFUNC_PARAMS) { if (!_vm->_actor->actorExists(actor_id)) { result = _vm->_actor->create(actor_id, pt.x, pt.y); if (result != SUCCESS) { - _vm->_console->print(S_WARN_PREFIX "SF.43: Couldn't create actor 0x%X.", actor_id); + _vm->_console->DebugPrintf(S_WARN_PREFIX "SF.43: Couldn't create actor 0x%X.\n", actor_id); return FAILURE; } } else { diff --git a/saga/sthread.cpp b/saga/sthread.cpp index cd9b3d722f..e6fed99bff 100644 --- a/saga/sthread.cpp +++ b/saga/sthread.cpp @@ -383,7 +383,7 @@ int Script::SThreadRun(SCRIPT_THREAD *thread, int instr_limit) { n_args = scriptS.readByte(); func_num = scriptS.readUint16LE(); if (func_num >= SFUNC_NUM) { - _vm->_console->print(S_ERROR_PREFIX "Invalid script function number: (%X)\n", func_num); + _vm->_console->DebugPrintf(S_ERROR_PREFIX "Invalid script function number: (%X)\n", func_num); thread->flags |= kTFlagAborted; break; } @@ -391,7 +391,7 @@ int Script::SThreadRun(SCRIPT_THREAD *thread, int instr_limit) { sfunc = _SFuncList[func_num]; sfuncRetVal = (this->*sfunc)(thread, n_args); if (sfuncRetVal != SUCCESS) { - _vm->_console->print(S_WARN_PREFIX "%X: Script function %d failed.\n", thread->i_offset, func_num); + _vm->_console->DebugPrintf(S_WARN_PREFIX "%X: Script function %d failed.\n", thread->i_offset, func_num); } if (func_num == 16) { // SF_gotoScene @@ -419,7 +419,7 @@ int Script::SThreadRun(SCRIPT_THREAD *thread, int instr_limit) { thread->stackPtr = thread->framePtr; setFramePtr(thread, thread->pop()); if (thread->stackSize() == 0) { - _vm->_console->print("Script execution complete."); + _vm->_console->DebugPrintf("Script execution complete.\n"); thread->flags |= kTFlagFinished; } else { thread->i_offset = thread->pop(); @@ -519,7 +519,7 @@ int Script::SThreadRun(SCRIPT_THREAD *thread, int instr_limit) { } } if (!branch_found) { - _vm->_console->print(S_ERROR_PREFIX "%X: Random jump target out of " "bounds.", thread->i_offset); + _vm->_console->DebugPrintf(S_ERROR_PREFIX "%X: Random jump target out of bounds.\n", thread->i_offset); } } break; @@ -757,7 +757,7 @@ int Script::SThreadRun(SCRIPT_THREAD *thread, int instr_limit) { a_index = _vm->_actor->getActorIndex(param1); if (a_index < 0) { - _vm->_console->print(S_WARN_PREFIX "%X: DLGP Actor id not found.", thread->i_offset); + _vm->_console->DebugPrintf(S_WARN_PREFIX "%X: DLGP Actor id not found.\n", thread->i_offset); } for (i = 0; i < n_voices; i++) { @@ -804,7 +804,7 @@ int Script::SThreadRun(SCRIPT_THREAD *thread, int instr_limit) { default: - _vm->_console->print(S_ERROR_PREFIX "%X: Invalid opcode encountered: " "(%X).\n", thread->i_offset, in_char); + _vm->_console->DebugPrintf(S_ERROR_PREFIX "%X: Invalid opcode encountered: (%X).\n", thread->i_offset, in_char); thread->flags |= kTFlagAborted; break; } @@ -816,7 +816,7 @@ int Script::SThreadRun(SCRIPT_THREAD *thread, int instr_limit) { scriptS.seek(thread->i_offset); } if (unhandled) { - _vm->_console->print(S_ERROR_PREFIX "%X: Unhandled opcode.\n", thread->i_offset); + _vm->_console->DebugPrintf(S_ERROR_PREFIX "%X: Unhandled opcode.\n", thread->i_offset); thread->flags |= kTFlagAborted; } if ((thread->flags == kTFlagNone) && debug_print) { |