Jump to content
  • Advertisement
Sign in to follow this  
colinisinhere

Load scripts...?

This topic is 5038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
I didn't go through all the logic of your code, but this looks similar to my shader loading code, and to other similar code that I have seen.

std::string does overload ==, but AFAIK it's case-sensitive only. In my engine I want shader keywords to be case-insensitive, so I'm using !stricmp() instead.

I did do some digging around to find out if there was a way to make a case-insensitive std::string, but didn't find anything. If there is a way, I'd love to know about it.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
I did do some digging around to find out if there was a way to make a case-insensitive std::string, but didn't find anything. If there is a way, I'd love to know about it.
Here. The code is a little shorter than I expected.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!