Added OSystem::logMessage(), which abstracts the logging of messages to

an outputstream.  For now, the output simply goes to stdout or stderr,
just like before, but the possibility is now there to redirect to a
file if desired.

Changed 'showinfo' commandline option to accept 'levels' of output
instead of simply being a boolean.  The new default is level 1,
in which normal messages are output during a run.  Level 2 will
show more detailed info, and may be useful in debugging end-user
problems.  There's still more work to do wrt level 2.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2029 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2010-04-29 12:46:07 +00:00
parent f8adf5c314
commit 5de12952ec
13 changed files with 179 additions and 140 deletions

View File

@ -830,8 +830,8 @@
</tr>
<tr>
<td><pre>-showinfo &lt;1|0&gt;</pre></td>
<td>Shows some game info on the commandline while Stella is running.</td>
<td><pre>-showinfo &lt;0|1|2&gt;</pre></td>
<td>Shows some application & game info on the commandline while Stella is running. Zero completely disables output (except for serious errors), while the remaining numbers show increasingly more detail.</td>
</tr>
<tr>

View File

@ -56,7 +56,7 @@ bool FrameBufferSoft::initSubsystem(VideoMode& mode)
if(!myRectList)
{
cerr << "ERROR: Unable to get memory for SDL rects" << endl;
myOSystem->logMessage("ERROR: Unable to get memory for SDL rects\n", 0);
return false;
}
@ -96,7 +96,9 @@ bool FrameBufferSoft::setVidMode(VideoMode& mode)
myScreen = SDL_SetVideoMode(mode.screen_w, mode.screen_h, 0, mySDLFlags);
if(myScreen == NULL)
{
cerr << "ERROR: Unable to open SDL window: " << SDL_GetError() << endl;
ostringstream buf;
buf << "ERROR: Unable to open SDL window: " << SDL_GetError() << endl;
myOSystem->logMessage(buf.str(), 0);
return false;
}
myFormat = myScreen->format;

View File

