In my engine I am organizing my materials in seperate files... for example:
// test.material
test {
texture textures/test.tga
}
To read that file, I have something like this:
bool CMaterial::loadFromFile(const char* fileName, ...) {
bool error = false;
bool inBrackets = false;
bool gotName = false;
string currentRead;
logger->newMsg("Loading material file '%s'", fileName); //! Logger Message
ifstream materialFile(fileName);
if(!materialFile.is_open()) {
logger->newMsg("Loading material file failed"); //! Logger Message
return false;
}
while(!materialFile.eof() && !error) {
materialFile >> currentRead;
//logger->newMsg("Syntax error: Unknown symbol '%s'", currentRead.c_str());
if(!inBrackets) {
if(currentRead == "{" && gotName){
inBrackets = true;
} else if(currentRead == "{" && !gotName){
error = true;
logger->newMsg("Syntax error: Unexpected '{' (name of material must be called first)");
} else if(!gotName) { //! Assumes that this is the name of the material
gotName = true;
materialName = currentRead;
}
else if(gotName) {
error = true;
logger->newMsg("Syntax error: Unknown symbol '%s'", currentRead.c_str());
}
}
else {
if(currentRead == "texture") {
getline(materialFile, currentRead);
loadTexture(currentRead.c_str());
}
}
}
if(error) {
logger->newMsg("Loading material file failed"); //! Logger Message
return false;
}
materialFile.close();
logger->newMsg("Loading material file successful"); //! Logger Message
return true;
}
Is this the right idea for how to load a file like this?
Also, does == work with std::string?
Thanks