diff options
| author | Jonas Ask | 2009-11-27 16:17:49 +0000 |
|---|---|---|
| committer | Jonas Ask | 2009-11-27 16:17:49 +0000 |
| commit | 86248d1d3dfdacdab2c4aa7781fa2c048200cccb (patch) | |
| tree | a0a93ef767d9de3a633d2132e6815a1aa280f199 /GroundMaterialConfiguration.cpp | |
| parent | b53e1de02057623713dc74e1ea72416f8f1be879 (diff) | |
| download | stonesense-86248d1d3dfdacdab2c4aa7781fa2c048200cccb.tar.gz stonesense-86248d1d3dfdacdab2c4aa7781fa2c048200cccb.tar.bz2 stonesense-86248d1d3dfdacdab2c4aa7781fa2c048200cccb.tar.xz | |
Added what used to be GroundMaterials to the ContentLoader.
Diffstat (limited to 'GroundMaterialConfiguration.cpp')
| -rw-r--r-- | GroundMaterialConfiguration.cpp | 96 |
1 files changed, 38 insertions, 58 deletions
diff --git a/GroundMaterialConfiguration.cpp b/GroundMaterialConfiguration.cpp index 6a21df4..1a76fb5 100644 --- a/GroundMaterialConfiguration.cpp +++ b/GroundMaterialConfiguration.cpp @@ -4,10 +4,10 @@ #include "dfhack/library/tinyxml/tinyxml.h"
-bool GroundMaterialNamesTranslatedFromGame = false;
+//bool GroundMaterialNamesTranslatedFromGame = false;
-vector<GroundMaterialConfiguration*> groundTypes;
-vector<preparseGroundMaterialConfiguration> xmlDefinedGroundTypes;
+//vector<GroundMaterialConfiguration*> groundTypes;
+//vector<preparseGroundMaterialConfiguration> xmlDefinedGroundTypes;
/*
GroundMaterialConfiguration::GroundMaterialConfiguration(char* gameIDstr, int wallSheetIndex,int floorSheetIndex)
@@ -33,15 +33,15 @@ void DumpGroundMaterialNamesToDisk(){ fclose(fp);
}
-void addConfToIDdsaj (int index, preparseGroundMaterialConfiguration& conf){
- if(groundTypes[index] == NULL){
+void addConfToGroundConfigList (vector<GroundMaterialConfiguration*>& configs, int index, preparseGroundMaterialConfiguration& conf){
+ if(configs[index] == NULL){
//TODO: possible memleak.
- groundTypes[index] = new GroundMaterialConfiguration();
+ configs[index] = new GroundMaterialConfiguration();
}
if( conf.overridingMaterials.empty() ){
- groundTypes[index]->defaultSprite = conf.spriteIndex;
- groundTypes[index]->fillerFloorSpriteIndex = conf.fillerFloorSpriteIndex;
+ configs[index]->defaultSprite = conf.spriteIndex;
+ configs[index]->fillerFloorSpriteIndex = conf.fillerFloorSpriteIndex;
}else{
int num = (int)conf.overridingMaterials.size();
for(int i=0; i < num; i++){
@@ -54,47 +54,44 @@ void addConfToIDdsaj (int index, preparseGroundMaterialConfiguration& conf){ if(conf.overridingMaterials[i].compare(v_stonetypes[j].id) == 0)
matGameId = j;
ovr.gameID = matGameId;
- groundTypes[index]->overridingMaterials.push_back( ovr );
+ configs[index]->overridingMaterials.push_back( ovr );
}
}
}
-/*void TranslateGroundMaterialNames(){
+void TranslateGroundMaterialNames(vector<GroundMaterialConfiguration*>& configs, vector<preparseGroundMaterialConfiguration>& rawGroundConfigs){
//create and entry for every known ground material type
uint32_t num;
uint32_t index = 0;
- groundTypes.clear();
+ configs.clear();
//figure out how many entries to make.
int highestID = 0;
- num = (uint32_t) xmlDefinedGroundTypes.size();
+ num = (uint32_t) rawGroundConfigs.size();
while( index < num ){
- for(uint32_t i = 0; i < xmlDefinedGroundTypes[index].wallFloorIDs.size(); i++){
- highestID = max(highestID, xmlDefinedGroundTypes[index].wallFloorIDs[i]);
+ for(uint32_t i = 0; i < rawGroundConfigs[index].wallFloorIDs.size(); i++){
+ highestID = max(highestID, rawGroundConfigs[index].wallFloorIDs[i]);
}
index++;
}
//create table
- groundTypes.resize( highestID + 1 );
+ configs.resize( highestID + 1 );
index = 0;
- num = (int)xmlDefinedGroundTypes.size();
+ num = (int)rawGroundConfigs.size();
while( index < num ){
- preparseGroundMaterialConfiguration& conf = xmlDefinedGroundTypes[index];
+ preparseGroundMaterialConfiguration& conf = rawGroundConfigs[index];
for(uint32_t i=0; i<conf.wallFloorIDs.size(); i++)
- addConfToIDdsaj( conf.wallFloorIDs[i], conf );
-
-
+ addConfToGroundConfigList(configs, conf.wallFloorIDs[i], conf );
index++;
}
- GroundMaterialNamesTranslatedFromGame = true;
-}*/
+}
-void parseWallFloorSpriteElement( TiXmlElement* elemWallFloorSprite ){
+void parseWallFloorSpriteElement( TiXmlElement* elemWallFloorSprite, vector<preparseGroundMaterialConfiguration>* rawGroundTypes ){
TiXmlElement* elemGameID;
TiXmlElement* elemMaterial;
@@ -124,46 +121,29 @@ void parseWallFloorSpriteElement( TiXmlElement* elemWallFloorSprite ){ elemMaterial = elemMaterial->NextSiblingElement("Material");
}
- xmlDefinedGroundTypes.push_back( newConfig );
+ rawGroundTypes->push_back( newConfig );
}
-void LoadGroundMaterialConfiguration( ){
+bool addSingleTerrainConfig( TiXmlElement* elemRoot, vector<preparseGroundMaterialConfiguration>* rawGroundTypes ){
+ string elementType = elemRoot->Value();
- char* filename = "GroundMaterials.xml";
- TiXmlDocument doc( filename );
- bool loadOkay = doc.LoadFile();
- TiXmlHandle hDoc(&doc);
- TiXmlElement* elemFloor;
- TiXmlElement* elemWall;
-
- //clear out old config data. TODO: check for memleaks
- xmlDefinedGroundTypes.clear();
-
- TiXmlElement* elemFloorRoot = hDoc.FirstChildElement("Floors").Element();
- TiXmlElement* elemWallRoot = hDoc.FirstChildElement("Walls").Element();
- if(elemFloorRoot == null){
- WriteErr("Could not find 'Floors' node in xml file\n");
- return;
- }
- if(elemWallRoot == null){
- WriteErr("Could not find 'Walls' node in xml file\n");
- return;
- }
-
- //parse floors
- elemFloor = elemFloorRoot->FirstChildElement("Floor");
- while( elemFloor ){
- parseWallFloorSpriteElement( elemFloor );
- elemFloor = elemFloor->NextSiblingElement("Floor");
+ if(elementType.compare( "floors" ) == 0){
+ //parse floors
+ TiXmlElement* elemFloor = elemRoot->FirstChildElement("Floor");
+ while( elemFloor ){
+ parseWallFloorSpriteElement( elemFloor, rawGroundTypes );
+ elemFloor = elemFloor->NextSiblingElement("Floor");
+ }
}
-
- //parse walls
- elemWall = elemWallRoot->FirstChildElement("Wall");
- while( elemWall ){
- parseWallFloorSpriteElement( elemWall );
- elemWall = elemWall->NextSiblingElement("Wall");
+ if(elementType.compare( "walls" ) == 0){
+ //parse walls
+ TiXmlElement* elemWall = elemRoot->FirstChildElement("Wall");
+ while( elemWall ){
+ parseWallFloorSpriteElement( elemWall, rawGroundTypes );
+ elemWall = elemWall->NextSiblingElement("Wall");
+ }
}
- GroundMaterialNamesTranslatedFromGame = false;
+ return true;
}
|
