The system strings segment is a fixed segment of the segment manager, which doesn't change during the game, thus move all the system strings code and variables inside the segment manager

svn-id: r49372
This commit is contained in:
Filippos Karapetis 2010-06-01 14:41:48 +00:00
parent 400542a1fe
commit e083c20da1
9 changed files with 44 additions and 48 deletions

View file

@ -54,7 +54,6 @@ SegManager::SegManager(ResourceManager *resMan) {
createClassTable();
}
// Destroy the object, free the memorys if allocated before
SegManager::~SegManager() {
resetSegMan();
}
@ -81,6 +80,25 @@ void SegManager::resetSegMan() {
createClassTable();
}
void SegManager::initSysStrings() {
sysStrings = (SystemStrings *)allocSegment(new SystemStrings(), &sysStringsSegment);
// Allocate static buffer for savegame and CWD directories
SystemString *strSaveDir = &sysStrings->_strings[SYS_STRING_SAVEDIR];
strSaveDir->_name = "savedir";
strSaveDir->_maxSize = MAX_SAVE_DIR_SIZE;
strSaveDir->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char));
// Set the savegame dir (actually, we set it to a fake value,
// since we cannot let the game control where saves are stored)
::strcpy(strSaveDir->_value, "");
// Allocate static buffer for the parser base
SystemString *strParserBase = &sysStrings->_strings[SYS_STRING_PARSER_BASE];
strParserBase->_name = "parser-base";
strParserBase->_maxSize = MAX_PARSER_BASE;
strParserBase->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char));
}
SegmentId SegManager::findFreeSegment() const {
// FIXME: This is a very crude approach: We find a free segment id by scanning
// from the start. This can be slow if the number of segments becomes large.
@ -393,10 +411,6 @@ DataStack *SegManager::allocateStack(int size, SegmentId *segid) {
return retval;
}
SystemStrings *SegManager::allocateSysStrings(SegmentId *segid) {
return (SystemStrings *)allocSegment(new SystemStrings(), segid);
}
void SegManager::freeHunkEntry(reg_t addr) {
if (addr.isNull()) {
warning("Attempt to free a Hunk from a null address");