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
// 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>
@ -49,15 +49,12 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename,
myMediaSource = 0;
mySwitches = 0;
mySystem = 0;
myProperties = defaultProperties();
// Get the MD5 message-digest for the ROM image
string md5 = MD5(image, size);
// Search for the properties based on MD5
const Properties* properties = propertiesSet.getMD5(md5);
if(properties)
myProperties = properties;
propertiesSet.getMD5(md5, myProperties);
// TODO: At some point I belive we'll need to set the properties'
// 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
// 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"
@ -23,7 +23,6 @@
using a sed script
*/
static const char* theScript[] = {
#include "DefProps.def"
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: 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>
@ -25,47 +25,86 @@ PropertiesSet::PropertiesSet()
{
root = 0;
mySize = 0;
useMemList = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PropertiesSet::~PropertiesSet()
{
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;
while(current)
if(useMemList)
{
string currentMd5 = current->props->get("Cartridge.MD5");
if(currentMd5 == md5)
// Make sure tree isn't empty
if(root == 0)
{
found = true;
break;
properties = defProps;
return;
}
// Else, do a BST search for the node with the given md5
TreeNode *current = root;
while(current)
{
string currentMd5 = current->props->get("Cartridge.MD5");
if(currentMd5 == md5)
{
found = true;
break;
}
else
{
if(md5 < currentMd5)
current = current->left;
else
current = current->right;
}
}
if(found)
properties = *(current->props);
else
{
if(md5 < currentMd5)
current = current->left;
else
current = current->right;
}
properties = defProps;
}
if(found)
return current->props;
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
for(;;)
useMemList = useList;
defProps = defaults;
proStream.open(filename.c_str());
if(useMemList)
{
// Make sure the stream is still good or we're done
if(!in)
// Loop reading properties
for(;;)
{
break;
}
// Make sure the stream is still good or we're done
if(!proStream)
{
break;
}
// Get the property list associated with this profile
Properties properties(defaults);
properties.load(in);
// Get the property list associated with this profile
Properties properties(defProps);
properties.load(proStream);
// If the stream is still good then insert the properties
if(in)
{
insert(properties);
// If the stream is still good then insert the properties
if(proStream)
{
insert(properties);
}
}
}
}

View File

@ -13,12 +13,13 @@
// See the file "license" for information on usage and redistribution of
// 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
#define PROPERTIESSET_HXX
#include <fstream>
#include <string>
#include "bspf.hxx"
@ -54,19 +55,21 @@ class PropertiesSet
Get the property from the set with the given MD5.
@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.
@param in The input stream to use
@param string The input file 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
@ -130,5 +133,14 @@ class PropertiesSet
// The size of the properties bst (i.e. the number of properties in it)
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

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: 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>
@ -600,8 +600,7 @@ void usage()
}
/**
Setup the properties set by loading builtin defaults and then a
set of user specific ones from the file $HOME/.stella.pro
Setup the properties set by loading from the file stella.pro
@param set The properties set to setup
*/
@ -610,24 +609,8 @@ void setupProperties(PropertiesSet& set)
// Try to load the file stella.pro file
string filename = "stella.pro";
// See if we can open the file
ifstream stream(filename.c_str());
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());
}
// File was opened so load properties from it
set.load(filename, &Console::defaultProperties(), false);
}
/**

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.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>
@ -1144,8 +1144,7 @@ void usage()
/**
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
properties set.
then a system-wide file "/etc/stella.pro".
@param set The properties set to setup
*/
@ -1153,25 +1152,15 @@ void setupProperties(PropertiesSet& set)
{
string homePropertiesFile = getenv("HOME");
homePropertiesFile += "/.stella.pro";
string systemPropertiesFile = "/etc/stella.pro";
if(access(homePropertiesFile.c_str(), R_OK) == 0)
{
ifstream homeStream(homePropertiesFile.c_str());
set.load(homeStream, &Console::defaultProperties());
set.load(homePropertiesFile, &Console::defaultProperties(), false);
}
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(systemStream, &Console::defaultProperties());
}
else
{
strstream builtin;
for(const char** p = defaultPropertiesFile(); *p != 0; ++p)
{
builtin << *p << endl;
}
set.load(builtin, &Console::defaultProperties());
set.load(systemPropertiesFile, &Console::defaultProperties(), false);
}
}

View File

@ -709,55 +709,31 @@ DWORD CMainDlg::ReadRomData(
// search through the properties set for this MD5
PropertiesSet& propertiesSet = m_stella.GetPropertiesSet();
Properties properties;
propertiesSet.getMD5(md5, properties);
uInt32 setSize = propertiesSet.size();
for (uInt32 i = 0; i < setSize; ++i)
if ( ! pListData->m_strManufacturer.Set(
properties.get("Cartridge.Manufacturer").c_str() ) )
{
if (propertiesSet.get(i).get("Cartridge.MD5") == md5)
{
// got it!
break;
}
return ERROR_NOT_ENOUGH_MEMORY;
}
if (i != setSize)
if ( ! pListData->m_strName.Set(
properties.get("Cartridge.Name").c_str() ) )
{
const Properties& properties = propertiesSet.get(i);
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;
}
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",
md5.c_str(),
pListData->GetTextForColumn( CListData::FILENAME_COLUMN ) );
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;
}
}

View File

@ -78,7 +78,7 @@ DWORD CStellaXMain::Initialize(
return ERROR_SUCCESS;
}
m_pPropertiesSet = new PropertiesSet("Cartridge.Name");
m_pPropertiesSet = new PropertiesSet();
if ( m_pPropertiesSet == NULL )
{
return ERROR_NOT_ENOUGH_MEMORY;
@ -89,12 +89,13 @@ DWORD CStellaXMain::Initialize(
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());
if(stream)
{
// File was opened so load properties from it
m_pPropertiesSet->load(stream, &Console::defaultProperties());
stream.close();
m_pPropertiesSet->load(filename, &Console::defaultProperties());
}
else
{
@ -115,24 +116,6 @@ DWORD CStellaXMain::Initialize(
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
}

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: 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>
@ -1116,8 +1116,7 @@ void usage()
/**
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
properties set.
then a system-wide file "/etc/stella.pro".
@param set The properties set to setup
*/
@ -1125,25 +1124,15 @@ void setupProperties(PropertiesSet& set)
{
string homePropertiesFile = getenv("HOME");
homePropertiesFile += "/.stella.pro";
string systemPropertiesFile = "/etc/stella.pro";
if(access(homePropertiesFile.c_str(), R_OK) == 0)
{
ifstream homeStream(homePropertiesFile.c_str());
set.load(homeStream, &Console::defaultProperties());
set.load(homePropertiesFile, &Console::defaultProperties(), false);
}
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(systemStream, &Console::defaultProperties());
}
else
{
strstream builtin;
for(const char** p = defaultPropertiesFile(); *p != 0; ++p)
{
builtin << *p << endl;
}
set.load(builtin, &Console::defaultProperties());
set.load(systemPropertiesFile, &Console::defaultProperties(), false);
}
}