OpenGL mode is working again; snapshot and menuing support still MIA.

Rearranged some things from Settings to OSystem, since many things in the
Settings class weren't actually related to settings at all.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@372 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-02-22 18:41:16 +00:00
parent f3a31ca452
commit aa8b0b9bdd
16 changed files with 283 additions and 247 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferGL.cxx,v 1.13 2005-02-21 02:23:48 stephena Exp $
// $Id: FrameBufferGL.cxx,v 1.14 2005-02-22 18:40:52 stephena Exp $
//============================================================================
#include <SDL.h>
@ -22,14 +22,15 @@
#include "Console.hxx"
#include "FrameBuffer.hxx"
#include "FrameBufferSDL.hxx"
#include "FrameBufferGL.hxx"
#include "MediaSrc.hxx"
#include "Settings.hxx"
#include "OSystem.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBufferGL::FrameBufferGL()
: myTexture(0),
FrameBufferGL::FrameBufferGL(OSystem* osystem)
: FrameBuffer(osystem),
myTexture(0),
myScreenmode(0),
myScreenmodeCount(0),
myFilterParam(GL_NEAREST),
@ -50,42 +51,23 @@ FrameBufferGL::~FrameBufferGL()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FrameBufferGL::initSubsystem()
{
// Get the desired width and height of the display
myWidth = myMediaSource->width() << 1;
myHeight = myMediaSource->height();
mySDLFlags |= SDL_OPENGL;
// Get the aspect ratio for the display
// Since the display is already doubled horizontally, we half the
// ratio that is provided
theAspectRatio = myConsole->settings().getFloat("gl_aspect") / 2;
theAspectRatio = myOSystem->settings().getFloat("gl_aspect") / 2;
if(theAspectRatio <= 0.0)
theAspectRatio = 1.0;
// Now create the OpenGL SDL screen
Uint32 initflags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
if(SDL_Init(initflags) < 0)
return false;
// Check which system we are running under
// Get the system-specific WM information
SDL_VERSION(&myWMInfo.version);
if(SDL_GetWMInfo(&myWMInfo) > 0)
myWMAvailable = true;
// Get the maximum size of a window for THIS screen
theMaxZoomLevel = maxWindowSizeForScreen();
// Check to see if window size will fit in the screen
if((uInt32)myConsole->settings().getInt("zoom") > theMaxZoomLevel)
if((uInt32)myOSystem->settings().getInt("zoom") > theMaxZoomLevel)
theZoomLevel = theMaxZoomLevel;
else
theZoomLevel = myConsole->settings().getInt("zoom");
mySDLFlags = SDL_OPENGL;
mySDLFlags |= myConsole->settings().getBool("fullscreen") ? SDL_FULLSCREEN : 0;
// Set the window title and icon
setWindowAttributes();
theZoomLevel = myOSystem->settings().getInt("zoom");
// Set up the OpenGL attributes
myDepth = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
@ -156,23 +138,8 @@ bool FrameBufferGL::initSubsystem()
// and the textures
setupPalette();
// Make sure that theUseFullScreenFlag sets up fullscreen mode correctly
if(myConsole->settings().getBool("fullscreen"))
{
grabMouse(true);
showCursor(false);
}
else
{
// Keep mouse in game window if grabmouse is selected
grabMouse(myConsole->settings().getBool("grabmouse"));
// Show or hide the cursor depending on the 'hidecursor' argument
showCursor(!myConsole->settings().getBool("hidecursor"));
}
// Show some OpenGL info
if(myConsole->settings().getBool("showinfo"))
if(myOSystem->settings().getBool("showinfo"))
{
cout << "Video rendering: OpenGL mode" << endl;
@ -247,11 +214,13 @@ bool FrameBufferGL::createScreen()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferGL::drawMediaSource()
{
MediaSource& mediasrc = myOSystem->console().mediaSource();
// Copy the mediasource framebuffer to the RGB texture
uInt8* currentFrame = myMediaSource->currentFrameBuffer();
uInt8* previousFrame = myMediaSource->previousFrameBuffer();
uInt32 width = myMediaSource->width();
uInt32 height = myMediaSource->height();
uInt8* currentFrame = mediasrc.currentFrameBuffer();
uInt8* previousFrame = mediasrc.previousFrameBuffer();
uInt32 width = mediasrc.width();
uInt32 height = mediasrc.height();
uInt16* buffer = (uInt16*) myTexture->pixels;
register uInt32 y;
@ -384,7 +353,7 @@ bool FrameBufferGL::createTextures()
return false;
// Create an OpenGL texture from the SDL texture
string filter = myConsole->settings().getString("gl_filter");
string filter = myOSystem->settings().getString("gl_filter");
if(filter == "linear")
{
myFilterParam = GL_LINEAR;
@ -471,13 +440,13 @@ void FrameBufferGL::toggleFilter()
if(myFilterParam == GL_NEAREST)
{
myFilterParam = GL_LINEAR;
myConsole->settings().setString("gl_filter", "linear");
myOSystem->settings().setString("gl_filter", "linear");
showMessage("Filtering: GL_LINEAR");
}
else
{
myFilterParam = GL_NEAREST;
myConsole->settings().setString("gl_filter", "nearest");
myOSystem->settings().setString("gl_filter", "nearest");
showMessage("Filtering: GL_NEAREST");
}
@ -523,7 +492,7 @@ void FrameBufferGL::viewport(uInt32* screenWidth, uInt32* screenHeight,
uInt32 desktopWidth = this->screenWidth();
uInt32 desktopHeight = this->screenHeight();
if(myConsole->settings().getBool("gl_fsmax") &&
if(myOSystem->settings().getBool("gl_fsmax") &&
desktopWidth != 0 && desktopHeight != 0)
{
// Use the largest available screen size
@ -543,7 +512,7 @@ void FrameBufferGL::viewport(uInt32* screenWidth, uInt32* screenHeight,
iwidth = (Uint16) (scale * iwidth);
iheight = (Uint16) (scale * iheight);
}
else if(myConsole->settings().getBool("gl_fsmax") &&
else if(myOSystem->settings().getBool("gl_fsmax") &&
myScreenmode != (SDL_Rect**) -1)
{
// Use the largest available screen size

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferGL.hxx,v 1.7 2005-02-21 02:23:48 stephena Exp $
// $Id: FrameBufferGL.hxx,v 1.8 2005-02-22 18:40:53 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_GL_HXX
@ -23,6 +23,8 @@
#include <SDL_opengl.h>
#include <SDL_syswm.h>
class OSystem;
#include "bspf.hxx"
#include "FrameBuffer.hxx"
@ -31,7 +33,7 @@
This class implements an SDL OpenGL framebuffer.
@author Stephen Anthony
@version $Id: FrameBufferGL.hxx,v 1.7 2005-02-21 02:23:48 stephena Exp $
@version $Id: FrameBufferGL.hxx,v 1.8 2005-02-22 18:40:53 stephena Exp $
*/
class FrameBufferGL : public FrameBuffer
{
@ -39,22 +41,22 @@ class FrameBufferGL : public FrameBuffer
/**
Creates a new OpenGL framebuffer
*/
FrameBufferGL();
FrameBufferGL(OSystem* osystem);
/**
Destructor
*/
virtual ~FrameBufferGL();
/**
Switches between the two filtering options in OpenGL.
Currently, these are GL_NEAREST and GL_LINEAR.
*/
void toggleFilter();
//////////////////////////////////////////////////////////////////////
// The following methods are derived from FrameBuffer.hxx
//////////////////////////////////////////////////////////////////////
/**
This routine is called to initialize OpenGL video mode.
Return false if any operation fails, otherwise return true.
*/
virtual bool initSubsystem();
/**
This routine is called whenever the screen needs to be recreated.
It updates the global screen variable.
@ -69,21 +71,13 @@ class FrameBufferGL : public FrameBuffer
@param b The blue component of the color.
*/
virtual Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b)
{ return SDL_MapRGB(myTexture->format, r, g, b); }
{ return SDL_MapRGB(myScreen->format, r, g, b); }
/**
This routine is called to get the specified scanline data.
@param row The row we are looking for
@param data The actual pixel data (in bytes)
Switches between the two filtering options in OpenGL.
Currently, these are GL_NEAREST and GL_LINEAR.
*/
virtual void scanline(uInt32 row, uInt8* data);
/**
This routine should be called to setup the video system for us to use.
Return false if any operation fails, otherwise return true.
*/
virtual bool initSubsystem();
virtual void toggleFilter();
/**
This routine should be called anytime the MediaSource needs to be redrawn
@ -130,8 +124,15 @@ class FrameBufferGL : public FrameBuffer
*/
virtual void postFrameUpdate();
private:
/**
This routine is called to get the specified scanline data.
@param row The row we are looking for
@param data The actual pixel data (in bytes)
*/
virtual void scanline(uInt32 row, uInt8* data);
private:
bool createTextures();
void viewport(uInt32* screenWidth, uInt32* screenHeight,

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSoft.cxx,v 1.8 2005-02-21 20:41:18 stephena Exp $
// $Id: FrameBufferSoft.cxx,v 1.9 2005-02-22 18:40:55 stephena Exp $
//============================================================================
#include <SDL.h>
@ -62,9 +62,6 @@ bool FrameBufferSoft::initSubsystem()
else
theZoomLevel = myOSystem->settings().getInt("zoom");
// Set the window title and icon
setWindowAttributes();
// Create the screen
if(!createScreen())
return false;
@ -95,6 +92,12 @@ bool FrameBufferSoft::createScreen()
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSoft::toggleFilter()
{
// No filter added yet ...
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSoft::drawMediaSource()
{

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSoft.hxx,v 1.6 2005-02-21 20:41:19 stephena Exp $
// $Id: FrameBufferSoft.hxx,v 1.7 2005-02-22 18:40:55 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_SOFT_HXX
@ -34,7 +34,7 @@ class RectList;
This class implements an SDL software framebuffer.
@author Stephen Anthony
@version $Id: FrameBufferSoft.hxx,v 1.6 2005-02-21 20:41:19 stephena Exp $
@version $Id: FrameBufferSoft.hxx,v 1.7 2005-02-22 18:40:55 stephena Exp $
*/
class FrameBufferSoft : public FrameBuffer
{
@ -74,6 +74,12 @@ class FrameBufferSoft : public FrameBuffer
virtual Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b)
{ return SDL_MapRGB(myScreen->format, r, g, b); }
/**
Switches between the filtering options in software mode.
Currently, none exist.
*/
virtual void toggleFilter();
/**
This routine should be called anytime the MediaSource needs to be redrawn
to the screen.

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SoundSDL.cxx,v 1.10 2005-02-22 02:59:53 stephena Exp $
// $Id: SoundSDL.cxx,v 1.11 2005-02-22 18:40:55 stephena Exp $
//============================================================================
#include <sstream>
@ -37,9 +37,6 @@ SoundSDL::SoundSDL(OSystem* osystem)
myFragmentSizeLogBase2(0),
myIsMuted(false)
{
uInt32 fragsize = myOSystem->settings().getInt("fragsize");
myVolume = myOSystem->settings().getInt("volume");
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
{
cerr << "WARNING: Couldn't initialize SDL audio system! " << endl;
@ -48,6 +45,8 @@ SoundSDL::SoundSDL(OSystem* osystem)
}
else
{
uInt32 fragsize = myOSystem->settings().getInt("fragsize");
SDL_AudioSpec desired;
desired.freq = 31400;
desired.format = AUDIO_U8;
@ -93,6 +92,16 @@ SoundSDL::SoundSDL(OSystem* osystem)
// And start the SDL sound subsystem ...
SDL_PauseAudio(0);
// Adjust volume to that defined in settings
myVolume = myOSystem->settings().getInt("volume");
setVolume(myVolume);
// Show some info
if(myOSystem->settings().getBool("showinfo"))
cout << "Sound enabled:" << endl
<< " Volume : " << myVolume << endl
<< " Frag size: " << fragsize << endl << endl;
}
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: mainSDL.cxx,v 1.23 2005-02-22 02:59:53 stephena Exp $
// $Id: mainSDL.cxx,v 1.24 2005-02-22 18:40:56 stephena Exp $
//============================================================================
#include <fstream>
@ -45,9 +45,6 @@
#ifdef DISPLAY_OPENGL
#include "FrameBufferGL.hxx"
// Indicates whether to use OpenGL mode
static bool theUseOpenGLFlag;
#endif
#if defined(UNIX)
@ -442,12 +439,10 @@ void HandleEvents()
theSound->adjustVolume(1);
break;
#ifdef DISPLAY_OPENGL
case SDLK_f:
if(theUseOpenGLFlag)
((FrameBufferGL*)theDisplay)->toggleFilter();
theDisplay->toggleFilter();
break;
#endif
#ifdef DEVELOPER_SUPPORT
case SDLK_END: // Alt-End increases XStart
theOSystem->console().changeXStart(1);
@ -545,10 +540,10 @@ void HandleEvents()
case SDLK_s: // Ctrl-s saves properties to a file
// Attempt to merge with propertiesSet
if(theSettings->getBool("mergeprops"))
theOSystem->console().saveProperties(theSettings->propertiesOutputFilename(), true);
theOSystem->console().saveProperties(theOSystem->propertiesOutputFilename(), true);
else // Save to file in home directory
{
string newPropertiesFile = theSettings->baseDir() + "/" + \
string newPropertiesFile = theOSystem->baseDir() + "/" + \
theOSystem->console().properties().get("Cartridge.Name") + ".pro";
theOSystem->console().saveProperties(newPropertiesFile);
}
@ -766,7 +761,7 @@ void SetupProperties(PropertiesSet& set)
{
bool useMemList = false;
string theAltPropertiesFile = theSettings->getString("altpro");
string thePropertiesFile = theSettings->propertiesInputFilename();
string thePropertiesFile = theOSystem->propertiesInputFilename();
// When 'listrominfo' or 'mergeprops' is specified, we need to have the
// full list in memory
@ -897,20 +892,13 @@ int main(int argc, char* argv[])
// Create an SDL window
string videodriver = theSettings->getString("video");
if(videodriver == "soft")
{
theDisplay = new FrameBufferSoft(theOSystem);
}
#ifdef DISPLAY_OPENGL
else if(videodriver == "gl")
{
theDisplay = new FrameBufferGL();
theUseOpenGLFlag = true;
}
theDisplay = new FrameBufferGL(theOSystem);
#endif
else // a driver that doesn't exist was requested, so use software mode
{
theDisplay = new FrameBufferSoft(theOSystem);
}
if(!theDisplay)
{
@ -920,22 +908,11 @@ int main(int argc, char* argv[])
return 0;
}
// Create a sound object for playing audio
// Create a sound object for playing audio, even if sound has been disabled
if(theSettings->getBool("sound"))
{
theSound = new SoundSDL(theOSystem);
ostringstream message;
message << "Sound enabled:" << endl;
//FIXME << " Volume : " << volume << endl
// << " Frag size: " << fragsize << endl;
ShowInfo(message.str());
}
else // even if sound has been disabled, we still need a sound object
{
else
theSound = new Sound(theOSystem);
ShowInfo("Sound disabled");
}
// Get a pointer to the file which contains the cartridge ROM
const char* file = argv[argc - 1];
@ -954,7 +931,7 @@ int main(int argc, char* argv[])
uInt32 size = in.gcount();
in.close();
// Create the 2600 game console
// Create an instance of the 2600 game console
Console* theConsole = (Console*) NULL;
theConsole = new Console(image, size, theOSystem);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBuffer.cxx,v 1.15 2005-02-22 02:59:54 stephena Exp $
// $Id: FrameBuffer.cxx,v 1.16 2005-02-22 18:40:59 stephena Exp $
//============================================================================
#include <sstream>
@ -93,23 +93,33 @@ FrameBuffer::~FrameBuffer(void)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::initialize(const string title, uInt32 width, uInt32 height)
{
myWidth = width;
myHeight = height;
bool isAlreadyInitialized = (SDL_WasInit(SDL_INIT_VIDEO) & SDL_INIT_VIDEO) > 0;
myWidth = width;
myHeight = height;
myFrameRate = myOSystem->settings().getInt("framerate");
// Now initialize the SDL screen
Uint32 initflags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
if(SDL_Init(initflags) < 0)
return;
// Now (re)initialize the SDL video system
if(!isAlreadyInitialized)
{
Uint32 initflags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
// Get the system-specific WM information
SDL_VERSION(&myWMInfo.version);
if(SDL_GetWMInfo(&myWMInfo) > 0)
myWMAvailable = true;
if(SDL_Init(initflags) < 0)
return;
// Get the system-specific WM information
SDL_VERSION(&myWMInfo.version);
if(SDL_GetWMInfo(&myWMInfo) > 0)
myWMAvailable = true;
setWindowIcon();
}
mySDLFlags = myOSystem->settings().getBool("fullscreen") ? SDL_FULLSCREEN : 0;
// Set window title
setWindowTitle(title);
// Initialize video subsystem
initSubsystem();
@ -1029,13 +1039,14 @@ uInt32 FrameBuffer::screenHeight()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::setWindowAttributes()
void FrameBuffer::setWindowTitle(const string title)
{
// Set the window title
ostringstream name;
name << "Stella: \"" << myOSystem->console().properties().get("Cartridge.Name") << "\"";
SDL_WM_SetCaption(name.str().c_str(), "stella");
SDL_WM_SetCaption(title.c_str(), "stella");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::setWindowIcon()
{
#ifndef MAC_OSX
// Set the window icon
uInt32 w, h, ncols, nbytes;
@ -1052,7 +1063,7 @@ void FrameBuffer::setWindowAttributes()
for(uInt32 i = 0; i < ncols; i++)
{
unsigned char code;
char color[32];
char color[32];
uInt32 col;
sscanf(stella_icon[1 + i], "%c c %s", &code, color);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBuffer.hxx,v 1.15 2005-02-21 20:43:10 stephena Exp $
// $Id: FrameBuffer.hxx,v 1.16 2005-02-22 18:41:11 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_HXX
@ -39,7 +39,7 @@ FIXME This class also implements a MAME-like user interface where Stella settin
can be changed.
@author Stephen Anthony
@version $Id: FrameBuffer.hxx,v 1.15 2005-02-21 20:43:10 stephena Exp $
@version $Id: FrameBuffer.hxx,v 1.16 2005-02-22 18:41:11 stephena Exp $
*/
class FrameBuffer
{
@ -55,7 +55,7 @@ class FrameBuffer
virtual ~FrameBuffer();
/**
Initializes the framebuffer display. This must be called before any
(Re)initializes the framebuffer display. This must be called before any
calls are made to derived methods.
@param title The title of the window
@ -207,9 +207,9 @@ FIXME
uInt32 maxWindowSizeForScreen();
/**
Set the title and icon for the main SDL window.
Set the title for the main SDL window.
*/
void setWindowAttributes();
void setWindowTitle(const string title);
/**
Set up the palette for a screen of any depth > 8.
@ -241,6 +241,11 @@ FIXME
*/
virtual Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b) = 0;
/**
Switches between the filtering options in the video subsystem.
*/
virtual void toggleFilter() = 0;
/**
This routine should be called anytime the MediaSource needs to be redrawn
to the screen.
@ -351,6 +356,11 @@ FIXME
float theAspectRatio;
private:
/**
Set the icon for the main SDL window.
*/
void setWindowIcon();
// Enumeration representing the different types of user interface widgets
enum Widget { W_NONE, MAIN_MENU, REMAP_MENU, INFO_MENU };

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OSystem.cxx,v 1.2 2005-02-21 20:43:20 stephena Exp $
// $Id: OSystem.cxx,v 1.3 2005-02-22 18:41:12 stephena Exp $
//============================================================================
#include <cassert>
@ -39,9 +39,33 @@ OSystem::~OSystem()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::update()
void OSystem::setPropertiesFiles(const string& userprops,
const string& systemprops)
{
// myFrameBuffer.update();
// Set up the input and output properties files
myPropertiesOutputFile = userprops;
if(fileExists(userprops))
myPropertiesInputFile = userprops;
else if(fileExists(systemprops))
myPropertiesInputFile = systemprops;
else
myPropertiesInputFile = "";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::setConfigFiles(const string& userconfig,
const string& systemconfig)
{
// Set up the names of the input and output config files
myConfigOutputFile = userconfig;
if(fileExists(userconfig))
myConfigInputFile = userconfig;
else if(fileExists(systemconfig))
myConfigInputFile = systemconfig;
else
myConfigInputFile = "";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OSystem.hxx,v 1.2 2005-02-21 20:43:20 stephena Exp $
// $Id: OSystem.hxx,v 1.3 2005-02-22 18:41:12 stephena Exp $
//============================================================================
#ifndef OSYSTEM_HXX
@ -35,7 +35,7 @@ class PropertiesSet;
other objects belong.
@author Stephen Anthony
@version $Id: OSystem.hxx,v 1.2 2005-02-21 20:43:20 stephena Exp $
@version $Id: OSystem.hxx,v 1.3 2005-02-22 18:41:12 stephena Exp $
*/
class OSystem
{
@ -51,12 +51,6 @@ class OSystem
virtual ~OSystem();
public:
/**
Updates the osystem by one frame. Determines which subsystem should
be updated. Generally will be called 'framerate' times per second.
*/
void update();
/**
Adds the specified eventhandler to the system.
@ -146,6 +140,68 @@ class OSystem
*/
Console& console(void) const { return *myConsole; }
/**
Set the base directory for all configuration files
*/
void setBaseDir(const string& basedir) { myBaseDir = basedir; }
/**
Set the directory where state files are stored
*/
void setStateDir(const string& statedir) { myStateDir = statedir; }
/**
Set the locations of game properties files
*/
void setPropertiesFiles(const string& userprops, const string& systemprops);
/**
Set the locations of config files
*/
void setConfigFiles(const string& userconfig, const string& systemconfig);
/**
Return the default directory for storing data.
*/
string baseDir() { return myBaseDir; }
/**
Return the directory for storing state files.
*/
string stateDir() { return myStateDir; }
/**
This method should be called to get the filename of the
properties (stella.pro) file for the purpose of loading.
@return String representing the full path of the properties filename.
*/
string propertiesInputFilename() { return myPropertiesInputFile; }
/**
This method should be called to get the filename of the
properties (stella.pro) file for the purpose of saving.
@return String representing the full path of the properties filename.
*/
string propertiesOutputFilename() { return myPropertiesOutputFile; }
/**
This method should be called to get the filename of the config file
for the purpose of loading.
@return String representing the full path of the config filename.
*/
string configInputFilename() { return myConfigInputFile; }
/**
This method should be called to get the filename of the config file
for the purpose of saving.
@return String representing the full path of the config filename.
*/
string configOutputFilename() { return myConfigOutputFile; }
public:
//////////////////////////////////////////////////////////////////////
// The following methods are system-specific and must be implemented
@ -171,6 +227,15 @@ class OSystem
*/
virtual bool fileExists(const string& filename) = 0;
/**
This method should be called to create the specified directory.
@param path The directory to create
@return boolean representing whether or not the directory was created
*/
virtual bool makeDir(const string& path) = 0;
protected:
// Pointer to the EventHandler object
EventHandler* myEventHandler;
@ -190,6 +255,15 @@ class OSystem
// Pointer to the (currently defined) Console object
Console* myConsole;
private:
string myBaseDir;
string myStateDir;
string myPropertiesInputFile;
string myPropertiesOutputFile;
string myConfigInputFile;
string myConfigOutputFile;
private:
// Copy constructor isn't supported by this class so make it private
OSystem(const OSystem&);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Settings.cxx,v 1.32 2005-02-21 20:43:20 stephena Exp $
// $Id: Settings.cxx,v 1.33 2005-02-22 18:41:12 stephena Exp $
//============================================================================
#include <cassert>
@ -80,7 +80,7 @@ void Settings::loadConfig()
string line, key, value;
uInt32 equalPos;
ifstream in(myConfigInputFile.c_str());
ifstream in(myOSystem->configInputFilename().c_str());
if(!in || !in.is_open())
{
cout << "Error: Couldn't load settings file\n";
@ -217,7 +217,7 @@ void Settings::usage()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::saveConfig()
{
ofstream out(myConfigOutputFile.c_str());
ofstream out(myOSystem->configOutputFilename().c_str());
if(!out || !out.is_open())
{
cout << "Error: Couldn't save settings file\n";

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Settings.hxx,v 1.20 2005-02-21 20:43:21 stephena Exp $
// $Id: Settings.hxx,v 1.21 2005-02-22 18:41:14 stephena Exp $
//============================================================================
#ifndef SETTINGS_HXX
@ -28,7 +28,7 @@ class OSystem;
This class provides an interface for accessing frontend specific settings.
@author Stephen Anthony
@version $Id: Settings.hxx,v 1.20 2005-02-21 20:43:21 stephena Exp $
@version $Id: Settings.hxx,v 1.21 2005-02-22 18:41:14 stephena Exp $
*/
class Settings
{
@ -138,61 +138,10 @@ class Settings
*/
void setString(const string& key, const string& value, bool save = true);
public:
/**
This method should be called to get the filename of the
properties (stella.pro) file for the purpose of loading.
@return String representing the full path of the properties filename.
*/
string propertiesInputFilename() { return myPropertiesInputFile; }
/**
This method should be called to get the filename of the
properties (stella.pro) file for the purpose of saving.
@return String representing the full path of the properties filename.
*/
string propertiesOutputFilename() { return myPropertiesOutputFile; }
/**
This method should be called to get the filename of the config file
for the purpose of loading.
@return String representing the full path of the config filename.
*/
string configInputFilename() { return myConfigInputFile; }
/**
This method should be called to get the filename of the config file
for the purpose of saving.
@return String representing the full path of the config filename.
*/
string configOutputFilename() { return myConfigOutputFile; }
/**
Return the default directory for storing data.
*/
string baseDir() { return myBaseDir; }
/**
Set the OSystem object for this settings class
*/
void setOSystem(OSystem* osystem) { myOSystem = osystem; }
protected:
void set(const string& key, const string& value, bool save = true);
string myBaseDir;
string myStateDir;
string myPropertiesInputFile;
string myPropertiesOutputFile;
string myConfigInputFile;
string myConfigOutputFile;
// The parent OSystem object
OSystem* myOSystem;
// Structure used for storing settings

View File

@ -13,13 +13,16 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Sound.cxx,v 1.16 2005-02-22 02:59:54 stephena Exp $
// $Id: Sound.cxx,v 1.17 2005-02-22 18:41:15 stephena Exp $
//============================================================================
#include "Serializer.hxx"
#include "Deserializer.hxx"
#include "bspf.hxx"
#include "OSystem.hxx"
#include "Settings.hxx"
#include "Sound.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -30,6 +33,11 @@ Sound::Sound(OSystem* osystem)
{
// Add the sound object to the system
myOSystem->attach(this);
// Show some info
if(myOSystem->settings().getBool("showinfo") &&
!myOSystem->settings().getBool("sound"))
cout << "Sound disabled." << endl << endl;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OSystemUNIX.cxx,v 1.2 2005-02-21 20:43:47 stephena Exp $
// $Id: OSystemUNIX.cxx,v 1.3 2005-02-22 18:41:15 stephena Exp $
//============================================================================
#include <cstdlib>
@ -42,7 +42,7 @@ OSystemUNIX::~OSystemUNIX()
string OSystemUNIX::stateFilename(const string& md5, uInt32 state)
{
ostringstream buf;
//FIXME buf << myStateDir << md5 << ".st" << state;
buf << stateDir() << "/" << md5 << ".st" << state;
return buf.str();
}
@ -50,5 +50,11 @@ string OSystemUNIX::stateFilename(const string& md5, uInt32 state)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystemUNIX::fileExists(const string& filename)
{
return (access(filename.c_str(), F_OK) == 0);
return access(filename.c_str(), F_OK) == 0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystemUNIX::makeDir(const string& path)
{
return mkdir(path.c_str(), 0777) == 0;
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OSystemUNIX.hxx,v 1.2 2005-02-21 20:43:53 stephena Exp $
// $Id: OSystemUNIX.hxx,v 1.3 2005-02-22 18:41:16 stephena Exp $
//============================================================================
#ifndef OSYSTEM_UNIX_HXX
@ -26,7 +26,7 @@
This class defines UNIX-like OS's (Linux) system specific settings.
@author Stephen Anthony
@version $Id: OSystemUNIX.hxx,v 1.2 2005-02-21 20:43:53 stephena Exp $
@version $Id: OSystemUNIX.hxx,v 1.3 2005-02-22 18:41:16 stephena Exp $
*/
class OSystemUNIX : public OSystem
{
@ -62,6 +62,15 @@ class OSystemUNIX : public OSystem
@return boolean representing whether or not the file exists
*/
virtual bool fileExists(const string& filename);
/**
This method should be called to create the specified directory.
@param path The directory to create
@return boolean representing whether or not the directory was created
*/
virtual bool makeDir(const string& path);
};
#endif

View File

@ -13,16 +13,10 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SettingsUNIX.cxx,v 1.9 2005-02-21 20:43:53 stephena Exp $
// $Id: SettingsUNIX.cxx,v 1.10 2005-02-22 18:41:16 stephena Exp $
//============================================================================
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "bspf.hxx"
#include "OSystem.hxx"
@ -33,40 +27,26 @@
SettingsUNIX::SettingsUNIX(OSystem* osystem)
: Settings(osystem)
{
// First set variables that the parent class needs
myBaseDir = getenv("HOME");
string stelladir = myBaseDir + "/.stella";
// First set variables that the OSystem needs
string basedir = getenv("HOME");
myOSystem->setBaseDir(basedir);
string stelladir = basedir + "/.stella";
if(!myOSystem->fileExists(stelladir))
mkdir(stelladir.c_str(), 0777);
// FIXME - add a OSystem mkdir
myOSystem->makeDir(stelladir);
myStateDir = stelladir + "/state/";
if(!myOSystem->fileExists(myStateDir))
mkdir(myStateDir.c_str(), 0777);
string statedir = stelladir + "/state/";
if(!myOSystem->fileExists(statedir))
myOSystem->makeDir(statedir);
myOSystem->setStateDir(statedir);
string userPropertiesFile = stelladir + "/stella.pro";
string systemPropertiesFile = "/etc/stella.pro";
string userConfigFile = stelladir + "/stellarc";
string systemConfigFile = "/etc/stellarc";
myOSystem->setPropertiesFiles(userPropertiesFile, systemPropertiesFile);
// Set up the names of the input and output config files
myConfigOutputFile = userConfigFile;
if(myOSystem->fileExists(userConfigFile))
myConfigInputFile = userConfigFile;
else if(myOSystem->fileExists(systemConfigFile))
myConfigInputFile = systemConfigFile;
else
myConfigInputFile = "";
// Set up the input and output properties files
myPropertiesOutputFile = userPropertiesFile;
if(myOSystem->fileExists(userPropertiesFile))
myPropertiesInputFile = userPropertiesFile;
else if(myOSystem->fileExists(systemPropertiesFile))
myPropertiesInputFile = systemPropertiesFile;
else
myPropertiesInputFile = "";
string userConfigFile = stelladir + "/stellarc";
string systemConfigFile = "/etc/stellarc";
myOSystem->setConfigFiles(userConfigFile, systemConfigFile);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -