Permalink
Browse files

stonesense now doesn't crash while starting for the second time

  • Loading branch information...
1 parent d841ba0 commit 4064cf25797462fc6ac61f578b7e4b6bd31bf6b6 @peterix peterix committed Aug 7, 2011
View
@@ -268,8 +268,8 @@ void Block::Draw(){
//Building
bool skipBuilding =
- (building.info.type == contentLoader.civzoneNum && !config.show_stockpiles) ||
- (building.info.type == contentLoader.stockpileNum && !config.show_zones);
+ (building.info.type == contentLoader->civzoneNum && !config.show_stockpiles) ||
+ (building.info.type == contentLoader->stockpileNum && !config.show_zones);
if(building.info.type != BUILDINGTYPE_NA && !skipBuilding)
{
@@ -372,11 +372,11 @@ void Block::Draw(){
//if(waterlevel == 7) waterlevel--;
if(water.type == 0)
{
- contentLoader.water[water.index-1].sprite.draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2));
+ contentLoader->water[water.index-1].sprite.draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2));
}
else
{
- contentLoader.lava[water.index-1].sprite.draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2));
+ contentLoader->lava[water.index-1].sprite.draw_world(x, y, z, this, (chopThisBlock && this->z == ownerSegment->z + ownerSegment->sizez -2));
}
}
View
@@ -32,8 +32,8 @@ int getDirectionFromString(const char* strDir)
int getBuildingFromString(const char* strType)
{
- for (uint32_t i=0; i<contentLoader.classIdStrings.size(); i++){
- if (contentLoader.classIdStrings[i].compare(strType) == 0)
+ for (uint32_t i=0; i<contentLoader->classIdStrings.size(); i++){
+ if (contentLoader->classIdStrings[i].compare(strType) == 0)
{
return i;
}
@@ -42,8 +42,8 @@ BuildingConfiguration::~BuildingConfiguration(void)
void DumpBuildingNamesToDisk(){
FILE* fp = fopen("buildingdump.txt", "w");
if(!fp) return;
- for(uint32_t j=0; j < contentLoader.classIdStrings.size(); j++){
- fprintf(fp, "%i:%s\n",j, contentLoader.classIdStrings[j].c_str());
+ for(uint32_t j=0; j < contentLoader->classIdStrings.size(); j++){
+ fprintf(fp, "%i:%s\n",j, contentLoader->classIdStrings[j].c_str());
}
fclose(fp);
}
View
@@ -124,7 +124,7 @@ bool addSingleColorConfig( TiXmlElement* elemRoot)
//parse colors
TiXmlElement* elemColor = elemRoot->FirstChildElement("color");
while( elemColor ){
- parseColorElement( elemColor, contentLoader.colorConfigs);
+ parseColorElement( elemColor, contentLoader->colorConfigs);
elemColor = elemColor->NextSiblingElement("color");
}
}
@@ -283,7 +283,7 @@ bool addSingleBuildingConfig( TiXmlElement* elemRoot, vector<BuildingConfigurat
return false;
}
- int gameID = TranslateBuildingName(strGameID, contentLoader.classIdStrings );
+ int gameID = TranslateBuildingName(strGameID, contentLoader->classIdStrings );
if (gameID == INVALID_INDEX) {
return false;
@@ -313,7 +313,7 @@ bool addSingleCustomBuildingConfig( TiXmlElement* elemRoot, vector<BuildingConf
return false;
}
- int gameID = TranslateBuildingName(strGameID, contentLoader.custom_workshop_types );
+ int gameID = TranslateBuildingName(strGameID, contentLoader->custom_workshop_types );
if (gameID == INVALID_INDEX) {
return false;
View
@@ -8,7 +8,7 @@
#include "dfhack/depends/tinyxml/tinyxml.h"
#include "GUI.h"
-ContentLoader contentLoader;
+ContentLoader * contentLoader;
@@ -172,7 +172,7 @@ bool ContentLoader::Load( DFHack::Core& DF){
}
try
{
- contentLoader.MemInfo = DF.vinfo;
+ contentLoader->MemInfo = DF.vinfo;
}
catch(exception &e)
{
@@ -211,8 +211,8 @@ bool ContentLoader::Load( DFHack::Core& DF){
}
}
- civzoneNum = TranslateBuildingName("building_civzonest", contentLoader.classIdStrings );
- stockpileNum = TranslateBuildingName("building_stockpilest", contentLoader.classIdStrings );
+ civzoneNum = TranslateBuildingName("building_civzonest", contentLoader->classIdStrings );
+ stockpileNum = TranslateBuildingName("building_stockpilest", contentLoader->classIdStrings );
//DumpPrefessionNamesToDisk(professionStrings, "priofessiondump.txt");
//DumpPrefessionNamesToDisk(classIdStrings, "buildingdump.txt");
@@ -224,7 +224,7 @@ bool ContentLoader::Load( DFHack::Core& DF){
//time to copy all the junk from mats to contentloader.
this->organic = Mats->organic;
this->inorganic = Mats->inorganic;
- contentLoader.obsidian = lookupMaterialIndex(INORGANIC, "OBSIDIAN");
+ contentLoader->obsidian = lookupMaterialIndex(INORGANIC, "OBSIDIAN");
loadGraphicsFromDisk(); //these get destroyed when flushImgFiles is called.
bool overallResult = parseContentIndexFile( "index.txt" );
@@ -483,19 +483,19 @@ int lookupMaterialIndex(int matType, const char* strValue)
// for appropriate elements, look up subtype
if (matType == INORGANIC && !config.skipInorganicMats)
{
- return lookupIndexedType(strValue,contentLoader.inorganic);
+ return lookupIndexedType(strValue,contentLoader->inorganic);
}
else if (matType == WOOD && !config.skipOrganicMats)
{
- return lookupIndexedType(strValue,contentLoader.organic);
+ return lookupIndexedType(strValue,contentLoader->organic);
}
else if (matType == PLANTCLOTH && !config.skipOrganicMats)
{
- return lookupIndexedType(strValue,contentLoader.organic);
+ return lookupIndexedType(strValue,contentLoader->organic);
}
else if (matType == LEATHER && !config.skipCreatureTypes)
{
- return lookupIndexedType(strValue,contentLoader.Mats->race);
+ return lookupIndexedType(strValue,contentLoader->Mats->race);
}
else
{
@@ -565,24 +565,24 @@ const char *lookupMaterialName(int matType,int matIndex)
// for appropriate elements, look up subtype
if ((matType == INORGANIC) && (!config.skipInorganicMats))
{
- if(matIndex < contentLoader.inorganic.size())
+ if(matIndex < contentLoader->inorganic.size())
{
- return contentLoader.inorganic[0].id.c_str();
+ return contentLoader->inorganic[0].id.c_str();
}
else return NULL;
}
else if ((matType == WOOD) && (!config.skipOrganicMats))
{
- typeVector=&(contentLoader.organic);
+ typeVector=&(contentLoader->organic);
}
else if ((matType == PLANTCLOTH) && (!config.skipOrganicMats))
{
- typeVector=&(contentLoader.organic);
+ typeVector=&(contentLoader->organic);
}
else if (matType == LEATHER)
{
if(!config.skipCreatureTypes)
- typeVector=&(contentLoader.Mats->race);
+ typeVector=&(contentLoader->Mats->race);
}
else
{
@@ -602,7 +602,7 @@ const char *lookupTreeName(int matIndex)
return NULL;
vector<t_matgloss>* typeVector;
// for appropriate elements, look up subtype
- typeVector=&(contentLoader.organic);
+ typeVector=&(contentLoader->organic);
if (matIndex >= typeVector->size())
return NULL;
return (*typeVector)[matIndex].id.c_str();
@@ -734,21 +734,21 @@ void ContentLoader::flushCreatureConfig()
}
ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex)
{
- if (matType >= contentLoader.colorConfigs.size())
+ if (matType >= contentLoader->colorConfigs.size())
{
return al_map_rgb(255, 255, 255);
}
if (matIndex < 0)
{
- return contentLoader.colorConfigs.at(matType).color;
+ return contentLoader->colorConfigs.at(matType).color;
}
- if (matIndex >= contentLoader.colorConfigs.at(matType).colorMaterials.size())
+ if (matIndex >= contentLoader->colorConfigs.at(matType).colorMaterials.size())
{
return al_map_rgb(255, 255, 255);
}
- if (contentLoader.colorConfigs.at(matType).colorMaterials.at(matIndex).colorSet)
+ if (contentLoader->colorConfigs.at(matType).colorMaterials.at(matIndex).colorSet)
{
- return contentLoader.colorConfigs.at(matType).colorMaterials.at(matIndex).color;
+ return contentLoader->colorConfigs.at(matType).colorMaterials.at(matIndex).color;
}
else return al_map_rgb(255, 255, 255);
}
View
@@ -67,8 +67,7 @@ class ContentLoader{
int obsidian;
};
-//singleton instance
-extern ContentLoader contentLoader;
+extern ContentLoader * contentLoader;
extern const char* getDocument(TiXmlNode* element);
extern void contentError(const char* message, TiXmlNode* element);
View
@@ -41,7 +41,7 @@ void DumpProfessionsToDisk(){
FILE* fp = fopen("dump.txt", "w");
if(!fp) return;
string proffStr;
- for(int j=0; (proffStr = contentLoader.professionStrings[j]) != "" ; j++){
+ for(int j=0; (proffStr = contentLoader->professionStrings[j]) != "" ; j++){
fprintf(fp, "%i:%s\n",j, proffStr.c_str());
}
fclose(fp);
@@ -55,10 +55,10 @@ int translateProfession(const char* currentProf)
if (currentProf == NULL || currentProf[0]==0)
return INVALID_INDEX;
- dfNumJobs = contentLoader.professionStrings.size();
+ dfNumJobs = contentLoader->professionStrings.size();
for(j=0; j < dfNumJobs; j++)
{
- proffStr = contentLoader.professionStrings[j];
+ proffStr = contentLoader->professionStrings[j];
if( proffStr.compare( currentProf ) == 0)
{
//assign ID
@@ -78,9 +78,9 @@ void pushCreatureConfig( vector<vector<CreatureConfiguration>*>& knownCreatures,
{
//resize using hint from creature name list
unsigned int newsize = gameID +1;
- if (newsize <= contentLoader.Mats->race.size())
+ if (newsize <= contentLoader->Mats->race.size())
{
- newsize = contentLoader.Mats->race.size() + 1;
+ newsize = contentLoader->Mats->race.size() + 1;
}
knownCreatures.resize(newsize);
}
@@ -97,7 +97,7 @@ void pushCreatureConfig( vector<vector<CreatureConfiguration>*>& knownCreatures,
bool addSingleCreatureConfig( TiXmlElement* elemCreature, vector<vector<CreatureConfiguration>*>& knownCreatures, int basefile ){
if(config.skipCreatureTypes)
return false;
- int gameID = lookupIndexedType(elemCreature->Attribute("gameID"),contentLoader.Mats->race);
+ int gameID = lookupIndexedType(elemCreature->Attribute("gameID"),contentLoader->Mats->race);
if (gameID == INVALID_INDEX)
return false;
const char* sheetIndexStr;
View
@@ -302,7 +302,7 @@ void DrawCreatureText(int drawx, int drawy, t_creature* creature ){
{
if(!config.skipCreatureTypes)
draw_textf_border(font, al_map_rgb(255,255,255), drawx, drawy-(WALLHEIGHT+al_get_font_line_height(font)), 0,
- "[%s]", contentLoader.Mats->race.at(creature->race).id.c_str());
+ "[%s]", contentLoader->Mats->race.at(creature->race).id.c_str());
}
}
@@ -415,12 +415,12 @@ void ReadCreaturesToSegment( DFHack::Core& DF, WorldSegment* segment)
CreatureConfiguration *GetCreatureConfig( t_creature* c ){
//find list for creature type
vector<CreatureConfiguration>* creatureData;
- uint32_t num = (uint32_t)contentLoader.creatureConfigs.size();
+ uint32_t num = (uint32_t)contentLoader->creatureConfigs.size();
if (c->race >= num)
{
return NULL;
}
- creatureData = contentLoader.creatureConfigs[c->race];
+ creatureData = contentLoader->creatureConfigs[c->race];
if (creatureData == NULL)
{
return NULL;
View
@@ -52,18 +52,18 @@ void parseFluidElement( TiXmlElement* elemFluid, int basefile)
if(type)
{
- if(contentLoader.lava[level-1].fluidset == 0)
+ if(contentLoader->lava[level-1].fluidset == 0)
{
- contentLoader.lava[level-1].sprite = tempSprite;
- contentLoader.lava[level-1].fluidset = 1;
+ contentLoader->lava[level-1].sprite = tempSprite;
+ contentLoader->lava[level-1].fluidset = 1;
}
}
else
{
- if(contentLoader.water[level-1].fluidset == 0)
+ if(contentLoader->water[level-1].fluidset == 0)
{
- contentLoader.water[level-1].sprite = tempSprite;
- contentLoader.water[level-1].fluidset = 1;
+ contentLoader->water[level-1].sprite = tempSprite;
+ contentLoader->water[level-1].fluidset = 1;
}
}
}
View
32 GUI.cpp
@@ -359,7 +359,7 @@ void drawDebugCursorAndInfo(){
"Coord:(%i,%i,%i)", debugCursor.x, debugCursor.y, debugCursor.z);
draw_textf_border(font, al_map_rgb(255,255,255), 2, al_get_bitmap_height(al_get_target_bitmap())-20-(i--*al_get_font_line_height(font)), 0,
- "Game Mode:%i, Control Mode:%i", contentLoader.gameMode.g_mode, contentLoader.gameMode.g_type);
+ "Game Mode:%i, Control Mode:%i", contentLoader->gameMode.g_mode, contentLoader->gameMode.g_type);
if(!b) return;
@@ -448,15 +448,15 @@ void drawDebugCursorAndInfo(){
const char* subMatName = lookupMaterialName(b->building.info.material.type,b->building.info.material.index);
draw_textf_border(font, al_map_rgb(255,255,255), 2, al_get_bitmap_height(al_get_target_bitmap())-20-(i--*al_get_font_line_height(font)), 0,
"Building: %s(%i,0x%x) Material: %s%s%s (%d,%d)",
- contentLoader.classIdStrings.at(b->building.info.type).c_str(),
+ contentLoader->classIdStrings.at(b->building.info.type).c_str(),
b->building.info.type, b->building.info.vtable,
matName?matName:"Unknown",subMatName?"/":"",subMatName?subMatName:"",
b->building.info.material.type,b->building.info.material.index);
if(b->building.custom_building_type != -1)
{
draw_textf_border(font, al_map_rgb(255,255,255), 2, al_get_bitmap_height(al_get_target_bitmap())-20-(i--*al_get_font_line_height(font)), 0,
- "Custom workshop type %s (%d)", contentLoader.custom_workshop_types[b->building.custom_building_type].c_str(),b->building.custom_building_type);
+ "Custom workshop type %s (%d)", contentLoader->custom_workshop_types[b->building.custom_building_type].c_str(),b->building.custom_building_type);
}
}
@@ -465,15 +465,15 @@ void drawDebugCursorAndInfo(){
if(!config.skipCreatureTypes)
draw_textf_border(font, al_map_rgb(255,255,255), 2, al_get_bitmap_height(al_get_target_bitmap())-20-(i--*al_get_font_line_height(font)), 0,
"Creature:%s(%i) Job:%s",
- contentLoader.Mats->race.at(b->creature->race).id.c_str(), b->creature->race,
- contentLoader.professionStrings.at(b->creature->profession).c_str());
+ contentLoader->Mats->race.at(b->creature->race).id.c_str(), b->creature->race,
+ contentLoader->professionStrings.at(b->creature->profession).c_str());
char strCreature[150] = {0};
generateCreatureDebugString( b->creature, strCreature );
//memset(strCreature, -1, 50);
try{
draw_textf_border(font, al_map_rgb(255,255,255), 2, al_get_bitmap_height(al_get_target_bitmap())-20-(i--*al_get_font_line_height(font)), 0,
- "flag1: %s Sex: %d Mood: %d Job: %s", strCreature, b->creature->sex + 1, b->creature->mood, (b->creature->current_job.active?contentLoader.MemInfo->getJob(b->creature->current_job.jobType).c_str():""));
+ "flag1: %s Sex: %d Mood: %d Job: %s", strCreature, b->creature->sex + 1, b->creature->mood, (b->creature->current_job.active?contentLoader->MemInfo->getJob(b->creature->current_job.jobType).c_str():""));
}
catch(exception &e)
{
@@ -485,18 +485,18 @@ void drawDebugCursorAndInfo(){
int xx = 2;
for(unsigned int j = 0; j<b->creature->nbcolors ; j++)
{
- if(contentLoader.Mats->raceEx.at(b->creature->race).castes.at(b->creature->caste).ColorModifier.at(j).colorlist.size() > b->creature->color[j])
+ if(contentLoader->Mats->raceEx.at(b->creature->race).castes.at(b->creature->caste).ColorModifier.at(j).colorlist.size() > b->creature->color[j])
{
- uint32_t cr_color = contentLoader.Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].colorlist[b->creature->color[j]];
- if(cr_color < contentLoader.Mats->color.size())
+ uint32_t cr_color = contentLoader->Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].colorlist[b->creature->color[j]];
+ if(cr_color < contentLoader->Mats->color.size())
{
draw_textf_border(font,
al_map_rgb_f(
- contentLoader.Mats->color[cr_color].red,
- contentLoader.Mats->color[cr_color].green,
- contentLoader.Mats->color[cr_color].blue), xx, yy, 0,
- "%s ", contentLoader.Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].part.c_str());
- xx += get_textf_width(font, "%s ", contentLoader.Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].part.c_str());
+ contentLoader->Mats->color[cr_color].red,
+ contentLoader->Mats->color[cr_color].green,
+ contentLoader->Mats->color[cr_color].blue), xx, yy, 0,
+ "%s ", contentLoader->Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].part.c_str());
+ xx += get_textf_width(font, "%s ", contentLoader->Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].part.c_str());
}
}
}
@@ -631,7 +631,7 @@ void DrawSpriteFromSheet( int spriteNum, ALLEGRO_BITMAP* spriteSheet, ALLEGRO_CO
10, 60 , SPRITEWIDTH, SPRITEHEIGHT);
*/
//draw_trans_sprite(target, tiny, x, y);
- if(b && (!b->designation.bits.pile) && config.fog_of_war && (contentLoader.gameMode.g_mode == GAMEMODE_ADVENTURE))
+ if(b && (!b->designation.bits.pile) && config.fog_of_war && (contentLoader->gameMode.g_mode == GAMEMODE_ADVENTURE))
{
color.r *= 0.25f;
color.g *= 0.25f;
@@ -768,7 +768,7 @@ void paintboard(){
draw_textf_border(font, al_map_rgb(255,255,255), 10, 2*al_get_font_line_height(font), 0, "FPS: %.2f", 1.0/time_since_last_frame);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 5*al_get_font_line_height(font), 0, "Draw: %ims", DrawTime);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 6*al_get_font_line_height(font), 0, "D1: %i", blockFactory.getPoolSize());
- draw_textf_border(font, al_map_rgb(255,255,255), 10, 7*al_get_font_line_height(font), 0, "%i/%i/%i, %i:%i", contentLoader.currentDay+1, contentLoader.currentMonth+1, contentLoader.currentYear, contentLoader.currentHour, (contentLoader.currentTickRel*60)/50);
+ draw_textf_border(font, al_map_rgb(255,255,255), 10, 7*al_get_font_line_height(font), 0, "%i/%i/%i, %i:%i", contentLoader->currentDay+1, contentLoader->currentMonth+1, contentLoader->currentYear, contentLoader->currentHour, (contentLoader->currentTickRel*60)/50);
draw_textf_border(font, al_map_rgb(255,255,255), 10, 8*al_get_font_line_height(font), 0, "%i Sprites drawn, %i tiles drawn, %.1f sprites per tile.", config.drawcount, config.tilecount, ((float)config.drawcount/(float)config.tilecount));
drawDebugCursorAndInfo();
}
Oops, something went wrong.

0 comments on commit 4064cf2

Please sign in to comment.