bool CSPList::Load (const string &filepath) { FILE *tempfile; string line; bool valid; bool fwdflag; bool backflag = false; tempfile = fopen (filepath.c_str(), "r"); if (tempfile == 0) { Message ("CSPList::Load - unable to open",""); return false; } else { while (fgets (cbuffer, 4000, tempfile)) { line = cbuffer; STrimN (line); // delete new line char if in string int npos = line.rfind ('\n'); if (npos >= 0) SDeleteN (line, npos, 1); valid = true; if (line.size() < 1) valid = false; // empty line if (line[0] == '#') valid = false; // comment line if (valid) { if (fcount < fmax) { if (fnewlineflag == 0) { if (cbuffer[0] == '*' || fcount < 1) Add (line); else Append (line, fcount-1); } else if (fnewlineflag == 1) { if (lastchar (line) == '\\') { SDeleteN (line, line.length()-1, 1); fwdflag = true; } else { fwdflag = false; } if (backflag == false) Add (line); else Append (line, fcount-1); backflag = fwdflag; } } else { Message ("CSPList::Load - not enough lines",""); return false; } } } fclose (tempfile); return true; } }
void CSPList::MakeIndex (string &index, const string &tag) { index = ""; string item; int idx = 0; for (int i=0; i<fcount; i++) { item = SPItemN (flines[i], tag); STrimN (item); if (item.size() > 0) { index += "["; index += item; index += "]"; index += Int_StrN (idx); idx++; } } }
void CCharShape::CreateMaterial (const string& line) { TVector3 diff = SPVector3N (line, "diff", TVector3 (0,0,0)); TVector3 spec = SPVector3N (line, "spec", TVector3 (0,0,0)); float exp = SPFloatN (line, "exp", 50); std::string mat = SPItemN (line, "mat"); STrimN(mat); Materials.push_back(TCharMaterial()); Materials.back().diffuse.r = diff.x; Materials.back().diffuse.g = diff.y; Materials.back().diffuse.b = diff.z; Materials.back().diffuse.a = 1.0; Materials.back().specular.r = spec.x; Materials.back().specular.g = spec.y; Materials.back().specular.b = spec.z; Materials.back().specular.a = 1.0; Materials.back().exp = exp; if(useActions) Materials.back().matline = line; MaterialIndex[mat] = Materials.size()-1; }
char *SPNewCharN (string &s, const string &tag) { string item = SPItemN (s, tag); if (item.size() < 1) return 0; STrimN (item); return NewStrN (item.c_str()); }
void SPCharN (string &s, const string &tag, char *result) { string item = SPItemN (s, tag); if (item.size() < 1) return; STrimN (item); strcpy (result, item.c_str()); }
bool SPBoolNX (string &s, const string &tag, const bool def) { string item = SPItemN (s, tag); STrimN (item); return Str_BoolNX (item, def); }
int SPEnumN (string &s, const string &tag, int def) { string item = SPItemN (s, tag); STrimN (item); if (item.size() < 1) return def; return SPIntN (EnumStr, item, def);; }
string SPStrN (string &s, const string &tag, const string def) { string item = SPItemN (s, tag); if (item.size() < 1) return def; STrimN (item); return item; }