From: Steve A. <ste...@us...> - 2003-09-19 20:22:06
|
Update of /cvsroot/stella/stella/src/ui/common In directory sc8-pr-cvs1:/tmp/cvs-serv9068/src/ui/common Modified Files: SettingsUNIX.cxx SettingsUNIX.hxx Log Message: Eliminated requirement for two platform specific files wrt porting. They both referred to each other, so it made more sense to only have one file. Porters will now only need to define their own SettingsXXX, derived from Settings.hxx, for platform specific stuff. Updated the X11 and SDL ports wrt to the previously mentioned stuff. The next task will be to update the DOS port, which should be incredibly easy (assuming I can get a stable DOS dev environment) ... Index: SettingsUNIX.cxx =================================================================== RCS file: /cvsroot/stella/stella/src/ui/common/SettingsUNIX.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SettingsUNIX.cxx 12 Sep 2003 18:08:53 -0000 1.2 --- SettingsUNIX.cxx 19 Sep 2003 15:45:01 -0000 1.3 *************** *** 17,38 **** //============================================================================ #include <fstream> #include "Console.hxx" #include "EventHandler.hxx" #include "StellaEvent.hxx" - #ifdef DEVELOPER_SUPPORT - #include "Props.hxx" - #endif - #include "Settings.hxx" #include "SettingsUNIX.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! SettingsUNIX::SettingsUNIX(const string& infile, const string& outfile) ! : mySettingsInputFilename(infile), ! mySettingsOutputFilename(outfile) { theUseFullScreenFlag = false; theGrabMouseFlag = false; --- 17,40 ---- //============================================================================ + #include <cstdlib> + #include <sstream> #include <fstream> + #include <unistd.h> + #include <sys/stat.h> + #include <sys/types.h> + + #include "bspf.hxx" #include "Console.hxx" #include "EventHandler.hxx" #include "StellaEvent.hxx" #include "Settings.hxx" #include "SettingsUNIX.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! SettingsUNIX::SettingsUNIX() { + // Initialize UNIX specific settings theUseFullScreenFlag = false; theGrabMouseFlag = false; *************** *** 43,47 **** theAccurateTimingFlag = true; theDesiredVolume = -1; - theDesiredFrameRate = 60; thePaddleMode = 0; theAlternateProFile = ""; --- 45,48 ---- *************** *** 50,150 **** theRightJoystickNumber = 1; ! #ifdef DEVELOPER_SUPPORT ! userDefinedProperties.set("Display.Format", "-1"); ! userDefinedProperties.set("Display.XStart", "-1"); ! userDefinedProperties.set("Display.Width", "-1"); ! userDefinedProperties.set("Display.YStart", "-1"); ! userDefinedProperties.set("Display.Height", "-1"); ! ! theMergePropertiesFlag = false; ! #endif ! ! handleRCFile(); ! } ! ! SettingsUNIX::~SettingsUNIX() ! { ! } ! // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! void SettingsUNIX::setConsole(Console* console) ! { ! myConsole = console; ! } ! // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! bool SettingsUNIX::handleCommandLineArgs(int argc, char* argv[]) ! { ! // Make sure we have the correct number of command line arguments ! if(argc == 1) ! return false; ! for(Int32 i = 1; i < (argc - 1); ++i) ! { ! // strip off the '-' character ! string key = argv[i]; ! key = key.substr(1, key.length()); ! string value = argv[++i]; ! parseArg(key, value); ! } ! return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! void SettingsUNIX::handleRCFile() { - string line, key, value; - uInt32 equalPos; - - ifstream in(mySettingsInputFilename.c_str()); - if(!in || !in.is_open()) - return; - - while(getline(in, line)) - { - // Strip all whitespace and tabs from the line - uInt32 garbage; - while((garbage = line.find(" ")) != string::npos) - line.erase(garbage, 1); - while((garbage = line.find("\t")) != string::npos) - line.erase(garbage, 1); - - // Ignore commented and empty lines - if((line.length() == 0) || (line[0] == ';')) - continue; - - // Search for the equal sign and discard the line if its not found - if((equalPos = line.find("=")) == string::npos) - continue; - - key = line.substr(0, equalPos); - value = line.substr(equalPos + 1, line.length() - key.length() - 1); - - // Check for absent key or value - if((key.length() == 0) || (value.length() == 0)) - continue; - - parseArg(key, value); - } - - in.close(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! void SettingsUNIX::parseArg(string& key, string& value) { // Now set up the options by key ! if(key == "fps") ! { ! // They're setting the desired frame rate ! uInt32 rate = atoi(value.c_str()); ! if(rate < 1) ! cout << "Invalid rate " << rate << endl; ! else ! theDesiredFrameRate = rate; ! } ! else if(key == "paddle") { // They're trying to set the paddle emulation mode --- 51,91 ---- theRightJoystickNumber = 1; ! // Set up user specific filenames ! myHomeDir = getenv("HOME"); ! string basepath = myHomeDir + "/.stella"; ! if(access(basepath.c_str(), R_OK|W_OK|X_OK) != 0 ) ! mkdir(basepath.c_str(), 0777); ! myStateDir = basepath + "/state/"; ! if(access(myStateDir.c_str(), R_OK|W_OK|X_OK) != 0 ) ! mkdir(myStateDir.c_str(), 0777); ! myUserPropertiesFile = basepath + "/stella.pro"; ! mySystemPropertiesFile = "/etc/stella.pro"; ! myUserConfigFile = basepath + "/stellarc"; ! mySystemConfigFile = "/etc/stellarc"; ! // Set up the names of the input and output config files ! mySettingsOutputFilename = myUserConfigFile; ! if(access(myUserConfigFile.c_str(), R_OK) == 0) ! mySettingsInputFilename = myUserConfigFile; ! else ! mySettingsInputFilename = mySystemConfigFile; ! mySnapshotFile = ""; ! myStateFile = ""; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! SettingsUNIX::~SettingsUNIX() { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! void SettingsUNIX::setArgument(string& key, string& value) { // Now set up the options by key ! if(key == "paddle") { // They're trying to set the paddle emulation mode *************** *** 217,229 **** theAccurateTimingFlag = false; } - else if(key == "zoom") - { - // They're setting the initial window size - uInt32 zoom = atoi(value.c_str()); - if(zoom < 1) - cout << "Invalid zoom value " << zoom << endl; - else - theZoomLevel = zoom; - } else if(key == "volume") { --- 158,161 ---- *************** *** 237,259 **** theDesiredVolume = volume; } - else if(key == "ssdir") - { - theSnapshotDir = value; - } - else if(key == "ssname") - { - if((value != "md5sum") && (value != "romname")) - cout << "Invalid snapshot name " << value << endl; - else - theSnapshotName = value; - } - else if(key == "sssingle") - { - uInt32 option = atoi(value.c_str()); - if(option == 1) - theMultipleSnapshotFlag = false; - else if(option == 0) - theMultipleSnapshotFlag = true; - } else if(key == "sound") { --- 169,172 ---- *************** *** 263,274 **** theSoundDriver = value; } - else if(key == "keymap") - { - theKeymapList = value; - } - else if(key == "joymap") - { - theJoymapList = value; - } else if(key == "joyleft") { --- 176,179 ---- *************** *** 287,300 **** theRightJoystickNumber = joynum; } - #ifdef DEVELOPER_SUPPORT - else if(key == "Dmerge") - { - uInt32 option = atoi(value.c_str()); - if(option == 1) - theMergePropertiesFlag = true; - else if(option == 0) - theMergePropertiesFlag = false; - } - #endif else { --- 192,195 ---- *************** *** 304,318 **** // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! void SettingsUNIX::save() { ! if(!myConsole) ! return; ! ! ofstream out(mySettingsOutputFilename.c_str()); ! if(!out || !out.is_open()) ! return; ! out << "fps = " << theDesiredFrameRate << endl ! << "paddle = " << thePaddleMode << endl << "owncmap = " << theUsePrivateColormapFlag << endl << "fullscreen = " << theUseFullScreenFlag << endl --- 199,207 ---- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! string SettingsUNIX::getArguments() { ! ostringstream buf; ! buf << "paddle = " << thePaddleMode << endl << "owncmap = " << theUsePrivateColormapFlag << endl << "fullscreen = " << theUseFullScreenFlag << endl *************** *** 324,341 **** << "zoom = " << theZoomLevel << endl << "volume = " << theDesiredVolume << endl - << "ssdir = " << theSnapshotDir << endl - << "ssname = " << theSnapshotName << endl - << "sssingle = " << theMultipleSnapshotFlag << endl << "sound = " << theSoundDriver << endl - #ifdef DEVELOPER_SUPPORT - << "Dmerge = " << theMergePropertiesFlag << endl - #endif - << "keymap = " << myConsole->eventHandler().getKeymap() << endl - << "joymap = " << myConsole->eventHandler().getJoymap() << endl << "joyleft = " << theLeftJoystickNumber << endl ! << "joyright = " << theRightJoystickNumber << endl ! << endl; ! out.close(); } --- 213,221 ---- << "zoom = " << theZoomLevel << endl << "volume = " << theDesiredVolume << endl << "sound = " << theSoundDriver << endl << "joyleft = " << theLeftJoystickNumber << endl ! << "joyright = " << theRightJoystickNumber << endl; ! return buf.str(); } *************** *** 367,371 **** << " -showinfo <0|1> Shows some game info\n" << " -accurate <0|1> Accurate game timing (uses more CPU)\n" ! #ifdef HAVE_PNG << " -ssdir <path> The directory to save snapshot files to\n" << " -ssname <name> How to name the snapshot (romname or md5sum)\n" --- 247,251 ---- << " -showinfo <0|1> Shows some game info\n" << " -accurate <0|1> Accurate game timing (uses more CPU)\n" ! #ifdef SNAPSHOT_SUPPORT << " -ssdir <path> The directory to save snapshot files to\n" << " -ssname <name> How to name the snapshot (romname or md5sum)\n" *************** *** 393,395 **** --- 273,338 ---- #endif << endl; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + string SettingsUNIX::stateFilename(uInt32 state) + { + if(!myConsole) + return ""; + + ostringstream buf; + buf << myStateDir << myConsole->properties().get("Cartridge.MD5") + << ".st" << state; + + myStateFile = buf.str(); + return myStateFile; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + string SettingsUNIX::snapshotFilename() + { + if(!myConsole) + return ""; + + string filename; + string path = theSnapshotDir; + + if(theSnapshotName == "romname") + path = path + "/" + myConsole->properties().get("Cartridge.Name"); + else if(theSnapshotName == "md5sum") + path = path + "/" + myConsole->properties().get("Cartridge.MD5"); + + // Replace all spaces in name with underscores + replace(path.begin(), path.end(), ' ', '_'); + + // Check whether we want multiple snapshots created + if(theMultipleSnapshotFlag) + { + // Determine if the file already exists, checking each successive filename + // until one doesn't exist + filename = path + ".png"; + if(access(filename.c_str(), F_OK) == 0 ) + { + ostringstream buf; + for(uInt32 i = 1; ;++i) + { + buf.str(""); + buf << path << "_" << i << ".png"; + if(access(buf.str().c_str(), F_OK) == -1 ) + break; + } + filename = buf.str(); + } + } + else + filename = path + ".png"; + + mySnapshotFile = filename; + return mySnapshotFile; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + string SettingsUNIX::userHomeDir() + { + return myHomeDir; } Index: SettingsUNIX.hxx =================================================================== RCS file: /cvsroot/stella/stella/src/ui/common/SettingsUNIX.hxx,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SettingsUNIX.hxx 12 Sep 2003 18:08:54 -0000 1.2 --- SettingsUNIX.hxx 19 Sep 2003 15:45:01 -0000 1.3 *************** *** 37,41 **** Create a new UNIX settings object */ ! SettingsUNIX(const string& infile, const string& outfile); /** --- 37,41 ---- Create a new UNIX settings object */ ! SettingsUNIX(); /** *************** *** 46,70 **** public: /** ! Display the commandline settings for this UNIX version of Stella. ! @param message A short message about this version of Stella */ ! virtual void usage(string& message); /** ! Save the current settings to an rc file. */ ! virtual void save(); /** ! Let the frontend know about the console object. */ ! virtual void setConsole(Console* console); public: /** ! Handle UNIX commandline arguments */ ! bool handleCommandLineArgs(Int32 ac, char** av); public: --- 46,92 ---- public: /** ! This method should be called to set arguments. ! @param key The variable to be set ! @param value The value for the variable to hold */ ! virtual void setArgument(string& key, string& value); /** ! This method should be called to get system-specific settings. ! ! @return A string representing all the key/value pairs. */ ! virtual string getArguments(); /** ! This method should be called to get the filename of a state file ! given the state number. ! ! @return String representing the full path of the state filename. */ ! virtual string stateFilename(uInt32 state); ! ! /** ! This method should be called to get the filename of a snapshot. ! ! @return String representing the full path of the snapshot filename. ! */ ! virtual string snapshotFilename(); public: /** ! Display the commandline settings for this UNIX version of Stella. ! ! @param message A short message about this version of Stella */ ! void usage(string& message); ! ! /** ! Return the users UNIX home directory ! ! @param message A short message about this version of Stella ! */ ! string userHomeDir(); public: *************** *** 94,100 **** Int32 theDesiredVolume; - // Indicates what the desired frame rate is - uInt32 theDesiredFrameRate; - // Indicate which paddle mode we're using: // 0 - Mouse emulates paddle 0 --- 116,119 ---- *************** *** 118,132 **** private: ! void handleRCFile(); ! void parseArg(string& key, string& value); ! ! // The full pathname of the settings file for input ! string mySettingsInputFilename; ! ! // The full pathname of the settings file for output ! string mySettingsOutputFilename; ! ! // The global Console object ! Console* myConsole; }; --- 137,142 ---- private: ! // The UNIX home directory ! string myHomeDir; }; |