@ -27,9 +27,7 @@
SoundNull::SoundNull(OSystem* osystem)
: Sound(osystem)
{
// Show some info
if(myOSystem->settings().getBool("showinfo"))
cout << "Sound disabled." << endl << endl;
myOSystem->logMessage("Sound disabled.\n\n", 1);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -67,8 +67,7 @@ void SoundSDL::open()
if(!myIsEnabled)
{
close();
if(myOSystem->settings().getBool("showinfo"))
cout << "Sound disabled." << endl << endl;
myOSystem->logMessage("Sound disabled.\n\n", 1);
return;
}
@ -82,10 +81,12 @@ void SoundSDL::open()
myIsMuted = false;
myLastRegisterSetCycle = 0;
ostringstream buf;
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
{
cerr << "WARNING: Couldn't initialize SDL audio system! " << endl;
cerr << " " << SDL_GetError() << endl;
buf << "WARNING: Couldn't initialize SDL audio system! " << endl
<< " " << SDL_GetError() << endl;
myOSystem->logMessage(buf.str(), 0);
return;
}
else
@ -108,8 +109,9 @@ void SoundSDL::open()
if(SDL_OpenAudio(&desired, &myHardwareSpec) < 0)
{
cerr << "WARNING: Couldn't open SDL audio system! " << endl;
cerr << " " << SDL_GetError() << endl;
buf << "WARNING: Couldn't open SDL audio system! " << endl
<< " " << SDL_GetError() << endl;
myOSystem->logMessage(buf.str(), 0);
return;
}
@ -117,9 +119,10 @@ void SoundSDL::open()
// will not work so we'll need to disable the audio support)
if(((float)myHardwareSpec.samples / (float)myHardwareSpec.freq) >= 0.25)
{
cerr << "WARNING: Sound device doesn't support realtime audio! Make ";
cerr << "sure a sound" << endl;
cerr << " server isn't running. Audio is disabled." << endl;
buf << "WARNING: Sound device doesn't support realtime audio! Make "
<< "sure a sound" << endl
<< " server isn't running. Audio is disabled." << endl;
myOSystem->logMessage(buf.str(), 0);
SDL_CloseAudio();
return;
@ -129,15 +132,6 @@ void SoundSDL::open()
myIsMuted = false;
myFragmentSizeLogBase2 = log((double)myHardwareSpec.samples) / log(2.0);
/*
cerr << "Freq: " << (int)myHardwareSpec.freq << endl;
cerr << "Format: " << (int)myHardwareSpec.format << endl;
cerr << "Channels: " << (int)myHardwareSpec.channels << endl;
cerr << "Silence: " << (int)myHardwareSpec.silence << endl;
cerr << "Samples: " << (int)myHardwareSpec.samples << endl;
cerr << "Size: " << (int)myHardwareSpec.size << endl;
*/
// Now initialize the TIASound object which will actually generate sound
myTIASound.outputFrequency(myHardwareSpec.freq);
myTIASound.tiaFrequency(tiafreq);
@ -151,15 +145,16 @@ void SoundSDL::open()
setVolume(myVolume);
// Show some info
if(myOSystem->settings().getBool("showinfo"))
cout << "Sound enabled:" << endl
<< " Volume : " << myVolume << endl
<< " Frag size : " << fragsize << endl
<< " Frequency : " << myHardwareSpec.freq << endl
<< " Format : " << myHardwareSpec.format << endl
<< " TIA Freq. : " << tiafreq << endl
<< " Channels : " << myNumChannels << endl
<< " Clip volume: " << (int)clipvol << endl << endl;
buf << "Sound enabled:" << endl
<< " Volume: " << myVolume << endl
<< " Frag size: " << fragsize << endl
<< " Frequency: " << myHardwareSpec.freq << endl
<< " Format: " << myHardwareSpec.format << endl
<< " TIA Freq: " << tiafreq << endl
<< " Channels: " << myNumChannels << endl
<< " Clip volume: " << (int)clipvol << endl
<< endl;
myOSystem->logMessage(buf.str(), 1);
}
}
@ -321,7 +316,6 @@ void SoundSDL::processFragment(uInt8* stream, Int32 length)
myTIASound.set(info.addr, info.value);
myRegWriteQueue.dequeue();
}
// cout << "Removed Items from RegWriteQueue!" << endl;
}
double position = 0.0;
@ -431,7 +425,9 @@ bool SoundSDL::save(Serializer& out) const
}
catch(const char* msg)
{
cerr << "ERROR: SoundSDL::save" << endl << " " << msg << endl;
ostringstream buf;
buf << "ERROR: SoundSDL::save" << endl << " " << msg << endl;
myOSystem->logMessage(buf.str(), 0);
return false;
}
@ -475,7 +471,9 @@ bool SoundSDL::load(Serializer& in)
}
catch(const char* msg)
{
cerr << "ERROR: SoundSDL::load" << endl << " " << msg << endl;
ostringstream buf;
buf << "ERROR: SoundSDL::load" << endl << " " << msg << endl;
myOSystem->logMessage(buf.str(), 0);
return false;
}

View File

@ -22,7 +22,7 @@
#include <cstdlib>
#define STELLA_VERSION "3.1.1"
#define STELLA_VERSION "3.2_svn"
#define STELLA_BUILD atoi("$Rev$"+6)
#endif

View File

@ -65,6 +65,8 @@ OSystem* theOSystem = (OSystem*) NULL;
// Does general Cleanup in case any operation failed (or at end of program)
int Cleanup()
{
theOSystem->logMessage("Cleanup from mainSDL\n", 2);
if(theOSystem)
delete theOSystem;
@ -99,21 +101,25 @@ int main(int argc, char* argv[])
#error Unsupported platform!
#endif
theOSystem->logMessage("Loading config options ...\n", 2);
theOSystem->settings().loadConfig();
// Take care of commandline arguments
theOSystem->logMessage("Loading commandline arguments ...\n", 2);
string romfile = theOSystem->settings().loadCommandLine(argc, argv);
FilesystemNode romnode(romfile);
// Finally, make sure the settings are valid
// We do it once here, so the rest of the program can assume valid settings
theOSystem->logMessage("Validating config options ...\n", 2);
theOSystem->settings().validate();
// Create the full OSystem after the settings, since settings are
// probably needed for defaults
theOSystem->logMessage("Creating the OSystem ...\n", 2);
if(!theOSystem->create())
{
cout << "ERROR: Couldn't create OSystem" << endl;
theOSystem->logMessage("ERROR: Couldn't create OSystem\n", 0);
return Cleanup();
}
@ -122,20 +128,23 @@ int main(int argc, char* argv[])
// If so, show the information and immediately exit
if(theOSystem->settings().getBool("listrominfo"))
{
theOSystem->logMessage("Showing output from 'listrominfo' ...\n", 2);
theOSystem->propSet().print();
return Cleanup();
}
else if(theOSystem->settings().getBool("rominfo"))
{
theOSystem->logMessage("Showing output from 'rominfo' ...\n", 2);
if(argc > 1 && romnode.exists())
cout << theOSystem->getROMInfo(romfile);
theOSystem->logMessage(theOSystem->getROMInfo(romfile), 0);
else
cout << "ERROR: ROM doesn't exist" << endl;
theOSystem->logMessage("ERROR: ROM doesn't exist\n", 0);
return Cleanup();
}
else if(theOSystem->settings().getBool("help"))
{
theOSystem->logMessage("Displaying usage\n", 2);
theOSystem->settings().usage();
return Cleanup();
}
@ -160,6 +169,7 @@ int main(int argc, char* argv[])
// mode and let the main event loop take care of opening a new console/ROM.
if(argc == 1 || romfile == "" || !romnode.exists() || romnode.isDirectory())
{
theOSystem->logMessage("Attempting to use ROM launcher ...\n", 2);
if(theOSystem->settings().getBool("uselauncher"))
{
if(!theOSystem->createLauncher())
@ -167,6 +177,7 @@ int main(int argc, char* argv[])
}
else
{
theOSystem->logMessage("Launcher could not be started, showing usage\n", 2);
theOSystem->settings().usage();
return Cleanup();
}
@ -175,6 +186,7 @@ int main(int argc, char* argv[])
{
if(theOSystem->settings().getBool("takesnapshot"))
{
theOSystem->logMessage("Taking snapshots with 'takesnapshot' ...\n", 2);
for(int i = 0; i < 30; ++i) theOSystem->frameBuffer().update();
theOSystem->eventHandler().takeSnapshot();
return Cleanup();
@ -205,7 +217,9 @@ int main(int argc, char* argv[])
while(SDL_PollEvent(&event)) /* swallow event */ ;
// Start the main loop, and don't exit until the user issues a QUIT command
theOSystem->logMessage("Starting main loop ...\n", 2);
theOSystem->mainLoop();
theOSystem->logMessage("Finished main loop ...\n", 2);
// Cleanup time ...
return Cleanup();

View File

@ -177,8 +177,6 @@ void EventHandler::reset(State state)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setupJoysticks()
{
bool showinfo = myOSystem->settings().getBool("showinfo");
#ifdef JOYSTICK_SUPPORT
// Keep track of how many Stelladaptors we've found
int saCount = 0;
@ -198,12 +196,10 @@ void EventHandler::setupJoysticks()
}
// (Re)-Initialize the joystick subsystem
if(showinfo)
cout << "Joystick devices found:" << endl;
myOSystem->logMessage("Joystick devices found:\n", 1);
if((SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) || (SDL_NumJoysticks() <= 0))
{
if(showinfo)
cout << "No joysticks present." << endl;
myOSystem->logMessage("No joysticks present.\n\n", 1);
return;
}
@ -224,6 +220,7 @@ void EventHandler::setupJoysticks()
}
// Figure out what type of joystick this is
ostringstream buf;
if(name.find("Stelladaptor", 0) != string::npos)
{
saCount++;
@ -234,33 +231,31 @@ void EventHandler::setupJoysticks()
else if(saCount == 2)
ourJoysticks[i].name = "Stelladaptor 2";
if(showinfo)
cout << " " << i << ": " << ourJoysticks[i].name << endl;
buf << " " << i << ": " << ourJoysticks[i].name << endl;
myOSystem->logMessage(buf.str(), 1);
}
else
{
ourJoysticks[i].type = JT_REGULAR;
ourJoysticks[i].name = SDL_JoystickName(i);
if(showinfo)
cout << " " << i << ": " << ourJoysticks[i].name << " with "
<< SDL_JoystickNumAxes(ourJoysticks[i].stick) << " axes, "
<< SDL_JoystickNumHats(ourJoysticks[i].stick) << " hats, "
<< SDL_JoystickNumBalls(ourJoysticks[i].stick) << " balls, "
<< SDL_JoystickNumButtons(ourJoysticks[i].stick) << " buttons"
<< endl;
buf << " " << i << ": " << ourJoysticks[i].name << " with "
<< SDL_JoystickNumAxes(ourJoysticks[i].stick) << " axes, "
<< SDL_JoystickNumHats(ourJoysticks[i].stick) << " hats, "
<< SDL_JoystickNumBalls(ourJoysticks[i].stick) << " balls, "
<< SDL_JoystickNumButtons(ourJoysticks[i].stick) << " buttons"
<< endl;
myOSystem->logMessage(buf.str(), 1);
}
}
if(showinfo)
cout << endl;
myOSystem->logMessage("\n", 1);
// Map the stelladaptors we've found according to the specified ports
const string& sa1 = myOSystem->settings().getString("sa1");
const string& sa2 = myOSystem->settings().getString("sa2");
mapStelladaptors(sa1, sa2);
#else
if(showinfo)
cout << "No joysticks present." << endl;
myOSystem->logMessage("No joysticks present.\n", 1);
#endif
}
@ -268,8 +263,6 @@ void EventHandler::setupJoysticks()
void EventHandler::mapStelladaptors(const string& sa1, const string& sa2)
{
#ifdef JOYSTICK_SUPPORT
bool showinfo = myOSystem->settings().getBool("showinfo");
for(int i = 0; i < kNumJoysticks; i++)
{
if(ourJoysticks[i].name == "Stelladaptor 1")
@ -277,14 +270,12 @@ void EventHandler::mapStelladaptors(const string& sa1, const string& sa2)
if(sa1 == "left")
{
ourJoysticks[i].type = JT_STELLADAPTOR_LEFT;
if(showinfo)
cout << " Stelladaptor 1 emulates left joystick port\n";
myOSystem->logMessage(" Stelladaptor 1 emulates left joystick port\n", 1);
}
else if(sa1 == "right")
{
ourJoysticks[i].type = JT_STELLADAPTOR_RIGHT;
if(showinfo)
cout << " Stelladaptor 1 emulates right joystick port\n";
myOSystem->logMessage(" Stelladaptor 1 emulates right joystick port\n", 1);
}
}
else if(ourJoysticks[i].name == "Stelladaptor 2")
@ -292,19 +283,16 @@ void EventHandler::mapStelladaptors(const string& sa1, const string& sa2)
if(sa2 == "left")
{
ourJoysticks[i].type = JT_STELLADAPTOR_LEFT;
if(showinfo)
cout << " Stelladaptor 2 emulates left joystick port\n";
myOSystem->logMessage(" Stelladaptor 2 emulates left joystick port\n", 1);
}
else if(sa2 == "right")
{
ourJoysticks[i].type = JT_STELLADAPTOR_RIGHT;
if(showinfo)
cout << " Stelladaptor 2 emulates right joystick port\n";
myOSystem->logMessage(" Stelladaptor 2 emulates right joystick port\n", 1);
}
}
}
if(showinfo)
cout << endl;
myOSystem->logMessage("\n", 1);
myOSystem->settings().setString("sa1", sa1);
myOSystem->settings().setString("sa2", sa2);

