Exemple #1
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);
}
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 #3
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 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);
}
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;
}
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);
}
void AddComment (CSPList &list, const string& comment) {
	string line = "# " + comment;
	list.Add (line);
}
void AddItem (CSPList &list, const string& tag, const string& content) {
	string item = "  [" +tag + "] " + content;
	list.Add (item);
}
void AddComment (CSPList &list, string comment)  {
	string line;
	line = "# " + comment;
	list.Add (line);
}
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);
}