Skip to content

Commit

Permalink
fixed some crashes that occur when re-loading configs.
Browse files Browse the repository at this point in the history
should be ok now.
  • Loading branch information
RosaryMala committed Apr 24, 2010
1 parent 3762a5d commit 701514f
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 36 deletions.
4 changes: 4 additions & 0 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ void parseConfigLine( string line ){
if(value < 0) value = 0;
config.colors.white_b = value;
}
if( line.find("[USE_OPENGL") != -1){
string result = parseStrFromLine( "USE_OPENGL", line );
config.opengl = (result == "YES");
}
}


Expand Down
48 changes: 26 additions & 22 deletions ContentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ bool ContentLoader::Load(API& DF){
treeConfigs.clear();
shrubConfigs.clear();
flushImgFiles();
inorganicMaterials.clear();
organicMaterials.clear();
creatureMaterials.clear();
classIdStrings.clear();
professionStrings.clear();

// This is an extra suspend/resume, but it only happens when reloading the config
// ie not enough to worry about
Expand All @@ -72,36 +67,45 @@ bool ContentLoader::Load(API& DF){
//classIdStrings = *tempClasses;

DFHack::Materials * Mats = DF.getMaterials();
if(inorganicMaterials.empty())
Mats->ReadInorganicMaterials (inorganicMaterials);
if(organicMaterials.empty())
Mats->ReadOrganicMaterials (organicMaterials);
if(creatureMaterials.empty())
Mats->ReadCreatureTypes (creatureMaterials);
Bld = DF.getBuildings();
DFHack::memory_info *mem = DF.getMemoryInfo();
for(int i=0;; i++)
if(professionStrings.empty())
{
string temp;
try
for(int i=0;; i++)
{
temp = mem->getProfession(i);
}
catch(exception &)
{
break;
}
if(temp[0])
{
professionStrings.push_back(temp);
string temp;
try
{
temp = mem->getProfession(i);
}
catch(exception &)
{
break;
}
if(temp[0])
{
professionStrings.push_back(temp);
}
}
}

for(int i = 0; ; i++)
if(classIdStrings.empty())
{
string temp;
if(!mem->resolveClassIDToClassname(i, temp))
for(int i = 0; ; i++)
{
break;
string temp;
if(!mem->resolveClassIDToClassname(i, temp))
{
break;
}
classIdStrings.push_back(temp);
}
classIdStrings.push_back(temp);
}

//DumpPrefessionNamesToDisk(professionStrings, "priofessiondump.txt");
Expand Down
4 changes: 2 additions & 2 deletions CreatureConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void DumpProfessionsToDisk(){
FILE* fp = fopen("dump.txt", "w");
if(!fp) return;
string proffStr;
for(int j=0; (proffStr = dfMemoryInfo->getProfession(j)) != "" ; j++){
for(int j=0; (proffStr = contentLoader.professionStrings[j]) != "" ; j++){
fprintf(fp, "%i:%s\n",j, proffStr.c_str());
}
fclose(fp);
Expand All @@ -59,7 +59,7 @@ int translateProfession(const char* currentProf)
{
for(j=0; true; j++)
{
proffStr = dfMemoryInfo->getProfession(j);
proffStr = contentLoader.professionStrings[j];
if( proffStr.compare( currentProf ) == 0)
{
//assign ID
Expand Down
3 changes: 0 additions & 3 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ int MiniMapSegmentWidth =0;
int MiniMapSegmentHeight =0;
double oneBlockInPixels = 0;

ALLEGRO_BITMAP* IMGIcon;
ALLEGRO_BITMAP* IMGObjectSheet;
ALLEGRO_BITMAP* IMGCreatureSheet;
ALLEGRO_BITMAP* IMGRampSheet;
Expand Down Expand Up @@ -630,8 +629,6 @@ void loadGraphicsFromDisk(){
draw_textf_border(font, al_get_bitmap_width(al_get_target_bitmap())/2, al_get_bitmap_height(al_get_target_bitmap())/2, ALLEGRO_ALIGN_CENTRE, "Loading...");
al_flip_display();
int index;
index = loadImgFile("stonesense.png");
IMGIcon = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("objects.png");
IMGObjectSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("creatures.png");
Expand Down
1 change: 0 additions & 1 deletion GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ extern int MiniMapSegmentWidth;
extern int MiniMapSegmentHeight;
extern double oneBlockInPixels;

extern ALLEGRO_BITMAP* IMGIcon;
extern ALLEGRO_BITMAP* IMGObjectSheet;
extern ALLEGRO_BITMAP* IMGCreatureSheet;
extern ALLEGRO_BITMAP* IMGRampSheet;
Expand Down
1 change: 1 addition & 0 deletions UserInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ void doKeys(int Key)
paintboard();
}
if(Key == ALLEGRO_KEY_G){
flushImgFiles();
loadGraphicsFromDisk();
timeToReloadConfig = true;
timeToReloadSegment = true;
Expand Down
1 change: 1 addition & 0 deletions commonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ typedef struct {
bool cache_images;
int imageCacheSize;
dfColors colors;
bool opengl;
} GameConfiguration;


Expand Down
2 changes: 0 additions & 2 deletions creatures/Wildlife.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<variant prof="MERCHANT" sex="M" sheetIndex="102" />
<variant prof="TRADER" sex="F" sheetIndex="103" />
<variant prof="MERCHANT" sex="F" sheetIndex="103" />
<variant prof="DIPLOMAT" sex="M" sheetIndex="106" />
<variant prof="DIPLOMAT" sex="F" sheetIndex="107" />
<Profession name="CHILD" sex="M" sheetIndex="120" />
<Profession name="CHILD" sex="F" sheetIndex="121" />
<Profession name="BABY" sheetIndex="122" />
Expand Down
1 change: 0 additions & 1 deletion index.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Remember: configs at the top of the list
# get precedence over those below

spam/spam.xml
terrain/index.txt
creatures/index.txt
buildings/index.txt
Expand Down
8 changes: 5 additions & 3 deletions init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ Shows building graphics for stockpiles. (Toggle with 'u')
Fog color, and alpha at the bottom z-level.
Setting the alpha to 0 disables fog, for a slight performance increase.
Color and alpha ranges are 0 (min) to 255 (max)
[SHOW_FOG:YES]
[SHOW_FOG:NO]
[FOG_RED:95]
[FOG_GREEN:95]
[FOG_BLUE:160]
[FOG_ALPHA:5]
[FOG_ALPHA:32]

Background color. setting this the same as the fog color produces a nice effect.
[BACK_RED:95]
Expand Down Expand Up @@ -107,8 +107,10 @@ This set's the preferred size of the internal image cache. If your videocard doe
a smaller size is used.
[IMAGE_CACHE_SIZE:4096]

These are the colors used by DF. they can be used by tilesets, if desired.
Force OpenGL if YES, otherwise defaults to Directx
[USE_OPENGL:YES]

These are the colors used by DF. they can be used by tilesets, if desired.
[BLACK_R:0]
[BLACK_G:0]
[BLACK_B:0]
Expand Down
7 changes: 5 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ ALLEGRO_EVENT_QUEUE *queue;

ALLEGRO_EVENT event;

ALLEGRO_BITMAP* IMGIcon;

int mouse_x, mouse_y, mouse_z;
unsigned int mouse_b;
bool key[ALLEGRO_KEY_MAX];
Expand Down Expand Up @@ -207,7 +209,7 @@ int main(void)


int gfxMode = config.Fullscreen ? ALLEGRO_FULLSCREEN : ALLEGRO_WINDOWED;
al_set_new_display_flags(gfxMode|ALLEGRO_RESIZABLE|ALLEGRO_OPENGL);
al_set_new_display_flags(gfxMode|ALLEGRO_RESIZABLE|(config.opengl ? ALLEGRO_OPENGL : 0));
display = al_create_display(config.screenWidth, config.screenHeight);
if(!display)
{
Expand All @@ -221,11 +223,12 @@ int main(void)
return 1;
}

IMGIcon = load_bitmap_withWarning("stonesense.png");
al_set_display_icon(IMGIcon);

//al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba_f(1.0, 1.0, 1.0, 1.0));
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_ONE, al_map_rgba(255, 255, 255, 255));
loadGraphicsFromDisk();
al_set_display_icon(IMGIcon);
al_clear_to_color(al_map_rgb(0,0,0));
draw_textf_border(font, al_get_bitmap_width(al_get_target_bitmap())/2, al_get_bitmap_height(al_get_target_bitmap())/2, ALLEGRO_ALIGN_CENTRE, "Starting up...");
al_flip_display();
Expand Down

0 comments on commit 701514f

Please sign in to comment.