View File

@ -68,13 +68,16 @@ FrameBuffer::~FrameBuffer(void)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FrameBuffer::initialize(const string& title, uInt32 width, uInt32 height)
{
ostringstream buf;
// Now (re)initialize the SDL video system
// These things only have to be done one per FrameBuffer creation
if(SDL_WasInit(SDL_INIT_VIDEO) == 0)
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
{
cerr << "ERROR: Couldn't initialize SDL: " << SDL_GetError() << endl;
buf << "ERROR: Couldn't initialize SDL: " << SDL_GetError() << endl;
myOSystem->logMessage(buf.str(), 0);
return false;
}
}
@ -108,7 +111,7 @@ bool FrameBuffer::initialize(const string& title, uInt32 width, uInt32 height)
if(!initSubsystem(mode))
{
cerr << "ERROR: Couldn't initialize video subsystem" << endl;
myOSystem->logMessage("ERROR: Couldn't initialize video subsystem\n", 0);
return false;
}
else
@ -155,8 +158,8 @@ bool FrameBuffer::initialize(const string& title, uInt32 width, uInt32 height)
// Finally, show some information about the framebuffer,
// but only on the first initialization
if(myInitializedCount == 1 && myOSystem->settings().getBool("showinfo"))
cout << about() << endl;
if(myInitializedCount == 1)
myOSystem->logMessage(about() + "\n", 1);
return true;
}
@ -757,7 +760,7 @@ void FrameBuffer::setWindowIcon()
sscanf(stella_icon[0], "%u %u %u %u", &w, &h, &ncols, &nbytes);
if((w != 32) || (h != 32) || (ncols > 255) || (nbytes > 1))
{
cerr << "ERROR: Couldn't load the icon.\n";
myOSystem->logMessage("ERROR: Couldn't load the application icon.\n", 0);
return;
}
@ -779,7 +782,7 @@ void FrameBuffer::setWindowIcon()
}
else
{
cerr << "ERROR: Couldn't load the icon.\n";
myOSystem->logMessage("ERROR: Couldn't load the application icon.\n", 0);
return;
}
rgba[code] = col;

