Fix for bug #1091748 (DIG: Starting new games takes a long time); turns out querying the debuglevel from the config-manager very often is too slow

svn-id: r16345
This commit is contained in:
Max Horn 2004-12-27 21:54:20 +00:00
parent 2eb17ef322
commit d138a880bf
6 changed files with 59 additions and 49 deletions

View File

@ -158,50 +158,6 @@ void CDECL warning(const char *s, ...) {
#endif #endif
} }
static void debugHelper(char *buf) {
#ifndef _WIN32_WCE
printf("%s\n", buf);
#endif
#if defined( USE_WINDBG )
strcat(buf, "\n");
#if defined( _WIN32_WCE )
TCHAR buf_unicode[1024];
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
OutputDebugString(buf_unicode);
#else
OutputDebugString(buf);
#endif
#endif
fflush(stdout);
}
void CDECL debug(int level, const char *s, ...) {
char buf[STRINGBUFLEN];
va_list va;
if (level > ConfMan.getInt("debuglevel"))
return;
va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
debugHelper(buf);
}
void CDECL debug(const char *s, ...) {
char buf[STRINGBUFLEN];
va_list va;
va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
debugHelper(buf);
}
void checkHeap() { void checkHeap() {
#if defined(_MSC_VER) #if defined(_MSC_VER)
if (_heapchk() != _HEAPOK) { if (_heapchk() != _HEAPOK) {

View File

@ -333,9 +333,9 @@ void GameDetector::parseCommandLine(int argc, char **argv) {
DO_OPTION_OPT('d', "debuglevel") DO_OPTION_OPT('d', "debuglevel")
if (option != NULL) if (option != NULL)
ConfMan.set("debuglevel", (int)strtol(option, 0, 10), kTransientDomain); ConfMan.set("debuglevel", (int)strtol(option, 0, 10), kTransientDomain);
int debuglevel = ConfMan.getInt("debuglevel"); gDebugLevel = ConfMan.getInt("debuglevel");
if (debuglevel) if (gDebugLevel)
printf("Debuglevel (from command line): %d\n", debuglevel); printf("Debuglevel (from command line): %d\n", gDebugLevel);
else else
printf("Debuglevel (from command line): 0 - Game only\n"); printf("Debuglevel (from command line): 0 - Game only\n");
END_OPTION END_OPTION
@ -510,6 +510,7 @@ ShowHelpAndExit:
void GameDetector::setTarget(const String &name) { void GameDetector::setTarget(const String &name) {
_targetName = name; _targetName = name;
ConfMan.setActiveDomain(name); ConfMan.setActiveDomain(name);
gDebugLevel = ConfMan.getInt("debuglevel");
} }
bool GameDetector::detectGame() { bool GameDetector::detectGame() {

View File

@ -38,6 +38,8 @@ enum {
GF_DEFAULT_TO_1X_SCALER = 1 << 30 GF_DEFAULT_TO_1X_SCALER = 1 << 30
}; };
extern int gDebugLevel;
struct GameSettings { struct GameSettings {
const char *name; const char *name;
const char *description; const char *description;

View File

@ -119,7 +119,7 @@ const char *gScummVMFeatures = ""
#ifdef USE_MPEG2 #ifdef USE_MPEG2
"MPEG2 " "MPEG2 "
#endif #endif
; ;
#if defined(WIN32) && defined(NO_CONSOLE) #if defined(WIN32) && defined(NO_CONSOLE)
#include <cstdio> #include <cstdio>
@ -184,6 +184,9 @@ static void do_memory_test(void) {
#endif #endif
int gDebugLevel = 0;
static bool launcherDialog(GameDetector &detector, OSystem *system) { static bool launcherDialog(GameDetector &detector, OSystem *system) {
system->beginGFXTransaction(); system->beginGFXTransaction();
@ -349,6 +352,8 @@ extern "C" int scummvm_main(GameDetector &detector, int argc, char *argv[]) {
else else
ConfMan.loadDefaultConfigFile(); ConfMan.loadDefaultConfigFile();
gDebugLevel = ConfMan.getInt("debuglevel");
// Update the config file // Update the config file
ConfMan.set("versioninfo", gScummVMVersion, Common::ConfigManager::kApplicationDomain); ConfMan.set("versioninfo", gScummVMVersion, Common::ConfigManager::kApplicationDomain);
@ -417,6 +422,50 @@ extern "C" int scummvm_main(GameDetector &detector, int argc, char *argv[]) {
END_OF_MAIN(); END_OF_MAIN();
#endif #endif
static void debugHelper(char *buf) {
#ifndef _WIN32_WCE
printf("%s\n", buf);
#endif
#if defined( USE_WINDBG )
strcat(buf, "\n");
#if defined( _WIN32_WCE )
TCHAR buf_unicode[1024];
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
OutputDebugString(buf_unicode);
#else
OutputDebugString(buf);
#endif
#endif
fflush(stdout);
}
void CDECL debug(int level, const char *s, ...) {
char buf[STRINGBUFLEN];
va_list va;
if (level > gDebugLevel)
return;
va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
debugHelper(buf);
}
void CDECL debug(const char *s, ...) {
char buf[STRINGBUFLEN];
va_list va;
va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
debugHelper(buf);
}
/* /*
#if !defined(__PALM_OS__) && !defined(_WIN32_WCE) #if !defined(__PALM_OS__) && !defined(_WIN32_WCE)
void *operator new(size_t size) { void *operator new(size_t size) {

View File

@ -44,7 +44,7 @@ void CDECL debugC(int channel, const char *s, ...) {
// FIXME: Still spew all debug at -d9, for crashes in startup etc. // FIXME: Still spew all debug at -d9, for crashes in startup etc.
// Add setting from commandline ( / abstract channel interface) // Add setting from commandline ( / abstract channel interface)
if (!(g_scumm->_debugFlags & channel) && (ConfMan.getInt("debuglevel") < 9)) if (!(g_scumm->_debugFlags & channel) && (gDebugLevel < 9))
return; return;
va_start(va, s); va_start(va, s);
@ -596,6 +596,7 @@ bool ScummDebugger::Cmd_DebugLevel(int argc, const char **argv) {
} else { // set level } else { // set level
int level = atoi(argv[1]); int level = atoi(argv[1]);
ConfMan.set("debuglevel", level, Common::ConfigManager::kTransientDomain); ConfMan.set("debuglevel", level, Common::ConfigManager::kTransientDomain);
gDebugLevel = ConfMan.getInt("debuglevel");
if (level > 0) { if (level > 0) {
_vm->_debugMode = true; _vm->_debugMode = true;
DebugPrintf("Debug level set to level %d\n", level); DebugPrintf("Debug level set to level %d\n", level);

View File

@ -91,6 +91,7 @@ bool Debugger::Cmd_DebugLevel(int argc, const char **argv) {
} else { // set level } else { // set level
int level = atoi(argv[1]); int level = atoi(argv[1]);
ConfMan.set("debuglevel", level, Common::ConfigManager::kTransientDomain); ConfMan.set("debuglevel", level, Common::ConfigManager::kTransientDomain);
gDebugLevel = ConfMan.getInt("debuglevel");
if (level > 0 && level < 10) { if (level > 0 && level < 10) {
_vm->_debugMode = true; _vm->_debugMode = true;
DebugPrintf("Debug level set to level %d\n", level); DebugPrintf("Debug level set to level %d\n", level);