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 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"); }
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 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++; } } }
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; }
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; } } }
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; } }
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; } }
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; }
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 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; }
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 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 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 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 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; }