Skip to content

Commit

Permalink
Make stonesense use DF/stonesense for all resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed Aug 7, 2011
1 parent 4064cf2 commit 9c99824
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 86 deletions.
5 changes: 0 additions & 5 deletions ColorConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ void parseColorElement( TiXmlElement* elemColor, vector<ColorConfiguration> & co
}
}

void flushColorConfig(vector<ColorConfiguration>& config)
{
config.clear();
}

bool addSingleColorConfig( TiXmlElement* elemRoot)
{
string elementType = elemRoot->Value();
Expand Down
37 changes: 21 additions & 16 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,21 +554,26 @@ void parseConfigLine( string line ){
}


bool loadConfigFile(){
string line;
ifstream myfile ("init.txt");
if (myfile.is_open() == false)
{
cout << "Cannot find init file" << endl;
return false;
}
bool loadConfigFile()
{
string line;
ALLEGRO_PATH * p =al_create_path("stonesense/init.txt");
const char * path = al_path_cstr(p,ALLEGRO_NATIVE_PATH_SEP);
ifstream myfile (path);
if (myfile.is_open() == false)
{
cout << "Cannot find init file" << endl;
al_destroy_path(p);
return false;
}

while ( !myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
parseConfigLine( line );
}
myfile.close();
return true;
while ( !myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
parseConfigLine( line );
}
myfile.close();
al_destroy_path(p);
return true;
}
16 changes: 12 additions & 4 deletions ContentBuildingReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,25 @@ inline bool readNode(SpriteNode* node, TiXmlElement* elemNode, TiXmlElement* ele

bool includeFile(SpriteNode* node, TiXmlElement* includeNode, SpriteBlock* &oldSibling)
{
string filenameStr("buildings/include/");
filenameStr.append(includeNode->Attribute("file"));
// get path... ugly
char configfilepath[FILENAME_BUFFERSIZE] = {0};
const char* documentRef = getDocument(includeNode);

TiXmlDocument doc( filenameStr.c_str() );
if (!getLocalFilename(configfilepath,includeNode->Attribute("file"),documentRef))
{
return false;
}
ALLEGRO_PATH * incpath = al_create_path(configfilepath);
al_append_path_component(incpath, "include");
TiXmlDocument doc( al_path_cstr(incpath, ALLEGRO_NATIVE_PATH_SEP) );
al_destroy_path(incpath);
bool loadOkay = doc.LoadFile();
TiXmlHandle hDoc(&doc);
TiXmlElement* elemParent;
if(!loadOkay)
{
contentError("Include failed",includeNode);
WriteErr("File load failed: %s\n",filenameStr.c_str());
WriteErr("File load failed: %s\n",configfilepath);
WriteErr("Line %d: %s\n",doc.ErrorRow(),doc.ErrorDesc());
return false;
}
Expand Down
14 changes: 9 additions & 5 deletions ContentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ContentLoader::~ContentLoader(void)
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainBlockConfigs);
flushCreatureConfig();
flushColorConfig(colorConfigs);
colorConfigs.clear();
}

void DumpMaterialNamesToDisk(vector<t_matgloss> material, const char* filename){
Expand Down Expand Up @@ -52,7 +52,7 @@ bool ContentLoader::Load( DFHack::Core& DF){
flushBuildingConfig(&customBuildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainBlockConfigs);
flushColorConfig(colorConfigs);
colorConfigs.clear();
creatureConfigs.clear();
treeConfigs.clear();
shrubConfigs.clear();
Expand Down Expand Up @@ -227,7 +227,9 @@ bool ContentLoader::Load( DFHack::Core& DF){
contentLoader->obsidian = lookupMaterialIndex(INORGANIC, "OBSIDIAN");

loadGraphicsFromDisk(); //these get destroyed when flushImgFiles is called.
bool overallResult = parseContentIndexFile( "index.txt" );
ALLEGRO_PATH * p = al_create_path("stonesense/index.txt");
bool overallResult = parseContentIndexFile( al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP) );
al_destroy_path(p);
translationComplete = false;

return true;
Expand All @@ -239,15 +241,17 @@ bool ContentLoader::reload_configs()
flushBuildingConfig(&customBuildingConfigs);
flushTerrainConfig(terrainFloorConfigs);
flushTerrainConfig(terrainBlockConfigs);
flushColorConfig(colorConfigs);
colorConfigs.clear();
creatureConfigs.clear();
treeConfigs.clear();
shrubConfigs.clear();
grassConfigs.clear();
flushImgFiles();

loadGraphicsFromDisk(); //these get destroyed when flushImgFiles is called.
bool overallResult = parseContentIndexFile( "index.txt" );
ALLEGRO_PATH * p = al_create_path("stonesense/index.txt");
bool overallResult = parseContentIndexFile( al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP) );
al_destroy_path(p);

return overallResult;
}
Expand Down
1 change: 1 addition & 0 deletions ContentLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class ContentLoader{
extern ContentLoader * contentLoader;

extern const char* getDocument(TiXmlNode* element);
bool getLocalFilename(char * buffer, const char* filename, const char* relativeto);
extern void contentError(const char* message, TiXmlNode* element);
extern char getAnimFrames(const char* framestring);
extern int loadConfigImgFile(const char* filename, TiXmlElement* referrer);
Expand Down
2 changes: 1 addition & 1 deletion FluidConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void parseFluidElement( TiXmlElement* elemFluid, int basefile)

bool addSingleFluidConfig( TiXmlElement* elemRoot)
{
int basefile = INVALID_INDEX;
int basefile = 0;
const char* filename = elemRoot->Attribute("file");
if (filename != NULL && filename[0] != 0)
{
Expand Down
90 changes: 57 additions & 33 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,39 +810,63 @@ void paintboard(){



void loadGraphicsFromDisk(){
/*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, "Loading...");
al_flip_display();*/
int index;
index = loadImgFile("objects.png");
if(index == -1) return;
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");
if(index == -1) return;
IMGCreatureSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("ramps.png");
if(index == -1) return;
IMGRampSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("SSStatusIcons.png");
if(index == -1) return;
IMGStatusSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("gibs.png");
if(index == -1) return;
IMGBloodSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("engravings_floor.png");
if(index == -1) return;
IMGEngFloorSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("engravings_left.png");
if(index == -1) return;
IMGEngLeftSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("engravings_right.png");
if(index == -1) return;
IMGEngRightSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
createEffectSprites();
void loadGraphicsFromDisk()
{
auto globulate = [](const char * filename, ALLEGRO_BITMAP *& imgd ) -> bool
{
int index;
ALLEGRO_PATH * p = al_create_path_for_directory("stonesense");
al_set_path_filename(p,filename);
index = loadImgFile(al_path_cstr(p,ALLEGRO_NATIVE_PATH_SEP));
if(index == -1)
{
al_destroy_path(p);
return false;
}
imgd = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
al_destroy_path(p);
return true;
};
if(!globulate("objects.png", IMGObjectSheet)) return;
if(!globulate("creatures.png", IMGObjectSheet)) return;
if(!globulate("ramps.png", IMGObjectSheet)) return;
if(!globulate("SSStatusIcons.png", IMGObjectSheet)) return;
if(!globulate("gibs.png", IMGObjectSheet)) return;
if(!globulate("engravings_floor.png", IMGObjectSheet)) return;
if(!globulate("engravings_left.png", IMGObjectSheet)) return;
if(!globulate("engravings_right.png", IMGObjectSheet)) return;
/*
al_set_path_filename(p,"creatures.png");
index = loadImgFile(al_path_cstr(p,ALLEGRO_NATIVE_PATH_SEP));
if(index == -1) return;
IMGCreatureSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
al_set_path_filename(p,"ramps.png");
index = loadImgFile(al_path_cstr(p,ALLEGRO_NATIVE_PATH_SEP));
if(index == -1) return;
IMGRampSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("SSStatusIcons.png");
if(index == -1) return;
IMGStatusSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("gibs.png");
if(index == -1) return;
IMGBloodSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("engravings_floor.png");
if(index == -1) return;
IMGEngFloorSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("engravings_left.png");
if(index == -1) return;
IMGEngLeftSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
index = loadImgFile("engravings_right.png");
if(index == -1) return;
IMGEngRightSheet = al_create_sub_bitmap(IMGFilelist[index], 0, 0, al_get_bitmap_width(IMGFilelist[index]), al_get_bitmap_height(IMGFilelist[index]));
*/
createEffectSprites();
}

//delete and clean out the image files
Expand Down
6 changes: 3 additions & 3 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ bool loadConfigFile();
//xmlBuildingReader.cpp
class BuildingConfiguration;

#define FILENAME_BUFFERSIZE 50
// temp buffers are bigger because they deal with absolute paths
#define FILENAME_BUFFERSIZE_LOCAL 200
// BUG: this is dangerous!
#define FILENAME_BUFFERSIZE 1024
#define FILENAME_BUFFERSIZE_LOCAL 2048

extern ALLEGRO_FONT *font;
extern ALLEGRO_KEYBOARD_STATE keyboard;
Expand Down
56 changes: 38 additions & 18 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ int32_t viewy = 0;
int32_t viewz = 0;
bool followmode = true;*/

ALLEGRO_BITMAP* load_bitmap_withWarning(const char* path){
ALLEGRO_BITMAP* img = 0;
img = al_load_bitmap(path);
if(!img){
DFConsole->printerr("Cannot load image: %s\n", path);
al_set_thread_should_stop(thread);
return 0;
}
al_convert_mask_to_alpha(img, al_map_rgb(255, 0, 255));
return img;
ALLEGRO_BITMAP* load_bitmap_withWarning(const char* path)
{
ALLEGRO_BITMAP* img = 0;
img = al_load_bitmap(path);
if(!img)
{
DFConsole->printerr("Cannot load image: %s\n", path);
al_set_thread_should_stop(thread);
return 0;
}
al_convert_mask_to_alpha(img, al_map_rgb(255, 0, 255));
return img;
}


Expand Down Expand Up @@ -140,12 +142,21 @@ void correctBlockForSegmetOffset(int32_t& x, int32_t& y, int32_t& z){

bool loadfont()
{
font = al_load_font(al_path_cstr(config.font, ALLEGRO_NATIVE_PATH_SEP), config.fontsize, 0);
if (!font) {
DFConsole->printerr("Cannot load font: %s\n", al_path_cstr(config.font, ALLEGRO_NATIVE_PATH_SEP));
return 0;
}
return 1;
ALLEGRO_PATH * p = al_create_path_for_directory("stonesense");
if(!al_join_paths(p, config.font))
{
al_destroy_path(p);
return false;
}
font = al_load_font(al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP), config.fontsize, 0);
if (!font)
{
DFConsole->printerr("Cannot load font: %s\n", al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP));
al_destroy_path(p);
return false;
}
al_destroy_path(p);
return true;
}

void benchmark(DFHack::Core * c){
Expand Down Expand Up @@ -177,10 +188,16 @@ void animUpdateProc()

void drawcredits()
{
static ALLEGRO_BITMAP* SplashImage = NULL; // BUG: leaks the image
al_clear_to_color(al_map_rgb(0,0,0));
//centred splash image
{
static ALLEGRO_BITMAP* SplashImage = load_bitmap_withWarning("splash.png");
if(!SplashImage)
{
ALLEGRO_PATH * p = al_create_path("stonesense/stonesense.png");
SplashImage = load_bitmap_withWarning(al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP));
al_destroy_path(p);
}
if(!SplashImage)
return;
al_draw_bitmap_region(SplashImage, 0, 0,
Expand Down Expand Up @@ -467,9 +484,12 @@ static void * stonesense_thread(ALLEGRO_THREAD * thred, void * parms)
if(config.software)
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP|ALLEGRO_ALPHA_TEST);

IMGIcon = load_bitmap_withWarning("stonesense.png");
ALLEGRO_PATH * p = al_create_path("stonesense/stonesense.png");
IMGIcon = load_bitmap_withWarning(al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP));
al_destroy_path(p);
if(!IMGIcon)
{
al_destroy_display(display);
stonesense_started = 0;
return NULL;
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion resources/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ buildings/index.txt
vegetation/index.txt
colors/index.txt
Colors.xml
Fluids/index.txt
Fluids/index.txt

0 comments on commit 9c99824

Please sign in to comment.