예제 #1
0
void loadScene(char *name) {
	char line_buffer[MAX_LINE_SIZE];

	fp = fopen(name,"r");

	if(!fp) {	/* file could not be opened properly */
		fprintf(stderr,"ERROR: Scene file %s could not be loaded\n", name);
		fflush(stderr);
		exit(-1);
	}

	/* now go through all the lines in the file */
	while(fgets(line_buffer, MAX_LINE_SIZE, fp)) {	
		/* only do something if it's not a comment and the line is not blank */
		if (!lineCanBeIgnored(line_buffer)) {
			/* at this point it is neither a comment nor a blank line */
			parseScene(line_buffer);
		}
	}

	fclose(fp);


	return;
}
예제 #2
0
void loadFloorPlan(void) {
	int count = 0;
	char line_buffer[MAX_LINE_SIZE];
	fprintf(stderr,"Loading floor plan\n");

	/* compute the size of the scene */
	scene_width = cells_wide * cell_size;
	scene_height = cells_high * cell_size;

	fprintf(stderr,"size of scene: %d x %d\n", scene_width, scene_height);

	while((count < cells_high * 2) && fgets(line_buffer, MAX_LINE_SIZE, fp)) {	
		/* only do something if it's not a comment and the line is not blank */
		if (!lineCanBeIgnored(line_buffer)) {
			parseFloorPlan(count, line_buffer);
			count++;
		}
	}

	/* after i have added all the walls, let us add the floor */
	float x = -(((float)scene_width) / (float)2);
	float y = (((float)scene_height) / (float)2);
	scene.addFloor(x, y, x + scene_width, y - scene_height, tex[num_tex-1], scene_width, scene_height);

	return;
}
예제 #3
0
	void Database::runSqlScript(QString script_path) {
		QSqlDatabase db = QSqlDatabase::database();

		if (not db.open())
			throw new ErrorOpeningDatabase(path());

		QFile script(script_path);
		if (not script.open(QIODevice::ReadOnly | QIODevice::Text))
			throw new ErrorReadingSQLScript(script_path);

		// NOTE query object must be created after database is open
		QSqlQuery query;

		QString line;
		while (!script.atEnd()) {
			line = QString(script.readLine());
			if (lineCanBeIgnored(line))
				continue;

			if (not query.exec(line))
				throw new SqlQueryError(query);
		}
		db.close();
		script.close();
	}
예제 #4
0
void loadTextures(void) {
	int count = 0;
	char line_buffer[MAX_LINE_SIZE];

	fprintf(stderr,"Loading textures\n");

	/* first make room for all the textures */
	tex = (Texture **)malloc(sizeof(Texture*) * num_tex);
	tex_codes = (int *)malloc(sizeof(int) * num_tex);

	while((count < num_tex) && fgets(line_buffer, MAX_LINE_SIZE, fp)) {	
		/* only do something if it's not a comment and the line is not blank */
		if (!lineCanBeIgnored(line_buffer)) {
			fprintf(stderr,"%s", line_buffer);
			parseTexture(count, line_buffer);
			count++;
		}
	}

	return;
}
예제 #5
0
void MazeParser::loadTextures()
{
   int count = 0;
   char line_buffer[MAX_LINE_SIZE];

   fprintf(stderr,"Loading textures\n");
   fflush(stderr);

   while((count < num_tex) && fgets(line_buffer, MAX_LINE_SIZE, fp))
   {
      /* only do something if it's not a comment and the line is not blank */
      if (!lineCanBeIgnored(line_buffer))
      {
         fprintf(stderr,"%s\n", line_buffer);
         fflush(stderr);
         parseTexture(count, line_buffer);
         count++;
      }
   }
   return;
}
예제 #6
0
void parseScene(char *line) {
	char command[MAX_LINE_SIZE];
	char arg[MAX_LINE_SIZE];
	char *start, *end;


	/* i need to get the first word */
	end = findFirstSpace(line);

	/* observe what the command is */
	copyString(command, line, end);

	if (!strcmp(command,"DIMENSIONS")) {
		/* parse the dimensions of the scene */
		
		start = skipSpace(end);
		end = findFirstSpace(start);
		copyString(arg, start, end);
		end = skipSpace(end);

		cells_wide = atoi(arg);

		start = skipSpace(end);
		end = findFirstSpace(start);
		copyString(arg, start, end);
		end = skipSpace(end);

		cells_high = atoi(arg);
		assert(lineCanBeIgnored(end));	/* the rest of the line should be able to be ignored */

		fprintf(stderr,"width: %d   height: %d\n", cells_wide, cells_high);
	}
	else if (!strcmp(command,"HEIGHT")) {
		start = skipSpace(end);
		end = findFirstSpace(start);
		copyString(arg, start, end);
		end = skipSpace(end);

		wall_height = atoi(arg);
		fprintf(stderr,"wall height: %d\n", wall_height);
	}
	else if (!strcmp(command,"CELL")) {
		start = skipSpace(end);
		end = findFirstSpace(start);
		copyString(arg, start, end);
		end = skipSpace(end);

		cell_size = atoi(arg);
		fprintf(stderr,"cell size: %d\n", cell_size);
	}
	else if (!strcmp(command,"TEXTURES")) {
		start = skipSpace(end);
		end = findFirstSpace(start);
		copyString(arg, start, end);
		end = skipSpace(end);

		num_tex = atoi(arg);
		fprintf(stderr,"number of textures: %d\n", num_tex);

		loadTextures();
	}
	else if (!strcmp(command,"FLOORPLAN")) {
		assert(lineCanBeIgnored(end));	/* the rest of the line should be able to be ignored */

		loadFloorPlan();
	}
	else {
		fprintf(stderr,"ERROR! Unrecognized command in scene file \n");
		fprintf(stderr,"%s\n", line);
		exit(-1);
	}

	return;
}