changed error checking syntax to make code more compact

This commit is contained in:
Steffen Fündgens 2014-12-08 15:48:46 +01:00
parent 2790bddd11
commit 28839b4d3a

View File

@ -40,7 +40,6 @@ void Level::errorCheck(XMLError error){
} }
void Level::load() { void Level::load() {
XMLError error=XML_NO_ERROR;
this->physics = Physics(); this->physics = Physics();
this->physics.init(); this->physics.init();
@ -61,7 +60,6 @@ void Level::load() {
//addTerrainPhysic //addTerrainPhysic
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap()); physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
//Loading Objects via xml //Loading Objects via xml
XMLDocument* doc = new XMLDocument(); XMLDocument* doc = new XMLDocument();
const char* xmlFile = ("../Levels/ObjectSetups/Level" + levelNum + ".xml").c_str(); const char* xmlFile = ("../Levels/ObjectSetups/Level" + levelNum + ".xml").c_str();
@ -80,13 +78,11 @@ void Level::load() {
XMLElement* thisComposition = doc->FirstChildElement("composition"); XMLElement* thisComposition = doc->FirstChildElement("composition");
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){ for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
int thisType = 0; int thisType = 0;
error = thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType); errorCheck(thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType));
errorCheck(error);
XMLElement* composition = compositions->FirstChildElement("composition"); XMLElement* composition = compositions->FirstChildElement("composition");
for(; composition; composition=composition->NextSiblingElement("composition")){ for(; composition; composition=composition->NextSiblingElement("composition")){
int compositionType = 0; int compositionType = 0;
error = composition->FirstChildElement("typeID")->QueryIntText(&compositionType); errorCheck(composition->FirstChildElement("typeID")->QueryIntText(&compositionType));
errorCheck(error);
if(thisType == compositionType){ if(thisType == compositionType){
XMLElement* object = composition->FirstChildElement("object"); XMLElement* object = composition->FirstChildElement("object");
for(; object; object=object->NextSiblingElement("object")){ for(; object; object=object->NextSiblingElement("object")){
@ -96,10 +92,8 @@ void Level::load() {
} }
std::string modelPath = charModelPath; std::string modelPath = charModelPath;
float objectScale, compScale; float objectScale, compScale;
error = object->FirstChildElement("scale")->QueryFloatText(&objectScale); errorCheck(object->FirstChildElement("scale")->QueryFloatText(&objectScale));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
error = thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale);
errorCheck(error);
Model model = Model(modelPath, objectScale * compScale); Model model = Model(modelPath, objectScale * compScale);
Material material; Material material;
XMLElement* objectData = compositions->FirstChildElement("objectData"); XMLElement* objectData = compositions->FirstChildElement("objectData");
@ -111,14 +105,10 @@ void Level::load() {
std::string dataModelPath = charDataModelPath; std::string dataModelPath = charDataModelPath;
if(dataModelPath == modelPath){ if(dataModelPath == modelPath){
float ambientFactor, diffuseFactor, specularFactor, shininess; float ambientFactor, diffuseFactor, specularFactor, shininess;
error = objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor); errorCheck(objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor));
errorCheck(error); errorCheck(objectData->FirstChildElement("diffuseFactor")->QueryFloatText(&diffuseFactor));
error = objectData->FirstChildElement("diffuseFactor")->QueryFloatText(&diffuseFactor); errorCheck(objectData->FirstChildElement("specularFactor")->QueryFloatText(&specularFactor));
errorCheck(error); errorCheck(objectData->FirstChildElement("shininess")->QueryFloatText(&shininess));
error = objectData->FirstChildElement("specularFactor")->QueryFloatText(&specularFactor);
errorCheck(error);
error = objectData->FirstChildElement("shininess")->QueryFloatText(&shininess);
errorCheck(error);
const char* charTexturePath = objectData->FirstChildElement("texturePath")->GetText(); const char* charTexturePath = objectData->FirstChildElement("texturePath")->GetText();
if(charTexturePath == NULL){ if(charTexturePath == NULL){
printf("XMLError: No texturePath found in objectData.\n"); printf("XMLError: No texturePath found in objectData.\n");
@ -129,24 +119,15 @@ void Level::load() {
} }
float compXPos, compYOffset, compZPos; float compXPos, compYOffset, compZPos;
glm::vec3 objectOffset, compRot; glm::vec3 objectOffset, compRot;
error = object->FirstChildElement("xOffset")->QueryFloatText(&objectOffset[0]); errorCheck(object->FirstChildElement("xOffset")->QueryFloatText(&objectOffset[0]));
errorCheck(error); errorCheck(object->FirstChildElement("yOffset")->QueryFloatText(&objectOffset[1]));
error = object->FirstChildElement("yOffset")->QueryFloatText(&objectOffset[1]); errorCheck(object->FirstChildElement("zOffset")->QueryFloatText(&objectOffset[2]));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
error = object->FirstChildElement("zOffset")->QueryFloatText(&objectOffset[2]); errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
error = thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos); errorCheck(thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]));
error = thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset); errorCheck(thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]));
errorCheck(error);
error = thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos);
errorCheck(error);
error = thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]);
errorCheck(error);
error = thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]);
errorCheck(error);
error = thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]);
errorCheck(error);
glm::vec3 compPos = glm::vec3(compXPos, glm::vec3 compPos = glm::vec3(compXPos,
compYOffset+terrain.getHeightmap()[int(compXPos-0.5+0.5*terrain.getHeightmapHeight())] compYOffset+terrain.getHeightmap()[int(compXPos-0.5+0.5*terrain.getHeightmapHeight())]
[int(compZPos-0.5+0.5*terrain.getHeightmapWidth())], [int(compZPos-0.5+0.5*terrain.getHeightmapWidth())],
@ -170,34 +151,20 @@ void Level::load() {
for(; light; light=light->NextSiblingElement("light")){ for(; light; light=light->NextSiblingElement("light")){
glm::vec3 compRot, lightOffset, lightColour; glm::vec3 compRot, lightOffset, lightColour;
float compScale, compXPos, compYOffset, compZPos, lightIntensity; float compScale, compXPos, compYOffset, compZPos, lightIntensity;
error = thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale); errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
errorCheck(error); errorCheck(light->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0]));
error = light->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0]); errorCheck(light->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1]));
errorCheck(error); errorCheck(light->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2]));
error = light->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1]); errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
error = light->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2]); errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]));
error = thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos); errorCheck(thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]));
errorCheck(error); errorCheck(thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]));
error = thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset); errorCheck(light->FirstChildElement("rColour")->QueryFloatText(&lightColour[0]));
errorCheck(error); errorCheck(light->FirstChildElement("gColour")->QueryFloatText(&lightColour[1]));
error = thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos); errorCheck(light->FirstChildElement("bColour")->QueryFloatText(&lightColour[2]));
errorCheck(error); errorCheck(light->FirstChildElement("intensity")->QueryFloatText(&lightIntensity));
error = thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]);
errorCheck(error);
error = thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]);
errorCheck(error);
error = thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]);
errorCheck(error);
error = light->FirstChildElement("rColour")->QueryFloatText(&lightColour[0]);
errorCheck(error);
error = light->FirstChildElement("gColour")->QueryFloatText(&lightColour[1]);
errorCheck(error);
error = light->FirstChildElement("bColour")->QueryFloatText(&lightColour[2]);
errorCheck(error);
error = light->FirstChildElement("intensity")->QueryFloatText(&lightIntensity);
errorCheck(error);
glm::vec3 compPos = glm::vec3(compXPos, glm::vec3 compPos = glm::vec3(compXPos,
compYOffset+terrain.getHeightmap()[int(compXPos-0.5+0.5*terrain.getHeightmapHeight())] compYOffset+terrain.getHeightmap()[int(compXPos-0.5+0.5*terrain.getHeightmapHeight())]
[int(compZPos-0.5+0.5*terrain.getHeightmapWidth())], [int(compZPos-0.5+0.5*terrain.getHeightmapWidth())],