diff options
| author | Petr Mrázek | 2011-07-22 00:45:54 +0000 |
|---|---|---|
| committer | Petr Mrázek | 2011-07-22 00:45:54 +0000 |
| commit | bf89e3ad6b98442dca909e327b80c5e292db6092 (patch) | |
| tree | 27f28ac93518f26fd099bf07340e9d7fe9f11f1c /ContentLoader.cpp | |
| parent | 650c5593bfd90afc93720b06fe74ee4ec7abf73e (diff) | |
| download | stonesense-bf89e3ad6b98442dca909e327b80c5e292db6092.tar.gz stonesense-bf89e3ad6b98442dca909e327b80c5e292db6092.tar.bz2 stonesense-bf89e3ad6b98442dca909e327b80c5e292db6092.tar.xz | |
Update stonesense for current dfhack, make sure it's buildable as a plugin.
Diffstat (limited to 'ContentLoader.cpp')
| -rw-r--r-- | ContentLoader.cpp | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/ContentLoader.cpp b/ContentLoader.cpp index f376c13..ab490e3 100644 --- a/ContentLoader.cpp +++ b/ContentLoader.cpp @@ -28,7 +28,7 @@ void DumpMaterialNamesToDisk(vector<t_matgloss> material, const char* filename){ FILE* fp = fopen(filename, "w");
if(!fp) return;
for(uint32_t j=0; j < material.size(); j++){
- fprintf(fp, "%i:%s\n",j, material[j].id);
+ fprintf(fp, "%i:%s\n",j, material[j].id.c_str());
}
fclose(fp);
}
@@ -275,7 +275,7 @@ bool getLocalFilename(char * buffer, const char* filename, const char* relativet return true;
}
-bool ContentLoader::parseContentIndexFile( char* filepath )
+bool ContentLoader::parseContentIndexFile( const char* filepath )
{
/*
al_clear_to_color(al_map_rgb(0,0,0));
@@ -352,7 +352,7 @@ bool ContentLoader::parseContentIndexFile( char* filepath ) return true;
}
-bool ContentLoader::parseContentXMLFile( char* filepath ){
+bool ContentLoader::parseContentXMLFile( const char* filepath ){
/*
al_clear_to_color(al_map_rgb(0,0,0));
draw_textf_border(font, al_get_bitmap_width(al_get_target_bitmap())/2,
@@ -477,16 +477,16 @@ char getAnimFrames(const char* framestring) }
return aframes;
}
-
-int lookupIndexedType(const char* indexName, vector<t_matgloss>& typeVector)
+template <typename T>
+int lookupIndexedType(const char* indexName, vector<T>& typeVector)
{
if (indexName == NULL || indexName[0] == 0)
{
- return INVALID_INDEX;
+ return INVALID_INDEX;
}
uint32_t vsize = (uint32_t)typeVector.size();
for(uint32_t i=0; i < vsize; i++){
- if (strcmp(indexName,typeVector[i].id) == 0)
+ if (typeVector[i].id == indexName)
return i;
}
return INVALID_INDEX;
@@ -494,31 +494,28 @@ int lookupIndexedType(const char* indexName, vector<t_matgloss>& typeVector) int lookupMaterialIndex(int matType, const char* strValue)
{
- vector<t_matgloss>* typeVector;
- // for appropriate elements, look up subtype
- if ((matType == INORGANIC) && (!config.skipInorganicMats))
- {
- typeVector=&(contentLoader.inorganic);
- }
- else if ((matType == WOOD) && (!config.skipOrganicMats))
- {
- typeVector=&(contentLoader.organic);
- }
- else if ((matType == PLANTCLOTH) && (!config.skipOrganicMats))
- {
- typeVector=&(contentLoader.organic);
- }
- else if (matType == LEATHER)
- {
- if(!config.skipCreatureTypes);
- typeVector=&(contentLoader.Mats->race);
- }
- else
- {
- //maybe allow some more in later
- return INVALID_INDEX;
- }
- return lookupIndexedType(strValue,*typeVector);
+ // for appropriate elements, look up subtype
+ if (matType == INORGANIC && !config.skipInorganicMats)
+ {
+ return lookupIndexedType(strValue,contentLoader.inorganic);
+ }
+ else if (matType == WOOD && !config.skipOrganicMats)
+ {
+ return lookupIndexedType(strValue,contentLoader.organic);
+ }
+ else if (matType == PLANTCLOTH && !config.skipOrganicMats)
+ {
+ return lookupIndexedType(strValue,contentLoader.organic);
+ }
+ else if (matType == LEATHER && !config.skipCreatureTypes)
+ {
+ return lookupIndexedType(strValue,contentLoader.Mats->race);
+ }
+ else
+ {
+ //maybe allow some more in later
+ return INVALID_INDEX;
+ }
}
const char *lookupMaterialTypeName(int matType)
@@ -582,7 +579,11 @@ const char *lookupMaterialName(int matType,int matIndex) // for appropriate elements, look up subtype
if ((matType == INORGANIC) && (!config.skipInorganicMats))
{
- typeVector=&(contentLoader.inorganic);
+ if(matIndex < contentLoader.inorganic.size())
+ {
+ return contentLoader.inorganic[0].id.c_str();
+ }
+ else return NULL;
}
else if ((matType == WOOD) && (!config.skipOrganicMats))
{
@@ -604,7 +605,7 @@ const char *lookupMaterialName(int matType,int matIndex) }
if (matIndex >= typeVector->size())
return NULL;
- return (*typeVector)[matIndex].id;
+ return (*typeVector)[matIndex].id.c_str();
}
const char *lookupTreeName(int matIndex)
@@ -618,7 +619,7 @@ const char *lookupTreeName(int matIndex) typeVector=&(contentLoader.organic);
if (matIndex >= typeVector->size())
return NULL;
- return (*typeVector)[matIndex].id;
+ return (*typeVector)[matIndex].id.c_str();
}
const char * lookupFormName(int formType)
|
