Changes to the PropertiesSet class which give a choice between storing the

properties in memory or always reading from the .pro file.  Removal of the
.pro file from the executable (now it MUST be included with the executable).

Typical improvements are 38% less memory usage and 46% reduction in
executable size.

Changes to all 4 frontends to accomodate changes made to the
PropertiesSet class.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@29 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2002-01-16 02:14:25 +00:00
parent bf5cae4704
commit 2f55b22d2b
9 changed files with 146 additions and 171 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Console.cxx,v 1.2 2002-01-08 17:11:32 stephena Exp $ // $Id: Console.cxx,v 1.3 2002-01-16 02:14:25 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -49,15 +49,12 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename,
myMediaSource = 0; myMediaSource = 0;
mySwitches = 0; mySwitches = 0;
mySystem = 0; mySystem = 0;
myProperties = defaultProperties();
// Get the MD5 message-digest for the ROM image // Get the MD5 message-digest for the ROM image
string md5 = MD5(image, size); string md5 = MD5(image, size);
// Search for the properties based on MD5 // Search for the properties based on MD5
const Properties* properties = propertiesSet.getMD5(md5); propertiesSet.getMD5(md5, myProperties);
if(properties)
myProperties = properties;
// TODO: At some point I belive we'll need to set the properties' // TODO: At some point I belive we'll need to set the properties'
// MD5 value so the user will be able to edit it. // MD5 value so the user will be able to edit it.

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DefProps.cxx,v 1.1.1.1 2001-12-27 19:54:21 bwmott Exp $ // $Id: DefProps.cxx,v 1.2 2002-01-16 02:14:25 stephena Exp $
//============================================================================ //============================================================================
#include "DefProps.hxx" #include "DefProps.hxx"
@ -23,7 +23,6 @@
using a sed script using a sed script
*/ */
static const char* theScript[] = { static const char* theScript[] = {
#include "DefProps.def"
0 0
}; };

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: PropsSet.cxx,v 1.2 2002-01-08 17:11:32 stephena Exp $ // $Id: PropsSet.cxx,v 1.3 2002-01-16 02:14:25 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -25,47 +25,86 @@ PropertiesSet::PropertiesSet()
{ {
root = 0; root = 0;
mySize = 0; mySize = 0;
useMemList = true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PropertiesSet::~PropertiesSet() PropertiesSet::~PropertiesSet()
{ {
deleteNode(root); deleteNode(root);
proStream.close();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Properties* PropertiesSet::getMD5(string md5) void PropertiesSet::getMD5(string md5, Properties &properties)
{ {
// Make sure tree isn't empty
if(root == 0)
return 0;
// Else, do a BST search for the node with the given md5
TreeNode *current = root;
bool found = false; bool found = false;
while(current) if(useMemList)
{ {
string currentMd5 = current->props->get("Cartridge.MD5"); // Make sure tree isn't empty
if(root == 0)
if(currentMd5 == md5)
{ {
found = true; properties = defProps;
break; return;
} }
else
// Else, do a BST search for the node with the given md5
TreeNode *current = root;
while(current)
{ {
if(md5 < currentMd5) string currentMd5 = current->props->get("Cartridge.MD5");
current = current->left;
if(currentMd5 == md5)
{
found = true;
break;
}
else else
current = current->right; {
if(md5 < currentMd5)
current = current->left;
else
current = current->right;
}
} }
}
if(found) if(found)
return current->props; properties = *(current->props);
else
properties = defProps;
}
else else
return 0; {
// Loop reading properties until required properties found
for(;;)
{
// Make sure the stream is still good or we're done
if(!proStream)
{
break;
}
// Get the property list associated with this profile
Properties currentProperties(defProps);
currentProperties.load(proStream);
// If the stream is still good then insert the properties
if(proStream)
{
string currentMd5 = currentProperties.get("Cartridge.MD5");
if(currentMd5 == md5)
{
properties = currentProperties;
return;
}
}
}
properties = defProps;
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -113,25 +152,33 @@ void PropertiesSet::deleteNode(TreeNode *node)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::load(istream& in, const Properties* defaults) void PropertiesSet::load(string filename, const Properties* defaults, bool useList)
{ {
// Loop reading properties useMemList = useList;
for(;;) defProps = defaults;
proStream.open(filename.c_str());
if(useMemList)
{ {
// Make sure the stream is still good or we're done // Loop reading properties
if(!in) for(;;)
{ {
break; // Make sure the stream is still good or we're done
} if(!proStream)
{
break;
}
// Get the property list associated with this profile // Get the property list associated with this profile
Properties properties(defaults); Properties properties(defProps);
properties.load(in); properties.load(proStream);
// If the stream is still good then insert the properties // If the stream is still good then insert the properties
if(in) if(proStream)
{ {
insert(properties); insert(properties);
}
} }
} }
} }

View File

@ -13,12 +13,13 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: PropsSet.hxx,v 1.2 2002-01-08 17:11:32 stephena Exp $ // $Id: PropsSet.hxx,v 1.3 2002-01-16 02:14:25 stephena Exp $
//============================================================================ //============================================================================
#ifndef PROPERTIESSET_HXX #ifndef PROPERTIESSET_HXX
#define PROPERTIESSET_HXX #define PROPERTIESSET_HXX
#include <fstream>
#include <string> #include <string>
#include "bspf.hxx" #include "bspf.hxx"
@ -54,18 +55,20 @@ class PropertiesSet
Get the property from the set with the given MD5. Get the property from the set with the given MD5.
@param md5 The md5 of the property to get @param md5 The md5 of the property to get
@return The property with the given MD5, or 0 if not found @param properties The property with the given MD5, or
the default property if not found
*/ */
Properties* getMD5(string md5); void getMD5(string md5, Properties& properties);
/** /**
Load properties from the specified input stream. Use the given Load properties from the specified file. Use the given
defaults properties as the defaults for any properties loaded. defaults properties as the defaults for any properties loaded.
@param in The input stream to use @param string The input file to use
@param defaults The default properties to use @param defaults The default properties to use
@param useList Flag to indicate storing properties in memory (default true)
*/ */
void load(istream& in, const Properties* defaults); void load(string filename, const Properties* defaults, bool useList = true);
/** /**
Save properties to the specified output stream Save properties to the specified output stream
@ -130,5 +133,14 @@ class PropertiesSet
// The size of the properties bst (i.e. the number of properties in it) // The size of the properties bst (i.e. the number of properties in it)
uInt32 mySize; uInt32 mySize;
// Whether to construct an in-memory list or rescan the file each time
bool useMemList;
// The file stream for the stella.pro file
ifstream proStream;
// The default properties set
const Properties* defProps;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: mainDOS.cxx,v 1.2 2002-01-10 20:03:05 stephena Exp $ // $Id: mainDOS.cxx,v 1.3 2002-01-16 02:14:25 stephena Exp $
//============================================================================ //============================================================================
#include <go32.h> #include <go32.h>
@ -600,8 +600,7 @@ void usage()
} }
/** /**
Setup the properties set by loading builtin defaults and then a Setup the properties set by loading from the file stella.pro
set of user specific ones from the file $HOME/.stella.pro
@param set The properties set to setup @param set The properties set to setup
*/ */
@ -610,24 +609,8 @@ void setupProperties(PropertiesSet& set)
// Try to load the file stella.pro file // Try to load the file stella.pro file
string filename = "stella.pro"; string filename = "stella.pro";
// See if we can open the file // File was opened so load properties from it
ifstream stream(filename.c_str()); set.load(filename, &Console::defaultProperties(), false);
if(stream)
{
// File was opened so load properties from it
set.load(stream, &Console::defaultProperties());
}
else
{
// Couldn't open the file so use the builtin properties file
strstream builtin;
for(const char** p = defaultPropertiesFile(); *p != 0; ++p)
{
builtin << *p << endl;
}
set.load(builtin, &Console::defaultProperties());
}
} }
/** /**

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: mainSDL.cxx,v 1.2 2002-01-10 19:53:33 stephena Exp $ // $Id: mainSDL.cxx,v 1.3 2002-01-16 02:14:25 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -1144,8 +1144,7 @@ void usage()
/** /**
Setup the properties set by first checking for a user file ".stella.pro", Setup the properties set by first checking for a user file ".stella.pro",
then a system-wide file "/etc/stella.pro", or finally a default then a system-wide file "/etc/stella.pro".
properties set.
@param set The properties set to setup @param set The properties set to setup
*/ */
@ -1153,25 +1152,15 @@ void setupProperties(PropertiesSet& set)
{ {
string homePropertiesFile = getenv("HOME"); string homePropertiesFile = getenv("HOME");
homePropertiesFile += "/.stella.pro"; homePropertiesFile += "/.stella.pro";
string systemPropertiesFile = "/etc/stella.pro";
if(access(homePropertiesFile.c_str(), R_OK) == 0) if(access(homePropertiesFile.c_str(), R_OK) == 0)
{ {
ifstream homeStream(homePropertiesFile.c_str()); set.load(homePropertiesFile, &Console::defaultProperties(), false);
set.load(homeStream, &Console::defaultProperties());
} }
else if(access("/etc/stella.pro", R_OK) == 0) else if(access(systemPropertiesFile.c_str(), R_OK) == 0)
{ {
ifstream systemStream("/etc/stella.pro"); set.load(systemPropertiesFile, &Console::defaultProperties(), false);
set.load(systemStream, &Console::defaultProperties());
}
else
{
strstream builtin;
for(const char** p = defaultPropertiesFile(); *p != 0; ++p)
{
builtin << *p << endl;
}
set.load(builtin, &Console::defaultProperties());
} }
} }

View File

@ -709,55 +709,31 @@ DWORD CMainDlg::ReadRomData(
// search through the properties set for this MD5 // search through the properties set for this MD5
PropertiesSet& propertiesSet = m_stella.GetPropertiesSet(); PropertiesSet& propertiesSet = m_stella.GetPropertiesSet();
Properties properties;
propertiesSet.getMD5(md5, properties);
uInt32 setSize = propertiesSet.size(); if ( ! pListData->m_strManufacturer.Set(
properties.get("Cartridge.Manufacturer").c_str() ) )
for (uInt32 i = 0; i < setSize; ++i)
{ {
if (propertiesSet.get(i).get("Cartridge.MD5") == md5) return ERROR_NOT_ENOUGH_MEMORY;
{
// got it!
break;
}
} }
if (i != setSize) if ( ! pListData->m_strName.Set(
properties.get("Cartridge.Name").c_str() ) )
{ {
const Properties& properties = propertiesSet.get(i); return ERROR_NOT_ENOUGH_MEMORY;
if ( ! pListData->m_strManufacturer.Set(
properties.get("Cartridge.Manufacturer").c_str() ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
if ( ! pListData->m_strName.Set(
properties.get("Cartridge.Name").c_str() ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
if (! pListData->m_strRarity.Set(
properties.get("Cartridge.Rarity").c_str() ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
if ( ! pListData->m_strNote.Set(
properties.get("Cartridge.Note").c_str() ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
} }
else
{
//
// Any output here should be appended to the emucore\stella.pro file
//
TRACE( "\"Cartridge.MD5\" \"%s\"\n\"Cartridge.Name\" \"%s\"\n\"\"\n", if (! pListData->m_strRarity.Set(
md5.c_str(), properties.get("Cartridge.Rarity").c_str() ) )
pListData->GetTextForColumn( CListData::FILENAME_COLUMN ) ); {
return ERROR_NOT_ENOUGH_MEMORY;
}
if ( ! pListData->m_strNote.Set(
properties.get("Cartridge.Note").c_str() ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
} }
} }

View File

@ -78,7 +78,7 @@ DWORD CStellaXMain::Initialize(
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
m_pPropertiesSet = new PropertiesSet("Cartridge.Name"); m_pPropertiesSet = new PropertiesSet();
if ( m_pPropertiesSet == NULL ) if ( m_pPropertiesSet == NULL )
{ {
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
@ -89,12 +89,13 @@ DWORD CStellaXMain::Initialize(
string filename( "stella.pro" ); string filename( "stella.pro" );
// See if we can open the file // See if we can open the file and load properties from it
ifstream stream(filename.c_str()); ifstream stream(filename.c_str());
if(stream) if(stream)
{ {
// File was opened so load properties from it // File was opened so load properties from it
m_pPropertiesSet->load(stream, &Console::defaultProperties()); stream.close();
m_pPropertiesSet->load(filename, &Console::defaultProperties());
} }
else else
{ {
@ -115,24 +116,6 @@ DWORD CStellaXMain::Initialize(
m_pPropertiesSet->insert( properties ); m_pPropertiesSet->insert( properties );
} }
#else
// @@ REVIEW: This is REALLY SLOW!
// Couldn't open the file so use the builtin properties file
strstream builtin;
for(const char** p = defaultPropertiesFile(); *p != 0; ++p)
{
builtin << *p << endl;
}
#ifdef _DEBUG
DWORD dwStartTick = ::GetTickCount();
#endif
m_pPropertiesSet->load( builtin, &Console::defaultProperties() );
#ifdef _DEBUG
TRACE( "Elapsed ticks for load = %ld", ::GetTickCount()-dwStartTick );
#endif
#endif #endif
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: mainX11.cxx,v 1.3 2002-01-10 19:22:58 stephena Exp $ // $Id: mainX11.cxx,v 1.4 2002-01-16 02:14:25 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -1116,8 +1116,7 @@ void usage()
/** /**
Setup the properties set by first checking for a user file ".stella.pro", Setup the properties set by first checking for a user file ".stella.pro",
then a system-wide file "/etc/stella.pro", or finally a default then a system-wide file "/etc/stella.pro".
properties set.
@param set The properties set to setup @param set The properties set to setup
*/ */
@ -1125,25 +1124,15 @@ void setupProperties(PropertiesSet& set)
{ {
string homePropertiesFile = getenv("HOME"); string homePropertiesFile = getenv("HOME");
homePropertiesFile += "/.stella.pro"; homePropertiesFile += "/.stella.pro";
string systemPropertiesFile = "/etc/stella.pro";
if(access(homePropertiesFile.c_str(), R_OK) == 0) if(access(homePropertiesFile.c_str(), R_OK) == 0)
{ {
ifstream homeStream(homePropertiesFile.c_str()); set.load(homePropertiesFile, &Console::defaultProperties(), false);
set.load(homeStream, &Console::defaultProperties());
} }
else if(access("/etc/stella.pro", R_OK) == 0) else if(access(systemPropertiesFile.c_str(), R_OK) == 0)
{ {
ifstream systemStream("/etc/stella.pro"); set.load(systemPropertiesFile, &Console::defaultProperties(), false);
set.load(systemStream, &Console::defaultProperties());
}
else
{
strstream builtin;
for(const char** p = defaultPropertiesFile(); *p != 0; ++p)
{
builtin << *p << endl;
}
set.load(builtin, &Console::defaultProperties());
} }
} }