View File

@ -123,33 +123,35 @@ OSystem::OSystem()
#if 0
// Debugging info for the GUI widgets
cerr << " kStaticTextWidget = " << kStaticTextWidget << endl;
cerr << " kEditTextWidget = " << kEditTextWidget << endl;
cerr << " kButtonWidget = " << kButtonWidget << endl;
cerr << " kCheckboxWidget = " << kCheckboxWidget << endl;
cerr << " kSliderWidget = " << kSliderWidget << endl;
cerr << " kListWidget = " << kListWidget << endl;
cerr << " kScrollBarWidget = " << kScrollBarWidget << endl;
cerr << " kPopUpWidget = " << kPopUpWidget << endl;
cerr << " kTabWidget = " << kTabWidget << endl;
cerr << " kEventMappingWidget = " << kEventMappingWidget << endl;
cerr << " kEditableWidget = " << kEditableWidget << endl;
cerr << " kAudioWidget = " << kAudioWidget << endl;
cerr << " kColorWidget = " << kColorWidget << endl;
cerr << " kCpuWidget = " << kCpuWidget << endl;
cerr << " kDataGridOpsWidget = " << kDataGridOpsWidget << endl;
cerr << " kDataGridWidget = " << kDataGridWidget << endl;
cerr << " kPromptWidget = " << kPromptWidget << endl;
cerr << " kRamWidget = " << kRamWidget << endl;
cerr << " kRomListWidget = " << kRomListWidget << endl;
cerr << " kRomWidget = " << kRomWidget << endl;
cerr << " kTiaInfoWidget = " << kTiaInfoWidget << endl;
cerr << " kTiaOutputWidget = " << kTiaOutputWidget << endl;
cerr << " kTiaWidget = " << kTiaWidget << endl;
cerr << " kTiaZoomWidget = " << kTiaZoomWidget << endl;
cerr << " kToggleBitWidget = " << kToggleBitWidget << endl;
cerr << " kTogglePixelWidget = " << kTogglePixelWidget << endl;
cerr << " kToggleWidget = " << kToggleWidget << endl;
ostringstream buf;
buf << " kStaticTextWidget = " << kStaticTextWidget << endl
<< " kEditTextWidget = " << kEditTextWidget << endl
<< " kButtonWidget = " << kButtonWidget << endl
<< " kCheckboxWidget = " << kCheckboxWidget << endl
<< " kSliderWidget = " << kSliderWidget << endl
<< " kListWidget = " << kListWidget << endl
<< " kScrollBarWidget = " << kScrollBarWidget << endl
<< " kPopUpWidget = " << kPopUpWidget << endl
<< " kTabWidget = " << kTabWidget << endl
<< " kEventMappingWidget = " << kEventMappingWidget << endl
<< " kEditableWidget = " << kEditableWidget << endl
<< " kAudioWidget = " << kAudioWidget << endl
<< " kColorWidget = " << kColorWidget << endl
<< " kCpuWidget = " << kCpuWidget << endl
<< " kDataGridOpsWidget = " << kDataGridOpsWidget << endl
<< " kDataGridWidget = " << kDataGridWidget << endl
<< " kPromptWidget = " << kPromptWidget << endl
<< " kRamWidget = " << kRamWidget << endl
<< " kRomListWidget = " << kRomListWidget << endl
<< " kRomWidget = " << kRomWidget << endl
<< " kTiaInfoWidget = " << kTiaInfoWidget << endl
<< " kTiaOutputWidget = " << kTiaOutputWidget << endl
<< " kTiaWidget = " << kTiaWidget << endl
<< " kTiaZoomWidget = " << kTiaZoomWidget << endl
<< " kToggleBitWidget = " << kToggleBitWidget << endl
<< " kTogglePixelWidget = " << kTogglePixelWidget << endl
<< " kToggleWidget = " << kToggleWidget << endl;
logMessage(buf.str(), 0);
#endif
}
@ -194,6 +196,12 @@ bool OSystem::create()
{
// Get updated paths for all configuration files
setConfigPaths();
ostringstream buf;
buf << "Base directory: '" << myBaseDir << "'" << endl
<< "Configuration file: '" << myConfigFile << "'" << endl
<< "User game properties: '" << myPropertiesFile << "'" << endl
<< endl;
logMessage(buf.str(), 1);
// Get relevant information about the video hardware
// This must be done before any graphics context is created, since
@ -412,7 +420,7 @@ bool OSystem::createFrameBuffer()
#endif
default: // Should never happen
cerr << "ERROR: Unknown emulation state in createFrameBuffer()" << endl;
logMessage("ERROR: Unknown emulation state in createFrameBuffer()\n", 0);
break;
}
@ -434,7 +442,7 @@ bool OSystem::createFrameBuffer()
fallback:
if(myFrameBuffer && myFrameBuffer->type() == kGLBuffer)
{
cerr << "ERROR: OpenGL mode failed, fallback to software" << endl;
logMessage("ERROR: OpenGL mode failed, fallback to software\n", 0);
delete myFrameBuffer; myFrameBuffer = NULL;
mySettings->setString("video", "soft");
bool ret = createFrameBuffer();
@ -463,6 +471,8 @@ void OSystem::createSound()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystem::createConsole(const string& romfile, const string& md5sum)
{
ostringstream buf;
// Do a little error checking; it shouldn't be necessary
if(myConsole) deleteConsole();
@ -474,7 +484,7 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
showmessage = true; // we show a message if a ROM is being reloaded
if(myRomFile == "")
{
cerr << "ERROR: Rom file not specified ..." << endl;
logMessage("ERROR: Rom file not specified ...\n", 0);
return false;
}
}
@ -511,7 +521,7 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
myEventHandler->reset(EventHandler::S_EMULATE);
if(!createFrameBuffer()) // Takes care of initializeVideo()
{
cerr << "ERROR: Couldn't create framebuffer for console" << endl;
logMessage("ERROR: Couldn't create framebuffer for console\n", 0);
myEventHandler->reset(EventHandler::S_LAUNCHER);
return false;
}
@ -524,10 +534,10 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
else
myFrameBuffer->showMessage("Multicart " + type + ", loading ROM" + id);
}
if(mySettings->getBool("showinfo"))
cout << "Game console created:" << endl
<< " ROM file: " << myRomFile << endl << endl
<< getROMInfo(myConsole) << endl;
buf << "Game console created:" << endl
<< " ROM file: " << myRomFile << endl << endl
<< getROMInfo(myConsole) << endl;
logMessage(buf.str(), 1);
// Update the timing info for a new console run
resetLoopTiming();
@ -537,7 +547,8 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
}
else
{
cerr << "ERROR: Couldn't create console for " << myRomFile << endl;
buf << "ERROR: Couldn't create console for " << myRomFile << endl;
logMessage(buf.str(), 0);
retval = false;
}
@ -562,16 +573,16 @@ void OSystem::deleteConsole()
#ifdef CHEATCODE_SUPPORT
myCheatManager->saveCheats(myConsole->properties().get(Cartridge_MD5));
#endif
if(mySettings->getBool("showinfo"))
{
double executionTime = (double) myTimingInfo.totalTime / 1000000.0;
double framesPerSecond = (double) myTimingInfo.totalFrames / executionTime;
cout << "Game console stats:" << endl
<< " Total frames drawn: " << myTimingInfo.totalFrames << endl
<< " Total time (sec): " << executionTime << endl
<< " Frames per second: " << framesPerSecond << endl
<< endl;
}
ostringstream buf;
double executionTime = (double) myTimingInfo.totalTime / 1000000.0;
double framesPerSecond = (double) myTimingInfo.totalFrames / executionTime;
buf << "Game console stats:" << endl
<< " Total frames drawn: " << myTimingInfo.totalFrames << endl
<< " Total time (sec): " << executionTime << endl
<< " Frames per second: " << framesPerSecond << endl
<< endl;
logMessage(buf.str(), 1);
delete myConsole; myConsole = NULL;
}
}
@ -582,7 +593,7 @@ bool OSystem::createLauncher()
myEventHandler->reset(EventHandler::S_LAUNCHER);
if(!createFrameBuffer())
{
cerr << "ERROR: Couldn't create launcher" << endl;
logMessage("ERROR: Couldn't create launcher\n", 0);
return false;
}
myLauncher->reStack();
@ -625,6 +636,15 @@ string OSystem::MD5FromFile(const string& filename)
return md5;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::logMessage(const string& message, uInt8 level)
{
if(level == 0)
cerr << message;
else if(level <= (uInt8)mySettings->getInt("showinfo"))
cout << message;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Console* OSystem::openConsole(const string& romfile, string& md5,
string& type, string& id)
@ -689,7 +709,11 @@ Console* OSystem::openConsole(const string& romfile, string& md5,
console = new Console(this, cart, props);
}
else
cerr << "ERROR: Couldn't open " << romfile << endl;
{
ostringstream buf;
buf << "ERROR: Couldn't open \'" << romfile << "\'" << endl;
logMessage(buf.str(), 0);
}
// Free the image since we don't need it any longer
if(image != 0 && size > 0)

View File

@ -358,7 +358,7 @@ class OSystem
Calculate the MD5sum of the given file.
@param filename Filename of potential ROM file
*/
*/
string MD5FromFile(const string& filename);
/**
@ -366,6 +366,15 @@ class OSystem
*/
void quit() { myQuitLoop = true; }
/**
Output a message to the a log (normally stdout).
@param message The message to be output
@param level If 0, always output the message, only output when
level is less than or equal to that in 'showinfo'
*/
void logMessage(const string& message, uInt8 level);
public:
//////////////////////////////////////////////////////////////////////
// The following methods are system-specific and must be implemented

View File

@ -49,9 +49,6 @@ PropertiesSet::~PropertiesSet()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::load(const string& filename)
{
if(myOSystem->settings().getBool("showinfo"))
cout << "User game properties: \'" << filename << "\'\n";
ifstream in(filename.c_str(), ios::in);
// Loop reading properties

View File

@ -118,7 +118,7 @@ Settings::Settings(OSystem* osystem)
// Misc options
setInternal("autoslot", "false");
setInternal("showinfo", "false");
setInternal("showinfo", "1");
setInternal("tiadriven", "false");
setInternal("avoxport", "");
setInternal("stats", "false");
@ -147,7 +147,7 @@ void Settings::loadConfig()
ifstream in(myOSystem->configFile().c_str());
if(!in || !in.is_open())
{
cout << "ERROR: Couldn't load settings file\n";
myOSystem->logMessage("ERROR: Couldn't load settings file\n", 0);
return;
}
@ -212,7 +212,9 @@ string Settings::loadCommandLine(int argc, char** argv)
if(++i >= argc)
{
cerr << "Missing argument for '" << key << "'" << endl;
ostringstream buf;
buf << "Missing argument for '" << key << "'" << endl;
myOSystem->logMessage(buf.str(), 0);
return "";
}
string value = argv[i];
@ -297,6 +299,10 @@ void Settings::validate()
s = getString("tv_noise");
if(s != "low" && s != "medium" && s != "high")
setInternal("tv_noise", "off");
i = getInt("showinfo");
if(i < 0 || i > 2)
setInternal("showinfo", "1");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -363,7 +369,7 @@ void Settings::usage()
<< endl
#endif
<< " -cheat <code> Use the specified cheatcode (see manual for description)\n"
<< " -showinfo <1|0> Shows some game info on commandline\n"
<< " -showinfo <0|1|2> Shows some application/game info on commandline\n"
<< " -joydeadzone <number> Sets 'deadzone' area for analog joysticks (0-29)\n"
<< " -joyallow4 <1|0> Allow all 4 directions on a joystick to be pressed simultaneously\n"
<< " -usemouse <1|0> Use mouse for various controllers (paddle, driving, etc)\n"
@ -457,7 +463,7 @@ void Settings::saveConfig()
ofstream out(myOSystem->configFile().c_str());
if(!out || !out.is_open())
{
cout << "ERROR: Couldn't save settings file\n";
myOSystem->logMessage("ERROR: Couldn't save settings file\n", 0);
return;
}

View File

@ -35,19 +35,19 @@ class GameList
GameList();
~GameList();
inline const string& name(int i)
inline const string& name(int i) const
{ return i < (int)myArray.size() ? myArray[i]._name : EmptyString; }
inline const string& path(int i)
inline const string& path(int i) const
{ return i < (int)myArray.size() ? myArray[i]._path : EmptyString; }
inline const string& md5(int i)
inline const string& md5(int i) const
{ return i < (int)myArray.size() ? myArray[i]._md5 : EmptyString; }
inline const bool isDir(int i)
inline const bool isDir(int i) const
{ return i < (int)myArray.size() ? myArray[i]._isdir: false; }
inline void setMd5(int i, const string& md5)
{ myArray[i]._md5 = md5; }
inline int size() { return myArray.size(); }
inline int size() const { return myArray.size(); }
inline void clear() { myArray.clear(); }
void appendGame(const string& name, const string& path, const string& md5,