diff options
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/console.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/said.cpp | 1 | ||||
-rw-r--r-- | engines/sci/engine/said.y | 1 | ||||
-rw-r--r-- | engines/sci/engine/scriptconsole.cpp | 3 | ||||
-rw-r--r-- | engines/sci/sci.cpp | 2 | ||||
-rw-r--r-- | engines/sci/scicore/sciconsole.cpp | 57 | ||||
-rw-r--r-- | engines/sci/scicore/sciconsole.h | 11 |
7 files changed, 28 insertions, 51 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index b5584dfc3b..5aef1919f1 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -34,6 +34,7 @@ namespace Sci { extern EngineState *g_EngineState; +extern bool g_redirect_sciprintf_to_gui; class ConsoleFunc : public Common::Functor2<int, const char **, bool> { public: @@ -48,7 +49,10 @@ public: tmp += ' '; tmp += argv[i]; } + g_redirect_sciprintf_to_gui = true; con_parse(g_EngineState, tmp.c_str()); + sciprintf("\n"); + g_redirect_sciprintf_to_gui = false; return true; #else diff --git a/engines/sci/engine/said.cpp b/engines/sci/engine/said.cpp index 7ed7999baa..f261454b55 100644 --- a/engines/sci/engine/said.cpp +++ b/engines/sci/engine/said.cpp @@ -2472,7 +2472,6 @@ int said(EngineState *s, byte *spec, int verbose) { int main (int argc, char *argv) { byte block[] = {0x01, 0x00, 0xf8, 0xf5, 0x02, 0x01, 0xf6, 0xf2, 0x02, 0x01, 0xf2, 0x01, 0x03, 0xff}; EngineState s; - con_passthrough = true; s.parser_valid = 1; said(&s, block); diff --git a/engines/sci/engine/said.y b/engines/sci/engine/said.y index 408d3971d1..6924da16e0 100644 --- a/engines/sci/engine/said.y +++ b/engines/sci/engine/said.y @@ -828,7 +828,6 @@ int said(EngineState *s, byte *spec, int verbose) { int main (int argc, char *argv) { byte block[] = {0x01, 0x00, 0xf8, 0xf5, 0x02, 0x01, 0xf6, 0xf2, 0x02, 0x01, 0xf2, 0x01, 0x03, 0xff}; EngineState s; - con_passthrough = true; s.parser_valid = 1; said(&s, block); diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp index 80993ae4db..5b37671eb9 100644 --- a/engines/sci/engine/scriptconsole.cpp +++ b/engines/sci/engine/scriptconsole.cpp @@ -30,7 +30,6 @@ #include "sci/engine/state.h" #include "sci/scicore/sciconsole.h" - #include "sci/sci.h" // For _console only #include "sci/console.h" // For _console only @@ -201,8 +200,6 @@ void con_init() { " a list of addresses and indices is provided.\n" " ?obj.idx may be used to disambiguate 'obj'\n" " by the index 'idx'.\n"); - - con_hook_int(&con_passthrough, "con_passthrough", "scicon->stdout passthrough"); } } diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 855803c889..3359ed9898 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -78,8 +78,6 @@ static void init_console() { "SCI0 palette- 0: EGA, 1:AGI/Amiga, 2:Grayscale\n"); con_hook_int(&sci01_priority_table_flags, "sci01_priority_table_flags", "SCI01 priority table debugging flags: 1:Disable, 2:Print on change\n"); - - con_passthrough = true; // enables all sciprintf data to be sent to stdout } static int init_gamestate(EngineState *gamestate, sci_version_t version) { diff --git a/engines/sci/scicore/sciconsole.cpp b/engines/sci/scicore/sciconsole.cpp index 0f5ea18017..863bf990b1 100644 --- a/engines/sci/scicore/sciconsole.cpp +++ b/engines/sci/scicore/sciconsole.cpp @@ -30,55 +30,46 @@ #include "sci/engine/state.h" #include "sci/scicore/sciconsole.h" +#include "sci/sci.h" // For _console only +#include "sci/console.h" // For _console only + namespace Sci { #ifdef SCI_CONSOLE -int con_passthrough = false; - -static void (*_con_string_callback)(char*) = NULL; static void (*_con_pixmap_callback)(gfx_pixmap_t *) = NULL; +bool g_redirect_sciprintf_to_gui = false; + int sciprintf(const char *fmt, ...) { va_list argp; - int bufsize = 256; - int i; - char *buf = (char *)sci_malloc(bufsize); - if (NULL == fmt) { - fprintf(stderr, "console.c: sciprintf(): NULL passed for parameter fmt\n"); - return -1; - } - - if (NULL == buf) { - fprintf(stderr, "console.c: sciprintf(): malloc failed for buf\n"); - return -1; - } + assert(fmt); + // First determine how big a buffer we need va_start(argp, fmt); - while ((i = vsnprintf(buf, bufsize - 1, fmt, argp)) == -1 || (i >= bufsize - 2)) { - // while we're out of space... - va_end(argp); - va_start(argp, fmt); // reset argp - - free(buf); - buf = (char *)sci_malloc(bufsize <<= 1); - } + int bufsize = vsnprintf(0, 0, fmt, argp); + assert(bufsize >= 0); va_end(argp); - if (con_passthrough) - printf("%s", buf); + // Allocate buffer for the full printed string + char *buf = (char *)sci_malloc(bufsize + 1); + assert(buf); - if (_con_string_callback) - _con_string_callback(buf); - else - free(buf); + // Print everything according to fmt into buf + va_start(argp, fmt); // reset argp + int bufsize2 = vsnprintf(buf, bufsize + 1, fmt, argp); + assert(bufsize == bufsize2); + va_end(argp); - return 1; -} + // Display the result suitably + if (g_redirect_sciprintf_to_gui) + ((SciEngine *)g_engine)->_console->DebugPrintf("%s", buf); + printf("%s", buf); -void con_set_string_callback(void(*callback)(char *)) { - _con_string_callback = callback; + free(buf); + + return 1; } void con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *)) { diff --git a/engines/sci/scicore/sciconsole.h b/engines/sci/scicore/sciconsole.h index b483dfb8a4..e4fc867e10 100644 --- a/engines/sci/scicore/sciconsole.h +++ b/engines/sci/scicore/sciconsole.h @@ -43,9 +43,6 @@ namespace Sci { struct gfx_pixmap_t; -/** If this flag is set, we echo all sciprintf() stuff to the text console. */ -extern int con_passthrough; - union cmd_param_t { int32 val; const char *str; @@ -57,14 +54,6 @@ typedef int (*ConCommand)(EngineState *s, const Common::Array<cmd_param_t> &cmdP /*** FUNCTION DEFINITIONS ***/ -void con_set_string_callback(void(*callback)(char *)); -/* Sets the console string callback -** Parameters: (void -> char *) callback: The closure to invoke after -** a string for sciprintf() has been generated -** This sets a single callback function to be used after sciprintf() -** is used. -*/ - void con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *)); /* Sets the console pixmap callback ** Parameters: (void -> gfx_pixmap_t *) callback: The closure to invoke after |