void CTexture::LoadTextureList () {
    int rep, id;
    string texfile, line, name;

    TextureIndex = "";
    CSPList list (200);
    if (list.Load (param.tex_dir, "textures.lst")) {
        for (int i=0; i<list.Count(); i++) {
            line = list.Line (i);
            name = SPStrN (line, "name", "");
            id = SPIntN (line, "id", 0);
            texfile = SPStrN (line, "file", "");
            rep = SPIntN (line, "repeat", 0);
            if (id >= 0 && id < MAX_COMMON_TEX) {
                if (rep>0) CommonTex[id] =
                        LoadMipmapTexture (param.tex_dir.c_str(), texfile.c_str(), rep);
                else CommonTex[id] =
                        LoadTexture (param.tex_dir.c_str(), texfile.c_str());
                if (CommonTex[id] > 0) {
                    TextureIndex = TextureIndex + "[" + name + "]" + Int_StrN (CommonTex[id]);
                    numTextures++;
                }
            } else Message ("wrong texture id in textures.lst");
        }
    } else Message ("failed to load common textures");
}
bool CScore::LoadHighScore () {
	CSPList list (520);

	Scorelist.resize(Course.CourseList.size());

	if (!list.Load (param.config_dir, "highscore")) {
		Message ("could not load highscore list");
		return false;
	}

	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		string course = SPStrN (line, "course", "unknown");
		TCourse* cidx = Course.GetCourse(course);

		TScore score;
		score.player = SPStrN (line, "plyr", "unknown");
		score.points = SPIntN (line, "pts", 0);
		score.herrings = SPIntN (line, "herr", 0);
		score.time = SPFloatN (line, "time", 0);

		AddScore (cidx, score);
	}
	return true;
}
void CPlayers::LoadAvatars () {
	CSPList list (MAX_AVATARS);
	int i;
	string line, filename;
	GLuint texid;

	if (!list.Load (param.player_dir, "avatars.lst")) {
		Message ("could not load avators.lst");
		return;
	}

	AvatarIndex = "";
	numAvatars = 0;
	for (i=0; i<list.Count(); i++) {
		line = list.Line (i);
		filename = SPStrN (line, "file", "unknown");
		texid = Tex.LoadTexture (param.player_dir, filename);
		if (texid > 0) {
			avatars[numAvatars].filename = filename;
			avatars[numAvatars].texid = texid;
			AvatarIndex += "[" + filename + "]";
			AvatarIndex += Int_StrN (texid);
			numAvatars++;
		}
	}
}
bool CScore::SaveHighScore () const {
	CSPList splist ((int)Scorelist.size()*MAX_SCORES);

	for (size_t li=0; li<Scorelist.size(); li++) {
		const TScoreList* lst = &Scorelist[li];
		if (lst != NULL) {
			int num = lst->numScores;
			if (num > 0) {
				for (int sc=0; sc<num; sc++) {
					const TScore& score = lst->scores[sc];
					string line = "*[course] " + Course.CourseList[li].dir;
					line += " [plyr] " + score.player;
					line += " [pts] " + Int_StrN (score.points);
					line += " [herr] " + Int_StrN (score.herrings);
					line += " [time] " + Float_StrN (score.time, 1);
					splist.Add (line);
				}
			}
		}
	}
	if (!splist.Save (param.config_dir, "highscore")) {
		Message ("could not save highscore list");
		return false;
	}
	return true;
}
Exemple #5
0
bool CKeyframe::Load (string dir, string filename) {
	if (loaded && loadedfile == filename) return true;
	CSPList list (1000);
	int i;
	string line;
	TVector2 pp;
	numFrames = 0;
	TVector3 posit;

	if (list.Load (dir, filename)) {
		for (i=0; i<list.Count(); i++) {
			line = list.Line (i);
			frames[numFrames] = new (TKeyframe2);
			frames[numFrames]->val[0] = SPFloatN (line, "time", 0);		
			posit = SPVector3N (line, "pos", MakeVector (0, 0, 0));
			frames[numFrames]->val[1] = posit.x;
			frames[numFrames]->val[2] = posit.y;
			frames[numFrames]->val[3] = posit.z;
			frames[numFrames]->val[4] = SPFloatN (line, "yaw", 0);
			frames[numFrames]->val[5] = SPFloatN (line, "pitch", 0);
			frames[numFrames]->val[6] = SPFloatN (line, "roll", 0);
			frames[numFrames]->val[7] = SPFloatN (line, "neck", 0);
			frames[numFrames]->val[8] = SPFloatN (line, "head", 0);
			pp = SPVector2N (line, "sh", MakeVector2 (0, 0));
			frames[numFrames]->val[9] = pp.x;
			frames[numFrames]->val[10] = pp.y;
			pp = SPVector2N (line, "arm", MakeVector2 (0, 0));
			frames[numFrames]->val[11] = pp.x;
			frames[numFrames]->val[12] = pp.y;
			pp = SPVector2N (line, "hip", MakeVector2 (0, 0));
			frames[numFrames]->val[13] = pp.x;
			frames[numFrames]->val[14] = pp.y;
			pp = SPVector2N (line, "knee", MakeVector2 (0, 0));
			frames[numFrames]->val[15] = pp.x;
			frames[numFrames]->val[16] = pp.y;
			pp = SPVector2N (line, "ankle", MakeVector2 (0, 0));
			frames[numFrames]->val[17] = pp.x;
			frames[numFrames]->val[18] = pp.y;

			numFrames++;
		}
		loaded = true;
		loadedfile = filename;
		return true;
	} else {
		MessageN ("keyframe not found:", filename);
		loaded = false;
		return false;
	}	
}
void CCharacter::LoadCharacterList () {
	CSPList list (MAX_CHARACTERS+2);
	string line, typestr, charpath, previewfile;
	int i;
	GLuint texid;

	if (!list.Load (param.char_dir, "characters.lst")) {
		Message ("could not load characters.lst");
		return;
	}

	numCharacters = 0;
	TCharacter *ch;
	for (i=0; i<list.Count(); i++) {
		line = list.Line (i);
		CharList[i].name = SPStrN (line, "name", "");
		CharList[i].dir = SPStrN (line, "dir", "");
		typestr = SPStrN (line, "type", "unknown");
		CharList[i].type = SPIntN (char_type_index, typestr, -1);

		charpath = param.char_dir + SEP + CharList[i].dir;
		if (DirExists (charpath.c_str())) {
			previewfile = charpath + SEP + "preview.png";
			texid = Tex.LoadMipmapTexture (previewfile.c_str(), 0);
			if (texid < 1) {
				Message ("could not load previewfile of character");					
//				texid = Tex.TexID (NO_PREVIEW);
			}
			
			ch = &CharList[i];
			ch->preview = texid;

			ch->shape = new CCharShape;
			if (ch->shape->Load (charpath, "shape.lst", false) == false) {
				free (ch->shape);
				ch->shape = NULL;
				Message ("could not load character shape");
			} else numCharacters++;

			ch->frames[0].Load (charpath, "start.lst"); 
			ch->finishframesok = true;
			ch->frames[1].Load (charpath, "finish.lst"); 
			if (ch->frames[1].loaded == false) ch->finishframesok = false;
			ch->frames[2].Load (charpath, "wonrace.lst"); 
			if (ch->frames[2].loaded == false) ch->finishframesok = false;
			ch->frames[3].Load (charpath, "lostrace.lst"); 
			if (ch->frames[3].loaded == false) ch->finishframesok = false;
		}
	}
}
void CCourse::LoadItemList () {
	CSPList list (16000);

	if (!list.Load (CourseDir, "items.lst")) {
		Message ("could not load items list");
		return;
	}

	CollArr.clear();
	NocollArr.clear();
	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		int x = SPIntN (line, "x", 0);
		int z = SPIntN (line, "z", 0);
		double height = SPFloatN (line, "height", 1);
		double diam = SPFloatN (line, "diam", 1);
		double xx = (nx - x) / (double)(nx - 1.0) * curr_course->size.x;
		double zz = -(ny - z) / (double)(ny - 1.0) * curr_course->size.y;

		string name = SPStrN (line, "name", "");
		size_t type = ObjectIndex[name];
		if (ObjTypes[type].texture == NULL && ObjTypes[type].drawable) {
			string terrpath = param.obj_dir + SEP + ObjTypes[type].textureFile;
			ObjTypes[type].texture = new TTexture();
			ObjTypes[type].texture->LoadMipmap(terrpath, 0);
		}
		bool coll = ObjTypes[type].collidable;
		if (coll == 1) {
			CollArr.push_back(TCollidable());
		    CollArr.back().pt.x = xx;
		    CollArr.back().pt.z = zz;
		    CollArr.back().pt.y = FindYCoord (xx, zz);
		    CollArr.back().height = height;
		    CollArr.back().diam = diam;
		    CollArr.back().tree_type = type;
		} else if (coll == 0) {
			NocollArr.push_back(TItem());
		    NocollArr.back().pt.x = xx;
		    NocollArr.back().pt.z = zz;
		    NocollArr.back().pt.y = FindYCoord (xx, zz);
			NocollArr.back().height = height;
		    NocollArr.back().diam = diam;
		    NocollArr.back().item_type = type;
			NocollArr.back().collectable = ObjTypes[type].collectable;
			NocollArr.back().drawable = ObjTypes[type].drawable;
			ObjTypes[type].num_items++;
		}
	}
}
Exemple #8
0
void CKeyframe::SaveTest (string dir, string filename) {
	CSPList list (100);
	string line;
	TKeyframe2 *frame;
	double ll, rr;

	for (int i=0; i<numFrames; i++) {
		frame = frames[i];
		line = "*[time] " + Float_StrN (frame->val[0], 1);
		line += " [pos] " + Float_StrN (frame->val[1], 2);
		line += " " + Float_StrN (frame->val[2], 2);
		line += " " + Float_StrN (frame->val[3], 2);
		if (frame->val[4] != 0) line += " [yaw] " + Float_StrN (frame->val[4], 0);
		if (frame->val[5] != 0) line += " [pitch] " + Float_StrN (frame->val[5], 0);
		if (frame->val[6] != 0) line += " [roll] " + Float_StrN (frame->val[6], 0);
		if (frame->val[7] != 0) line += " [neck] " + Float_StrN (frame->val[7], 0);
		if (frame->val[8] != 0) line += " [head] " + Float_StrN (frame->val[8], 0);

		ll = frame->val[9];
		rr = frame->val[10];
		if (ll != 0 || rr != 0) 
			line += " [sh] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		ll = frame->val[11];
		rr = frame->val[12];
		if (ll != 0 || rr != 0) 
			line += " [arm] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		ll = frame->val[13];
		rr = frame->val[14];
		if (ll != 0 || rr != 0) 
			line += " [hip] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		ll = frame->val[15];
		rr = frame->val[16];
		if (ll != 0 || rr != 0) 
			line += " [knee] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		ll = frame->val[17];
		rr = frame->val[18];
		if (ll != 0 || rr != 0) 
			line += " [ankle] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		list.Add (line);
	}
	list.Save (dir, filename);
}
void CCharacter::LoadCharacterList () {
	CSPList list (MAX_CHARACTERS);

	if (!list.Load (param.char_dir, "characters.lst")) {
		Message ("could not load characters.lst");
		return;
	}

	CharList.resize(list.Count());
	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		CharList[i].name = SPStrN (line, "name");
		CharList[i].dir = SPStrN (line, "dir");
		string typestr = SPStrN (line, "type", "unknown");
		CharList[i].type = SPIntN (char_type_index, typestr, -1);

		string charpath = param.char_dir + SEP + CharList[i].dir;
		if (DirExists (charpath.c_str())) {
			string previewfile = charpath + SEP "preview.png";

			TCharacter* ch = &CharList[i];
			ch->preview = new TTexture();
			if (!ch->preview->LoadMipmap(previewfile, false)) {
				Message ("could not load previewfile of character");
//				texid = Tex.TexID (NO_PREVIEW);
			}


			ch->shape = new CCharShape;
			if (ch->shape->Load (charpath, "shape.lst", false) == false) {
				delete ch->shape;
				ch->shape = NULL;
				Message ("could not load character shape");
			}

			ch->frames[0].Load (charpath, "start.lst");
			ch->finishframesok = true;
			ch->frames[1].Load (charpath, "finish.lst");
			if (ch->frames[1].loaded == false) ch->finishframesok = false;
			ch->frames[2].Load (charpath, "wonrace.lst");
			if (ch->frames[2].loaded == false) ch->finishframesok = false;
			ch->frames[3].Load (charpath, "lostrace.lst");
			if (ch->frames[3].loaded == false) ch->finishframesok = false;
		}
	}
}
Exemple #10
0
bool CFont::LoadFontlist() {
	CSPList list;
	if (!list.Load(param.font_dir, "fonts.lst")) {
		fonts.push_back(new sf::Font()); // Insert an empty font, otherwise ETR will crash
		return false;
	}

	for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line) {
		std::string fontfile = SPStrN(*line, "file");
		std::string name = SPStrN(*line, "name");

		int ftidx = LoadFont(name, param.font_dir, fontfile);
		if (ftidx < 0) {
			Message("couldn't load font", name);
		}
	}
	return true;
}
void CPlayers::LoadAvatars () {
	CSPList list (MAX_AVATARS);

	if (!list.Load (param.player_dir, "avatars.lst")) {
		Message ("could not load avators.lst");
		return;
	}

	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		string filename = SPStrN (line, "file", "unknown");
		TTexture* texture = new TTexture();
		if (texture && texture->Load(param.player_dir, filename)) {
			avatars.push_back(TAvatar(filename, texture));
		} else
			delete texture;
	}
}
void CKeyframe::SaveTest (const string& dir, const string& filename) {
	CSPList list (100);

	for (size_t i=0; i<frames.size(); i++) {
		TKeyframe* frame = &frames[i];
		string line = "*[time] " + Float_StrN (frame->val[0], 1);
		line += " [pos] " + Float_StrN (frame->val[1], 2);
		line += " " + Float_StrN (frame->val[2], 2);
		line += " " + Float_StrN (frame->val[3], 2);
		if (frame->val[4] != 0) line += " [yaw] " + Float_StrN (frame->val[4], 0);
		if (frame->val[5] != 0) line += " [pitch] " + Float_StrN (frame->val[5], 0);
		if (frame->val[6] != 0) line += " [roll] " + Float_StrN (frame->val[6], 0);
		if (frame->val[7] != 0) line += " [neck] " + Float_StrN (frame->val[7], 0);
		if (frame->val[8] != 0) line += " [head] " + Float_StrN (frame->val[8], 0);

		double ll = frame->val[9];
		double rr = frame->val[10];
		if (ll != 0 || rr != 0)
			line += " [sh] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		ll = frame->val[11];
		rr = frame->val[12];
		if (ll != 0 || rr != 0)
			line += " [arm] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		ll = frame->val[13];
		rr = frame->val[14];
		if (ll != 0 || rr != 0)
			line += " [hip] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		ll = frame->val[15];
		rr = frame->val[16];
		if (ll != 0 || rr != 0)
			line += " [knee] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		ll = frame->val[17];
		rr = frame->val[18];
		if (ll != 0 || rr != 0)
			line += " [ankle] " + Float_StrN (ll, 0) + " " + Float_StrN (rr, 0);

		list.Add (line);
	}
	list.Save (dir, filename);
}
Exemple #13
0
bool CEnvironment::LoadEnvironmentList () {
	int i;
	string line;

	CSPList list (32, true);
	if (!list.Load (param.env_dir2, "environment.lst")) {
		Message ("could not load environment.lst");
		return false;
	}

	numLocs = 0;
	for (i=0; i<list.Count(); i++) {
		line = list.Line (i);
		locs[i].name = SPStrN (line, "location", "");
		numLocs++;
	}
	list.MakeIndex (EnvIndex, "location");
	return true;
}
Exemple #14
0
bool CKeyframe::Load(const std::string& dir, const std::string& filename) {
	if (loaded && loadedfile == filename) return true;
	CSPList list;

	if (list.Load(dir, filename)) {
		frames.resize(list.size());
		std::size_t i = 0;
		for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line, i++) {
			frames[i].val[0] = SPFloatN(*line, "time", 0);
			TVector3d posit = SPVector3d(*line, "pos");
			frames[i].val[1] = posit.x;
			frames[i].val[2] = posit.y;
			frames[i].val[3] = posit.z;
			frames[i].val[4] = SPFloatN(*line, "yaw", 0);
			frames[i].val[5] = SPFloatN(*line, "pitch", 0);
			frames[i].val[6] = SPFloatN(*line, "roll", 0);
			frames[i].val[7] = SPFloatN(*line, "neck", 0);
			frames[i].val[8] = SPFloatN(*line, "head", 0);
			TVector2d pp = SPVector2d(*line, "sh");
			frames[i].val[9] = pp.x;
			frames[i].val[10] = pp.y;
			pp = SPVector2d(*line, "arm");
			frames[i].val[11] = pp.x;
			frames[i].val[12] = pp.y;
			pp = SPVector2d(*line, "hip");
			frames[i].val[13] = pp.x;
			frames[i].val[14] = pp.y;
			pp = SPVector2d(*line, "knee");
			frames[i].val[15] = pp.x;
			frames[i].val[16] = pp.y;
			pp = SPVector2d(*line, "ankle");
			frames[i].val[17] = pp.x;
			frames[i].val[18] = pp.y;
		}
		loaded = true;
		loadedfile = filename;
		return true;
	} else {
		Message("keyframe not found:", filename);
		loaded = false;
		return false;
	}
}
bool CKeyframe::Load (const string& dir, const string& filename) {
	if (loaded && loadedfile == filename) return true;
	CSPList list (1000);

	if (list.Load (dir, filename)) {
		frames.resize(list.Count());
		for (size_t i=0; i<list.Count(); i++) {
			const string& line = list.Line(i);
			frames[i].val[0] = SPFloatN (line, "time", 0);
			TVector3 posit = SPVector3N (line, "pos", NullVec);
			frames[i].val[1] = posit.x;
			frames[i].val[2] = posit.y;
			frames[i].val[3] = posit.z;
			frames[i].val[4] = SPFloatN (line, "yaw", 0);
			frames[i].val[5] = SPFloatN (line, "pitch", 0);
			frames[i].val[6] = SPFloatN (line, "roll", 0);
			frames[i].val[7] = SPFloatN (line, "neck", 0);
			frames[i].val[8] = SPFloatN (line, "head", 0);
			TVector2 pp = SPVector2N (line, "sh", TVector2(0, 0));
			frames[i].val[9] = pp.x;
			frames[i].val[10] = pp.y;
			pp = SPVector2N (line, "arm", TVector2(0, 0));
			frames[i].val[11] = pp.x;
			frames[i].val[12] = pp.y;
			pp = SPVector2N (line, "hip", TVector2(0, 0));
			frames[i].val[13] = pp.x;
			frames[i].val[14] = pp.y;
			pp = SPVector2N (line, "knee", TVector2(0, 0));
			frames[i].val[15] = pp.x;
			frames[i].val[16] = pp.y;
			pp = SPVector2N (line, "ankle", TVector2(0, 0));
			frames[i].val[17] = pp.x;
			frames[i].val[18] = pp.y;
		}
		loaded = true;
		loadedfile = filename;
		return true;
	} else {
		Message ("keyframe not found:", filename);
		loaded = false;
		return false;
	}
}
Exemple #16
0
bool CTexture::LoadTextureList() {
	FreeTextureList();
	CSPList list;
	if (list.Load(param.tex_dir, "textures.lst")) {
		for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line) {
			int id = SPIntN(*line, "id", -1);
			CommonTex.resize(std::max(CommonTex.size(), (std::size_t)id+1));
			std::string texfile = SPStrN(*line, "file");
			bool rep = SPBoolN(*line, "repeat", false);
			if (id >= 0) {
				CommonTex[id] = new TTexture();
				CommonTex[id]->Load(param.tex_dir, texfile, rep);
			} else Message("wrong texture id in textures.lst");
		}
	} else {
		Message("failed to load common textures");
		return false;
	}
	return true;
}
void CTranslation::LoadLanguages () {
	CSPList list (MAX_LANGUAGES);

	languages_ok = false;
	if (!list.Load (param.trans_dir, "languages.lst")) {
		Message ("could not load language list");
		return;
	}

	languages.resize(list.Count()+1);
	languages[0].lang = "en_GB";
	languages[0].language = "English";
	for (size_t i=1; i<list.Count()+1; i++) {
		const string& line = list.Line(i-1);
		languages[i].lang = SPStrN (line, "lang", "en_GB");
		languages[i].language = SPStrN (line, "language", "English");
		LangIndex[languages[i].lang] = i;
	}
	if (!languages.empty()) languages_ok = true;

	if(param.language == string::npos)
		param.language = GetSystemDefaultLangIdx();
}
bool CEnvironment::LoadEnvironmentList () {
	CSPList list (32, true);
	if (!list.Load (param.env_dir2, "environment.lst")) {
		Message ("could not load environment.lst");
		return false;
	}

	locs.resize(list.Count());
	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		locs[i].name = SPStrN (line, "location", "");
	}
	list.MakeIndex (EnvIndex, "location");
	return true;
}
bool CCourse::LoadObjectTypes () {
	CSPList list (MAX_OBJECT_TYPES+10);

	if (!list.Load (param.obj_dir, "object_types.lst")) {
		Message ("could not load object types");
		return false;
	}

	ObjTypes.resize(list.Count());

	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
	    ObjTypes[i].name = SPStrN (line, "name", "");
		ObjTypes[i].textureFile = ObjTypes[i].name;
		ObjTypes[i].texture = NULL;

		ObjTypes[i].drawable = SPBoolN (line, "draw", true);
		if (ObjTypes[i].drawable) {
			ObjTypes[i].textureFile = SPStrN (line, "texture", "");
		}
		ObjTypes[i].collectable = SPBoolN (line, "snap", -1) != 0;
		if (ObjTypes[i].collectable == 0) {
			ObjTypes[i].collectable = -1;
		}

		ObjTypes[i].collidable = SPBoolN (line, "coll", false);
		ObjTypes[i].reset_point = SPBoolN (line, "reset", false);
		ObjTypes[i].use_normal = SPBoolN (line, "usenorm", false);

		if (ObjTypes[i].use_normal) {
			ObjTypes[i].normal = SPVector3N (line, "norm", TVector3(0, 1, 0));
			NormVector ((ObjTypes[i].normal));
		}
		ObjTypes[i].poly = 1;
	}
	list.MakeIndex (ObjectIndex, "name");
	return true;
}
void AddComment (CSPList &list, const string& comment) {
	string line = "# " + comment;
	list.Add (line);
}
Exemple #21
0
void CCharShape::SaveCharNodes (string dir, string filename) {
	CSPList list (MAX_CHAR_NODES + 10);
	string line, order, joint;
	TCharNode *node;
	TCharAction *act;
	int  i, ii, aa;
	TVector3 rotation;
	bool rotflag;

	list.Add ("# Generated by Tuxracer tools");
	list.Add ("");
	if (numMatlines > 0) {
		list.Add ("# Materials:");
		for (i=0; i<numMatlines; i++) list.Add (Matlines[i]);
		list.Add ("");
	}

	list.Add ("# Nodes:");
	for (i=1; i<numNodes; i++) {
		node = Nodes[i];
		act = Actions[i];
		if (node->parent_name >= node->node_name) Message ("wrong parent index");
		line = "*[node] " + Int_StrN (node->node_name);
		line += " [par] " + Int_StrN (node->parent_name); 
		order = act->order;
		rotation = NullVec;
		rotflag = false;

		if (order.size() > 0) {
			line += " [order] " + order;
			for (ii=0; ii<(int)order.size(); ii++) {
				aa = order.at(ii)-48;	
				switch (aa) {
					case 0: line += " [trans] " + Vector_StrN (act->vec[ii], 2); break;
					case 4: line += " [scale] " + Vector_StrN (act->vec[ii], 2); break;
 					case 1: rotation.x = act->dval[ii]; rotflag = true; break;
 					case 2: rotation.y = act->dval[ii]; rotflag = true; break;
 					case 3: rotation.z = act->dval[ii]; rotflag = true; break;
					case 5: line += " [vis] " + Float_StrN (act->dval[ii], 0); break;
					case 9: rotation.z = act->dval[ii]; rotflag = true; break;
				}
			}
			if (rotflag) line += " [rot] " + Vector_StrN (rotation, 2);
		}
		if (act->mat.size() > 0) line += " [mat] " + act->mat;
		if (node->joint.size() > 0) line += " [joint] " + node->joint;
		if (act->name.size() > 0) line += " [name] " + act->name;
		if (node->render_shadow) line += " [shad] 1";
		
		list.Add (line);
		if (i<numNodes-3) {
			if (node->visible && !Nodes[i+1]->visible) list.Add ("");
			joint = Nodes[i+2]->joint;
			if (joint.size() > 0) list.Add ("# " + joint);
		}
	}	
	list.Save (dir, filename);
}
Exemple #22
0
bool CCharShape::Load (string dir, string filename, bool with_actions) {
	CSPList list (500);
	int i, ii, act;
	string line, order, name, mat_name, fullname;
	TVector3 scale, trans, rot;
	double visible;
	bool shadow;
	int node_name, parent_name;

	useActions = with_actions;
	CreateRootNode ();
	newActions = true;

	file_name = filename;
 	if (!list.Load (dir, filename)) {
		Message ("could not load character", filename.c_str());
		return false;
	}

	for (i=0; i<list.Count(); i++) {
		line = list.Line (i);
		node_name = SPIntN (line, "node", -1); 
		parent_name = SPIntN (line, "par", -1);		
		mat_name = SPStrN (line, "mat", "");
		name = SPStrN (line, "joint", "");	
		fullname = SPStrN (line, "name", "");

		if (SPIntN (line, "material", 0) > 0) {
			CreateMaterial (line.c_str());
			if (useActions) {
				Matlines[numMatlines] = line;
				numMatlines++;
			}
		} else {
			visible = SPFloatN (line, "vis", -1.0);	
			shadow = SPBoolN (line, "shad", false);
			order = SPStrN (line, "order", "");
 			CreateCharNode (parent_name, node_name, name, fullname, order, shadow);					
			rot = SPVector3N (line, "rot", NullVec);
			MaterialNode (node_name, mat_name);
			for (ii=0; ii<(int)order.size(); ii++) {
				act = order.at(ii)-48;	
				switch (act) {
					case 0:
						trans = SPVector3N (line, "trans", MakeVector (0,0,0));
						TranslateNode (node_name, trans);
						break;
					case 1: RotateNode (node_name, 1, rot.x); break;
					case 2: RotateNode (node_name, 2, rot.y); break;
					case 3: RotateNode (node_name, 3, rot.z); break;
					case 4:
						scale = SPVector3N (line, "scale", MakeVector (1,1,1));
						ScaleNode (node_name, scale);
						break;
					case 5: VisibleNode (node_name, visible); break;
					case 9: RotateNode (node_name, 2, rot.z); break;
					default: break;
				}
			}
		}
	}
	newActions = false;
	return true;
}
bool CCharShape::Load (const string& dir, const string& filename, bool with_actions) {
	CSPList list (500);

	useActions = with_actions;
	CreateRootNode ();
	newActions = true;

	if (!list.Load (dir, filename)) {
		Message ("could not load character", filename);
		return false;
	}

	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		int node_name = SPIntN (line, "node", -1);
		int parent_name = SPIntN (line, "par", -1);
		string mat_name = SPStrN (line, "mat");
		string name = SPStrN (line, "joint");
		string fullname = SPStrN (line, "name");

		if (SPIntN (line, "material", 0) > 0) {
			CreateMaterial (line);
		} else {
			float visible = SPFloatN (line, "vis", -1.0);
			bool shadow = SPBoolN (line, "shad", false);
			string order = SPStrN (line, "order");
			CreateCharNode (parent_name, node_name, name, fullname, order, shadow);
			TVector3d rot = SPVector3d(line, "rot");
			MaterialNode (node_name, mat_name);
			for (size_t ii = 0; ii < order.size(); ii++) {
				int act = order[ii]-48;
				switch (act) {
					case 0: {
						TVector3d trans = SPVector3d(line, "trans");
						TranslateNode (node_name, trans);
						break;
					}
					case 1:
						RotateNode (node_name, 1, rot.x);
						break;
					case 2:
						RotateNode (node_name, 2, rot.y);
						break;
					case 3:
						RotateNode (node_name, 3, rot.z);
						break;
					case 4: {
						TVector3d scale = SPVector3(line, "scale", TVector3d(1, 1, 1));
						ScaleNode (node_name, scale);
						break;
					}
					case 5:
						VisibleNode (node_name, visible);
						break;
					case 9:
						RotateNode (node_name, 2, rot.z);
						break;
					default:
						break;
				}
			}
		}
	}
	newActions = false;
	return true;
}
void CCharShape::SaveCharNodes (const string& dir, const string& filename) {
	CSPList list (MAX_CHAR_NODES + 10);

	list.Add ("# Generated by Tuxracer tools");
	list.AddLine ();
	if (!Materials.empty()) {
		list.Add ("# Materials:");
		for (size_t i=0; i<Materials.size(); i++)
			if (!Materials[i].matline.empty())
				list.Add (Materials[i].matline);
		list.AddLine ();
	}

	list.Add ("# Nodes:");
	for (size_t i=1; i<numNodes; i++) {
		TCharNode* node = Nodes[i];
		TCharAction* act = node->action;
		if (node->parent_name >= node->node_name) Message ("wrong parent index");
		string line = "*[node] " + Int_StrN ((int)node->node_name);
		line += " [par] " + Int_StrN ((int)node->parent_name);

		if (!act->order.empty()) {
			bool rotflag = false;
			TVector3d rotation;
			line += " [order] " + act->order;
			for (size_t ii=0; ii<act->order.size(); ii++) {
				int aa = act->order[ii]-48;
				switch (aa) {
					case 0:
						line += " [trans] " + Vector_StrN (act->vec[ii], 2);
						break;
					case 4:
						line += " [scale] " + Vector_StrN (act->vec[ii], 2);
						break;
					case 1:
						rotation.x = act->dval[ii];
						rotflag = true;
						break;
					case 2:
						rotation.y = act->dval[ii];
						rotflag = true;
						break;
					case 3:
						rotation.z = act->dval[ii];
						rotflag = true;
						break;
					case 5:
						line += " [vis] " + Float_StrN (act->dval[ii], 0);
						break;
					case 9:
						rotation.z = act->dval[ii];
						rotflag = true;
						break;
				}
			}
			if (rotflag) line += " [rot] " + Vector_StrN (rotation, 2);
		}
		if (!act->mat.empty()) line += " [mat] " + act->mat;
		if (!node->joint.empty()) line += " [joint] " + node->joint;
		if (!act->name.empty()) line += " [name] " + act->name;
		if (node->render_shadow) line += " [shad] 1";

		list.Add (line);
		if (i<numNodes-3) {
			if (node->visible && !Nodes[i+1]->visible) list.AddLine ();
			const string& joint = Nodes[i+2]->joint;
			if (joint.empty()) list.Add ("# " + joint);
		}
	}
	list.Save (dir, filename);
}
void AddComment (CSPList &list, string comment)  {
	string line;
	line = "# " + comment;
	list.Add (line);
}
void AddItem (CSPList &list, const string& tag, const string& content) {
	string item = "  [" +tag + "] " + content;
	list.Add (item);
}
void SaveConfigFile () {
	CSPList liste (512);

	liste.Add ("# ------------------------------------------------------------------");
	liste.Add ("#   The first group of params can be adjusted ");
	liste.Add ("#   on the configuration screen, too");
	liste.Add ("# ------------------------------------------------------------------");
	liste.Add ("");

	AddComment (liste, "Full-screen mode [0...1]");
	AddIntItem (liste, "fullscreen", param.fullscreen);
	liste.Add ("");

	AddComment (liste, "Screen resolution [0...9]");
	AddComment (liste, "0 = auto, 1 = 800x600, 2 = 1024x768");
	AddComment (liste, "3 = 1152x864, 4 = 1280x960, 5 = 1280x1024");
	AddComment (liste, "6 = 1360x768, 7 = 1400x1050, 8 = 1440x900, 9=1680x1050");
	AddIntItem (liste, "res_type", (int)param.res_type);
	liste.Add ("");

	AddComment (liste, "Level of details [1...3]");
	AddComment (liste, "1 = best performance, 3 = best appearance");
	AddIntItem (liste, "detail_level", param.perf_level);
	liste.Add ("");

	AddComment (liste, "Language code [0...]");
	AddComment (liste, "0 = English etc.");
	AddIntItem (liste, "language", (int)param.language);
	liste.Add ("");

	AddComment (liste, "Sound volume [0...120]");
	AddComment (liste, "Sounds are the terrain effects or the pickup noise.");
	AddIntItem (liste, "sound_volume", param.sound_volume);
	liste.Add ("");

	AddComment (liste, "Volume of the background music [0...120]");
    AddIntItem (liste, "music_volume", param.music_volume);
	liste.Add ("");

	liste.Add ("# ------------------------------------------------------------------");
	liste.Add ("#   The second group of params must be adjusted in this file.");
	liste.Add ("# ------------------------------------------------------------------");
	liste.Add ("");

	AddComment (liste, "Forward clipping distance");
	AddComment (liste, "Controls how far ahead of the camera the course");
	AddComment (liste, "is rendered. Larger values mean that more of the course is");
	AddComment (liste, "rendered, resulting in slower performance. Decreasing this ");
	AddComment (liste, "value is an effective way to improve framerates.");
	AddIntItem (liste, "forward_clip_distance", param.forward_clip_distance);
	liste.Add ("");

	AddComment (liste, "Backward clipping distance");
	AddComment (liste, "Some objects aren't yet clipped to the view frustum, ");
	AddComment (liste, "so this value is used to control how far up the course these ");
	AddComment (liste, "objects are drawn.");
	AddIntItem (liste, "backward_clip_distance", param.backward_clip_distance);
	liste.Add ("");

	AddComment (liste, "Field of View of the camera");
	AddIntItem (liste, "fov", param.fov);
	liste.Add ("");

	AddComment (liste, "Bpp mode - bits per pixel [0...2]");
	AddComment (liste, "Controls the color depth of the OpenGL window");
	AddComment (liste, "0 = use current bpp setting of operating system,");
	AddComment (liste, "1 = 16 bpp, 2 = 32 bpp");
	AddIntItem (liste, "bpp_mode", param.bpp_mode);
	liste.Add ("");

	AddComment (liste, "Tree detail distance");
	AddComment (liste, "Controls how far up the course the trees are drawn crosswise.");
	AddIntItem (liste, "tree_detail_distance", param.tree_detail_distance);
	liste.Add ("");

	AddComment (liste, "Tux sphere divisions");
	AddComment (liste, "Controls how detailled the character is drawn");
	AddIntItem (liste, "tux_sphere_divisions", param.tux_sphere_divisions);
	liste.Add ("");

	AddComment (liste, "Tux shadow sphere divisions");
	AddComment (liste, "The same but for the shadow of the character");
	AddIntItem (liste, "tux_shadow_sphere_div", param.tux_shadow_sphere_divisions);
	liste.Add ("");

	AddComment (liste, "Detail level of the course");
	AddComment (liste, "This param is used for the quadtree and controls the");
	AddComment (liste, "LOD of the algorithm. ");
	AddIntItem (liste, "course_detail_level", param.course_detail_level);
	liste.Add ("");

	AddComment (liste, "Font type [0...2]");
	AddComment (liste, "0 = always arial-like font,");
	AddComment (liste, "1 = papercut font on the menu screens");
	AddComment (liste, "2 = papercut font for the hud display, too");
	AddIntItem (liste, "use_papercut_font", param.use_papercut_font);
	liste.Add ("");

	AddComment (liste, "Cursor type [0...1]");
	AddComment (liste, "0 = normal cursor (arrow), 1 = icicle");
	AddIntItem (liste, "ice_cursor", param.ice_cursor);
	liste.Add ("");

	AddComment (liste, "Draw full skybox [0...1]");
	AddComment (liste, "A normal skybox consists of 6 textures. In Tuxracer");
	AddComment (liste, "3 textures are invisible (top, bottom and back).");
	AddComment (liste, "These textures needn't be drawn.");
	AddIntItem (liste, "full_skybox", param.full_skybox);
	liste.Add ("");

	AddComment (liste, "Audio frequency");
	AddComment (liste, "Typical values are 11025, 22050 ...");
	AddIntItem (liste, "audio_freq", param.audio_freq);
	liste.Add ("");

	AddComment (liste, "Size of audio buffer");
	AddComment (liste, "Typical values are 512, 1024, 2048 ...");
	AddIntItem (liste, "audio_buffer_size", param.audio_buffer_size);
	liste.Add ("");

	AddComment (liste, "Select the music:");
	AddComment (liste, "(the racing music is defined by a music theme)");
	AddItem (liste, "menu_music", param.menu_music);
	AddItem (liste, "credits_music", param.credits_music);
	AddItem (liste, "config_music", param.config_music);
	liste.Add ("");

	AddComment (liste, "Use sqare root of scale factors for menu screens [0...1]");
	AddComment (liste, "Exprimental: these factors reduce the effect of screen scaling.");
	AddComment (liste, "The widgets are closer to their default sizes.");
	AddIntItem (liste, "use_quad_scale", param.use_quad_scale);
	liste.Add ("");

	// ---------------------------------------
	liste.Save (param.configfile);
}
bool CCourse::LoadCourseList () {
	CSPList list (128);

	if (!list.Load (param.common_course_dir, "courses.lst")) {
		Message ("could not load courses.lst");
		return false;
	}

	CSPList paramlist (48);

	CourseList.resize(list.Count());
	for (size_t i=0; i<list.Count(); i++) {
		const string& line1 = list.Line(i);
		CourseList[i].name = SPStrN (line1, "name", "noname");
		CourseList[i].dir = SPStrN (line1, "dir", "nodir");

		string desc = SPStrN (line1, "desc", "");
		FT.AutoSizeN (2);
		vector<string> desclist = FT.MakeLineList (desc.c_str(), 335 * Winsys.scale - 16.0);
		size_t cnt = desclist.size();
		if (cnt > MAX_DESCRIPTION_LINES) cnt = MAX_DESCRIPTION_LINES;
		CourseList[i].num_lines = cnt;
		for (size_t ll=0; ll<cnt; ll++) {
			CourseList[i].desc[ll] = desclist[ll];
		}

		string coursepath = param.common_course_dir + SEP + CourseList[i].dir;
		if (DirExists (coursepath.c_str())) {
			// preview
			string previewfile = coursepath + SEP + "preview.png";
			CourseList[i].preview = new TTexture();
			if (!CourseList[i].preview->LoadMipmap(previewfile, 0)) {
				Message ("couldn't load previewfile");
//				texid = Tex.TexID (NO_PREVIEW);
			}

			// params
			string paramfile = coursepath + SEP + "course.dim";
			if (!paramlist.Load (paramfile)) {
				Message ("could not load course.dim");
			}

			const string& line2 = paramlist.Line (0);
			CourseList[i].author = SPStrN (line2, "author", "unknown");
			CourseList[i].size.x = SPFloatN (line2, "width", 100);
			CourseList[i].size.y = SPFloatN (line2, "length", 1000);
			CourseList[i].play_size.x = SPFloatN (line2, "play_width", 90);
			CourseList[i].play_size.y = SPFloatN (line2, "play_length", 900);
			CourseList[i].angle = SPFloatN (line2, "angle", 10);
			CourseList[i].scale = SPFloatN (line2, "scale", 10);
			CourseList[i].start.x = SPFloatN (line2, "startx", 50);
			CourseList[i].start.y = SPFloatN (line2, "starty", 5);
			CourseList[i].env = Env.GetEnvIdx (SPStrN (line2, "env", "etr"));
			CourseList[i].music_theme = Music.GetThemeIdx (SPStrN (line2, "theme", "normal"));
			CourseList[i].use_keyframe = SPBoolN (line2, "use_keyframe", false);
			CourseList[i].finish_brake = SPFloatN (line2, "finish_brake", 20);
			paramlist.Clear ();	// the list is used several times
		}
	}
	list.MakeIndex (CourseIndex, "dir");
	return true;
}
bool CCourse::LoadObjectMap () {
    CImage treeImg;

	if (!treeImg.LoadPng (CourseDir.c_str(), "trees.png", true)) {
		Message ("unable to open trees.png");
		return false;
	}

	int pad = 0;
    int cnt = 0;
	double height, diam;
	CSPList savelist (10000);

	CollArr.clear();
	NocollArr.clear();
	for (int y=0; y<ny; y++) {
        for (int x=0; x<nx; x++) {
            int imgidx = (x + nx * y) * treeImg.depth + pad;
			int type = GetObject (&treeImg.data[imgidx]);
			if (type >= 0) {
				cnt++;
				double xx = (nx - x) / (double)(nx - 1.0) * curr_course->size.x;
				double zz = -(ny - y) / (double)(ny - 1.0) * curr_course->size.y;
				if (ObjTypes[type].texture == NULL && ObjTypes[type].drawable) {
					string terrpath = param.obj_dir + SEP + ObjTypes[type].textureFile;
					ObjTypes[type].texture = new TTexture();
					ObjTypes[type].texture->LoadMipmap(terrpath, 0);
				}

				// set random height and diam - see constants above
				switch (type) {
					case 5: CalcRandomTrees (2.5, 2.5, height, diam); break;
					case 6: CalcRandomTrees (3, 3, height, diam); break;
					case 7: CalcRandomTrees (1.2, 1.2, height, diam); break;

					case 2: case 3:
					height = 6.0;
					diam = 9.0;
					break;

					default:
					height = 1;
					diam = 1;
					break;
				}

				bool coll = ObjTypes[type].collidable;
				if (coll == 1) {
					CollArr.push_back(TCollidable());
				    CollArr.back().pt.x = xx;
				    CollArr.back().pt.z = zz;
			    	CollArr.back().pt.y = FindYCoord (xx, zz);
				    CollArr.back().height = height;
				    CollArr.back().diam = diam;
				    CollArr.back().tree_type = type;
				}
				else if (coll == 0) {
					NocollArr.push_back(TItem());
				    NocollArr.back().pt.x = xx;
				    NocollArr.back().pt.z = zz;
			    	NocollArr.back().pt.y = FindYCoord (xx, zz);
				    NocollArr.back().height = height;
				    NocollArr.back().diam = diam;
				    NocollArr.back().item_type = type;
					NocollArr.back().collectable = ObjTypes[type].collectable;
					NocollArr.back().drawable = ObjTypes[type].drawable;
					ObjTypes[type].num_items++;
				}

				if (SaveItemsFlag) {
					string line = "*[name]";
					line += ObjTypes[type].name;
					SPSetIntN (line, "x", x);
					SPSetIntN (line, "z", y);
					SPSetFloatN (line, "height", height, 1);
					SPSetFloatN (line, "diam", diam, 1);
					savelist.Add (line);
				}
			}
		}
        pad += (nx * treeImg.depth) % 4;
	}
	if (SaveItemsFlag) {
		string itemfile = CourseDir + SEP + "items.lst";
		savelist.Save (itemfile);
	}
	return true;
}