Jump to content

  • Log In with Google      Sign In   
  • Create Account

Level Loading Lark


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 sethhope   Members   -  Reputation: 462

Like
0Likes
Like

Posted 27 April 2013 - 04:04 PM

I am beginning to create a simple level loader for my game engine. It has a simple syntax, so I figured it would be pretty easy to create... How wrong I was. 

 

Below is the code for decoding my level files:

void JTechScript::JLoadLevel(const char *filename)
{
	objects = 0;
	//initialize variables and get load file
	fileName = filename;
	std::ifstream levelFile(fileName);
	char letter;
	letter = levelFile.get();
	//begin insane nested loop stuffz
	//go until the end of file
	while(letter != END_FILE)
	{
		//check for new object character "#"
		if(letter == NEW_OBJECT)
		{
			//initialize more stuffz
			char tempObjectType[32];
			int x = 0;
			objects++;
			//read until end of line and make that the name of the object
			while(letter != END_LINE)
			{
				std::cout << letter;
				x++;
				tempObjectType[x] = letter;
				letter = levelFile.get();
			}
			std::string objectType(tempObjectType);


			//-------------------------------------------------------------------------
			// \/ \/ \/ \/ \/ custom object types here \/ \/ \/ \/ \/

			if(objectType == "CAMERA")
			{
				objParameter[objects][1] = 1;
			}
			else if(objectType == "WORLD")
			{
				objParameter[objects][1] = 2;
			}
			else if(objectType == "SPHERE")
			{
				objParameter[objects][1] = 3;
			}

			//END CUSTOM PARAMETERS
			//--------------------------------------------------------------------------


			//more initialization 
			int tempParameterNum;
			char buffer[32];
			int value = 2;
			//read until the end of the object
			while(letter != END_OBJECT)
			{
				tempParameterNum = 0;
				//read each line and make it a number
				if(letter != END_LINE)
				{
					std::cout << letter;
					buffer[tempParameterNum] = letter;
					tempParameterNum++;
				}else{

				//set the number as an object parameter
				value++;
				objParameter[objects][value] = atoi(buffer);
				//clear the buffer
				for(int i = 32;i < 32; ++i)
				{
					buffer[i] = 0;
				}
				}
				letter = levelFile.get();
			}
		}
		letter = levelFile.get();
	}
	//if you can figure this out, you deserve a medal. So... (1) <-- there... there is your medal.
	//................................................................SHUDDUP! I SUCK AT ASCII ART!
}

 

 

This is the file it is decoding

 

#CAMERA;
0;
100;
0;
|

#WORLD;
-100;
-10;
-100;
|
*

 

 

It seems to work fine, but when I try to retrieve the values for objParameter[1][1], it returns -842150451.. It returns the same number for objParameter[2][1] as well.

 

 

Please help... I have been working FOREVER on this.


I develop to expand the universe.
"Live long and code strong!" - Delta_Echo (dream.in.code)

Sponsor:

#2 sethhope   Members   -  Reputation: 462

Like
0Likes
Like

Posted 27 April 2013 - 05:34 PM

Woah! Got it fixed! Forgot to put a \0 null character after the declaration of the object type!


I develop to expand the universe.
"Live long and code strong!" - Delta_Echo (dream.in.code)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS