bool CPlayerService::LoadXwzFromFile() { dwt::ifstream Player("Data\\升级\\修为值换算.txt"); if (!Player.is_open()) { rfalse("无法打开修为值换算表!"); return false; } char buffer[2048]; while (!Player.eof()) { Player.getline(buffer, sizeof(buffer)); if (0 == buffer[0] || '//' == (*(LPWORD)buffer)) continue; std::strstream linebuf(buffer, (std::streamsize)strlen(buffer)); linebuf >> m_PlayerXwzData.m_Atk >> m_PlayerXwzData.m_Defence >> m_PlayerXwzData.m_CtrAtk >> m_PlayerXwzData.m_Escape >> m_PlayerXwzData.m_Hp >> m_PlayerXwzData.m_Mp >> m_PlayerXwzData.m_Tp >> m_PlayerXwzData.m_ATKSPEED >> m_PlayerXwzData.m_SPEED >> m_PlayerXwzData.m_ABSDAMAGE >> m_PlayerXwzData.m_REDUCEDAMAGE >> m_PlayerXwzData.m_NONFANGYU >> m_PlayerXwzData.KylinArmLevel; } return true; }
bool CMyString::Init() { dwt::ifstream StrinfStream("string\\chineseGB\\chinese.txt"); if (!StrinfStream.is_open()) { return false; } // 开始读取配置了~~~ char buffer[2048]; while (!StrinfStream.eof()) { StrinfStream.getline(buffer, sizeof(buffer)); if (0 == buffer[0] || '//' == (*(LPWORD)buffer)) continue; std::strstream linebuf(buffer, (std::streamsize)strlen(buffer)); std::string strkey; std::string strvalue; linebuf >> strkey; linebuf >> strvalue; strInfo *sinfo = new strInfo; sinfo->bparamcount = parsestrparamcount(strvalue.c_str(),strvalue.length()); sinfo->s_strValue = strvalue.c_str(); m_smystringinfo.insert(make_pair(strkey, sinfo)); } return true; }
bool CFightPetService::LoadPetBaseRise() { dwt::ifstream stream("Data\\侠客\\侠客成长值.txt"); if (!stream.is_open()) { rfalse("无法打开侠客配置表!"); return false; } char buffer[2048]; SFightPetRise *pData = 0; while (!stream.eof()) { stream.getline(buffer, sizeof(buffer)); if (0 == buffer[0] || '//' == (*(LPWORD)buffer)) continue; std::strstream linebuf(buffer, (std::streamsize)strlen(buffer)); pData = new SFightPetRise; DWORD temp = 0; pData->m_nRare = ((linebuf >> temp), temp); temp = 0; pData->m_nHpRiseMin = ((linebuf >> temp), temp); temp = 0; pData->m_nHpRiseMax = ((linebuf >> temp), temp); temp = 0; pData->m_nMpRiseMin = ((linebuf >> temp), temp); temp = 0; pData->m_nMpRiseMax = ((linebuf >> temp), temp); temp = 0; pData->m_nGongJiRiseMin = ((linebuf >> temp), temp); temp = 0; pData->m_nGongJiRiseMax = ((linebuf >> temp), temp); temp = 0; pData->m_nFangYuRiseMin = ((linebuf >> temp), temp); temp = 0; pData->m_nFangYuRiseMax = ((linebuf >> temp), temp); temp = 0; pData->m_nShanBiRiseMin = ((linebuf >> temp), temp); temp = 0; pData->m_nShanBiRiseMax = ((linebuf >> temp), temp); temp = 0; pData->m_nBaojiRiseMin = ((linebuf >> temp), temp); temp = 0; pData->m_nBaojiRiseMax = ((linebuf >> temp), temp); temp = 0; pData->m_nWuXinRiseMin = ((linebuf >> temp), temp); temp = 0; pData->m_nWuXinRiseMax = ((linebuf >> temp), temp); temp = 0; std::pair<FightPetRise::iterator, bool> result; result = m_baseRiseData.insert(make_pair(pData->m_nRare, pData)); if (false == result.second) { rfalse("发现了一个重复的侠客稀有度成长值!!!"); delete pData; } } stream.close(); return true; }
bool CFightPetService::LoadPetBaseData() { dwt::ifstream stream("Data\\侠客\\侠客属性配置表.txt"); if (!stream.is_open()) { rfalse("无法打开侠客配置表!"); return false; } char buffer[2048]; SFightPetBaseData *pData = 0; while (!stream.eof()) { stream.getline(buffer, sizeof(buffer)); if (0 == buffer[0] || '//' == (*(LPWORD)buffer)) continue; std::strstream linebuf(buffer, (std::streamsize)strlen(buffer)); pData = new SFightPetBaseData; DWORD temp = 0; pData->m_ID = ((linebuf >> temp), temp); temp = 0; linebuf >> pData->m_Name; //pData->m_CanChangeName = ((linebuf >> temp), temp); temp = 0; for (size_t i = 0; i < 4; i++) { pData->m_Attri[i][0]=((linebuf >> temp), temp); temp = 0; } pData->m_RareMin= ((linebuf >> temp), temp); temp = 0; pData->m_RareMax= ((linebuf >> temp), temp); temp = 0; pData->m_nexp = ((linebuf >> temp), temp); temp = 0; pData->m_nmodelID = ((linebuf >> temp), temp); temp = 0; pData->m_niconID = ((linebuf >> temp), temp); temp = 0; pData->m_nLimitLevel = ((linebuf >> temp), temp); temp = 0; pData->m_bSex = ((linebuf >> temp), temp); temp = 0; pData->m_Type =((linebuf >> temp), temp); temp = 0; std::pair<FightPetBaseData::iterator, bool> result; result = m_baseData.insert(make_pair(pData->m_ID, pData)); if (false == result.second) { rfalse("发现了一个重复的侠客ID!!!"); delete pData; } } stream.close(); return true; }
bool CMountService::Init() { dwt::ifstream mountStream; mountStream.open("Data\\Æï³Ë\\Æï³ËÅäÖñí.txt"); if (!mountStream.is_open()) return false; char buffer[2048]; SMountBaseData *pMount = 0; while (!mountStream.eof()) { mountStream.getline(buffer, sizeof(buffer)); if (0 == buffer[0] || '//' == (*(LPWORD)buffer)) continue; std::strstream linebuf(buffer, (std::streamsize)strlen(buffer)); pMount = new SMountBaseData; linebuf >> pMount->m_Name; DWORD temp = 0; pMount->m_ID = ((linebuf >> temp), temp); temp = 0; pMount->m_Level = ((linebuf >> temp), temp); temp = 0; pMount->m_Quality = ((linebuf >> temp), temp); temp = 0; pMount->m_RideNum = ((linebuf >> temp), temp); temp = 0; pMount->m_CanUpdate = ((linebuf >> temp), temp); temp = 0; pMount->m_NeedExp = ((linebuf >> temp), temp); temp = 0; pMount->m_SpeedUp = ((linebuf >> temp), temp); temp = 0; for (size_t i = 0; i < EMA_MAX; i++) linebuf >> pMount->m_Attri[i][0], linebuf >> pMount->m_Attri[i][1]; pMount->m_ModelID = ((linebuf >> temp), temp); temp = 0; pair<std::hash_map<WORD, SMountBaseData*>::iterator, bool> result; result = m_baseData[pMount->m_ID].insert(make_pair(pMount->m_Level, pMount)); if (false == result.second) { rfalse("·¢ÏÖÁËÒ»¸öÖظ´µÄÆï³ËµÈ¼¶±àºÅ£¡"); delete pMount; } } return true; }
bool CPlayerService::Init() { dwt::ifstream Player("Data\\升级\\角色升级表.txt"); if (!Player.is_open()) { rfalse("无法打开角色升级表!"); return false; } char buffer[2048]; WORD level; SBaseAttribute *pData = 0; while (!Player.eof()) { Player.getline(buffer, sizeof(buffer)); if (0 == buffer[0] || '//' == (*(LPWORD)buffer)) continue; std::strstream linebuf(buffer, (std::streamsize)strlen(buffer)); pData = new SBaseAttribute; // linebuf >> level >> pData->m_FreePoint >> pData->m_GongJi >> pData->m_FangYu >> pData->m_BaoJi >> pData->m_ShanBi >> pData->m_BaseHp // >> pData->m_BaseMp >> pData->m_BaseTp >> pData->m_BaseJp >> pData->m_BaseSp >> pData->m_Exp >> pData->m_HpRecoverSpeed // >> pData->m_MpRecoverSpeed >> pData->m_TpRecoverSpeed >> pData->m_HpRecoverInterval >> pData->m_MpRecoverInterval // >> pData->m_TpRecoverInterval; linebuf >> level >> pData->m_BaseHp >> pData->m_BaseJp >> pData->m_GongJi >> pData->m_FangYu >> pData->m_Hit >> pData->m_ShanBi >> pData->m_BaoJi >> pData->m_uncrit>>pData->m_wreck >> pData->m_unwreck >> pData->m_puncture >> pData->m_unpuncture >> pData->m_BaseTp >> pData->m_TpRecover >> pData->m_TpRecoverInterval >> pData->m_Exp; std::pair<PlayerUpdateData::iterator, bool> result; result = m_PlayerUpdate.insert(make_pair(level, pData)); if (false == result.second) { rfalse("发现了一个重复的等级设定!"); delete pData; } } return true; }
std::vector<std::string> tokenize(const std::string &str, const std::string &delims) { std::vector<char> linebuf(str.begin(), str.end()); linebuf.resize(linebuf.size() + 1); std::vector<std::string> tokens; char *temp; char *token; token = strtok_r(linebuf.data(), delims.c_str(), &temp); while (token != nullptr) { tokens.emplace_back(token); token = strtok_r(nullptr, delims.c_str(), &temp); } return tokens; }
std::string ObjLoader::LoadObj(shapes_t& shapes, const char* filename, const char* mtl_basepath) { shapes.reset(); std::stringstream err; std::istringstream ifs(FileUtils::getInstance()->getStringFromFile(filename)); std::map<vertex_index, ssize_t> vertexCache; //std::ifstream ifs(filename); if (!ifs) { err << "Cannot open file [" << filename << "]" << std::endl; return err.str(); } std::vector<float> v; std::vector<float> vn; std::vector<float> vt; std::vector<std::vector<vertex_index> > faceGroup; std::string name; // material std::map<std::string, material_t> material_map; material_t material; int maxchars = 8192; // Alloc enough size. std::vector<char> buf(maxchars); // Alloc enough size. while (ifs.peek() != -1) { ifs.getline(&buf[0], maxchars); std::string linebuf(&buf[0]); // Trim newline '\r\n' or '\r' if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } // Skip if empty line. if (linebuf.empty()) { continue; } // Skip leading space. const char* token = linebuf.c_str(); token += strspn(token, " \t"); assert(token); if (token[0] == '\0') continue; // empty line if (token[0] == '#') continue; // comment line // vertex if (token[0] == 'v' && isSpace((token[1]))) { token += 2; float x, y, z; parseFloat3(x, y, z, token); v.push_back(x); v.push_back(y); v.push_back(z); continue; } // normal if (token[0] == 'v' && token[1] == 'n' && isSpace((token[2]))) { token += 3; float x, y, z; parseFloat3(x, y, z, token); vn.push_back(x); vn.push_back(y); vn.push_back(z); continue; } // texcoord if (token[0] == 'v' && token[1] == 't' && isSpace((token[2]))) { token += 3; float x, y; parseFloat2(x, y, token); vt.push_back(x); vt.push_back(y); continue; } // face if (token[0] == 'f' && isSpace((token[1]))) { token += 2; token += strspn(token, " \t"); std::vector<vertex_index> face; while (!isNewLine(token[0])) { // fix warning, cast to int, i think int is enough vertex_index vi = parseTriple(token, (int)v.size() / 3, (int)vn.size() / 3, (int)vt.size() / 2); face.push_back(vi); auto n = strspn(token, " \t\r"); token += n; } faceGroup.push_back(face); continue; } // use mtl if ((0 == strncmp(token, "usemtl", 6)) && isSpace((token[6]))) { exportFaceGroupToShape(vertexCache, shapes, v, vn, vt, faceGroup, material, name); faceGroup.clear(); char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); if (material_map.find(namebuf) != material_map.end()) { material = material_map[namebuf]; } else { // { error!! material not found } InitMaterial(material); } continue; } // load mtl if ((0 == strncmp(token, "mtllib", 6)) && isSpace((token[6]))) { char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); std::string err_mtl = LoadMtl(material_map, namebuf, mtl_basepath); if (!err_mtl.empty()) { faceGroup.clear(); // for safety //return err_mtl; } continue; } // group name if (token[0] == 'g' && isSpace((token[1]))) { // flush previous face group. shape_t shape; exportFaceGroupToShape(vertexCache, shapes, v, vn, vt, faceGroup, material, name); faceGroup.clear(); std::vector<std::string> names; while (!isNewLine(token[0])) { std::string str = parseString(token); names.push_back(str); token += strspn(token, " \t\r"); // skip tag } assert(names.size() > 0); // names[0] must be 'g', so skipt 0th element. if (names.size() > 1) { name = names[1]; } else { name = ""; } continue; } // object name if (token[0] == 'o' && isSpace((token[1]))) { // flush previous face group. shape_t shape; exportFaceGroupToShape(vertexCache, shapes, v, vn, vt, faceGroup, material, name); faceGroup.clear(); // @todo { multiple object name? } char namebuf[4096]; token += 2; sscanf(token, "%s", namebuf); name = std::string(namebuf); continue; } // Ignore unknown command. } shape_t shape; exportFaceGroupToShape(vertexCache, shapes, v, vn, vt, faceGroup, material, name); faceGroup.clear(); // for safety return err.str(); }
std::string LoadMtl ( std::map<std::string, ObjLoader::material_t>& material_map, const char* filename, const char* mtl_basepath) { material_map.clear(); std::stringstream err; std::string filepath; if (mtl_basepath) { filepath = std::string(mtl_basepath) + std::string(filename); } else { filepath = std::string(filename); } std::istringstream ifs(FileUtils::getInstance()->getStringFromFile(filepath)); if (!ifs) { err << "Cannot open file [" << filepath << "]" << std::endl; return err.str(); } ObjLoader::material_t material; int maxchars = 8192; // Alloc enough size. std::vector<char> buf(maxchars); // Alloc enough size. while (ifs.peek() != -1) { ifs.getline(&buf[0], maxchars); std::string linebuf(&buf[0]); // Trim newline '\r\n' or '\r' if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } // Skip if empty line. if (linebuf.empty()) { continue; } // Skip leading space. const char* token = linebuf.c_str(); token += strspn(token, " \t"); assert(token); if (token[0] == '\0') continue; // empty line if (token[0] == '#') continue; // comment line // new mtl if ((0 == strncmp(token, "newmtl", 6)) && isSpace((token[6]))) { // flush previous material. material_map.insert(std::pair<std::string, ObjLoader::material_t>(material.name, material)); // initial temporary material InitMaterial(material); // set new mtl name char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); material.name = namebuf; continue; } // ambient if (token[0] == 'K' && token[1] == 'a' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.ambient[0] = r; material.ambient[1] = g; material.ambient[2] = b; continue; } // diffuse if (token[0] == 'K' && token[1] == 'd' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.diffuse[0] = r; material.diffuse[1] = g; material.diffuse[2] = b; continue; } // specular if (token[0] == 'K' && token[1] == 's' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.specular[0] = r; material.specular[1] = g; material.specular[2] = b; continue; } // transmittance if (token[0] == 'K' && token[1] == 't' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.transmittance[0] = r; material.transmittance[1] = g; material.transmittance[2] = b; continue; } // ior(index of refraction) if (token[0] == 'N' && token[1] == 'i' && isSpace((token[2]))) { token += 2; material.ior = parseFloat(token); continue; } // emission if(token[0] == 'K' && token[1] == 'e' && isSpace(token[2])) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.emission[0] = r; material.emission[1] = g; material.emission[2] = b; continue; } // shininess if(token[0] == 'N' && token[1] == 's' && isSpace(token[2])) { token += 2; material.shininess = parseFloat(token); continue; } // illum model if (0 == strncmp(token, "illum", 5) && isSpace(token[5])) { token += 6; material.illum = parseInt(token); continue; } // dissolve if ((token[0] == 'd' && isSpace(token[1]))) { token += 1; material.dissolve = parseFloat(token); continue; } if (token[0] == 'T' && token[1] == 'r' && isSpace(token[2])) { token += 2; material.dissolve = parseFloat(token); continue; } // ambient texture if ((0 == strncmp(token, "map_Ka", 6)) && isSpace(token[6])) { token += 7; material.ambient_texname = trim(token); replacePathSeperator(material.ambient_texname); continue; } // diffuse texture if ((0 == strncmp(token, "map_Kd", 6)) && isSpace(token[6])) { token += 7; material.diffuse_texname = trim(token); replacePathSeperator(material.diffuse_texname); continue; } // specular texture if ((0 == strncmp(token, "map_Ks", 6)) && isSpace(token[6])) { token += 7; material.specular_texname = trim(token); replacePathSeperator(material.specular_texname); continue; } // normal texture if ((0 == strncmp(token, "map_Ns", 6)) && isSpace(token[6])) { token += 7; material.normal_texname = trim(token); replacePathSeperator(material.normal_texname); continue; } // unknown parameter const char* _space = strchr(token, ' '); if(!_space) { _space = strchr(token, '\t'); } if(_space) { auto len = _space - token; std::string key(token, len); std::string value = _space + 1; material.unknown_parameter.insert(std::pair<std::string, std::string>(key, value)); } } // flush last material. material_map.insert(std::pair<std::string, ObjLoader::material_t>(material.name, material)); return err.str(); }
std::string LoadObj( std::vector<shape_t>& shapes, std::vector<material_t>& materials, // [output] std::istream& inStream, MaterialReader& readMatFn) { std::stringstream err; std::vector<float> v; std::vector<float> vn; std::vector<float> vt; std::vector<std::vector<vertex_index> > faceGroup; std::string name; // material std::map<std::string, int> material_map; std::map<vertex_index, unsigned int> vertexCache; int material = -1; shape_t shape; int maxchars = 8192; // Alloc enough size. std::vector<char> buf(maxchars); // Alloc enough size. while (inStream.peek() != -1) { inStream.getline(&buf[0], maxchars); std::string linebuf(&buf[0]); // Trim newline '\r\n' or '\n' if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\r') linebuf.erase(linebuf.size()-1); } // Skip if empty line. if (linebuf.empty()) { continue; } // Skip leading space. const char* token = linebuf.c_str(); token += strspn(token, " \t"); assert(token); if (token[0] == '\0') continue; // empty line if (token[0] == '#') continue; // comment line // vertex if (token[0] == 'v' && isSpace((token[1]))) { token += 2; float x, y, z; parseFloat3(x, y, z, token); v.push_back(x); v.push_back(y); v.push_back(z); continue; } // normal if (token[0] == 'v' && token[1] == 'n' && isSpace((token[2]))) { token += 3; float x, y, z; parseFloat3(x, y, z, token); vn.push_back(x); vn.push_back(y); vn.push_back(z); continue; } // texcoord if (token[0] == 'v' && token[1] == 't' && isSpace((token[2]))) { token += 3; float x, y; parseFloat2(x, y, token); vt.push_back(x); vt.push_back(y); continue; } // face if (token[0] == 'f' && isSpace((token[1]))) { token += 2; token += strspn(token, " \t"); std::vector<vertex_index> face; while (!isNewLine(token[0])) { vertex_index vi = parseTriple(token, v.size() / 3, vn.size() / 3, vt.size() / 2); face.push_back(vi); int n = strspn(token, " \t\r"); token += n; } faceGroup.push_back(face); continue; } // use mtl if ((0 == strncmp(token, "usemtl", 6)) && isSpace((token[6]))) { char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); faceGroup.clear(); if (material_map.find(namebuf) != material_map.end()) { material = material_map[namebuf]; } else { // { error!! material not found } material = -1; } continue; } // load mtl if ((0 == strncmp(token, "mtllib", 6)) && isSpace((token[6]))) { char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); std::string err_mtl = readMatFn(namebuf, materials, material_map); if (!err_mtl.empty()) { faceGroup.clear(); // for safety return err_mtl; } continue; } // group name if (token[0] == 'g' && isSpace((token[1]))) { // flush previous face group. bool ret = exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, material, name, true); if (ret) { shapes.push_back(shape); } shape = shape_t(); //material = -1; faceGroup.clear(); std::vector<std::string> names; while (!isNewLine(token[0])) { std::string str = parseString(token); names.push_back(str); token += strspn(token, " \t\r"); // skip tag } assert(names.size() > 0); // names[0] must be 'g', so skipt 0th element. if (names.size() > 1) { name = names[1]; } else { name = ""; } continue; } // object name if (token[0] == 'o' && isSpace((token[1]))) { // flush previous face group. bool ret = exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, material, name, true); if (ret) { shapes.push_back(shape); } //material = -1; faceGroup.clear(); shape = shape_t(); // @todo { multiple object name? } char namebuf[4096]; token += 2; sscanf(token, "%s", namebuf); name = std::string(namebuf); continue; } // Ignore unknown command. } bool ret = exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, material, name, true); if (ret) { shapes.push_back(shape); } faceGroup.clear(); // for safety return err.str(); }
void ObjectParser( TArray<FVector>& positions, TArray<FVector>& normals, TArray<FVector2D>& uvs, TArray<int32>& indices ) { char filepath[1024]; sprintf_s(filepath, "../../../../../../Siggraph2017/assets/Simplygon/InfinityBlade/InfinityBladeAdversaries/Enemy_Bear/clean_Enemy_Bear_099.obj"); std::ifstream ifs(filepath); if (!ifs) { UE_LOG(LogTemp, Warning, TEXT("output : %s"), L"オブジェクトファイルの読み込みに失敗しました"); } int maxchars = 8192; // Alloc enough size. std::vector<char> buf(maxchars); // Alloc enough size. while (ifs.peek() != -1) { ifs.getline(&buf[0], maxchars); std::string linebuf(&buf[0]); // Trim newline '\r\n' or '\r' if (linebuf.size() > 0) { if (linebuf[linebuf.size() - 1] == '\n') linebuf.erase(linebuf.size() - 1); } if (linebuf.size() > 0) { if (linebuf[linebuf.size() - 1] == '\n') linebuf.erase(linebuf.size() - 1); } // Skip if empty line. if (linebuf.empty()) { continue; } // Skip leading space. const char* token = linebuf.c_str(); token += strspn(token, " \t"); assert(token); if (token[0] == '\0') continue; // empty line if (token[0] == '#') continue; // comment line // vertex if (token[0] == 'v' && isSpace((token[1]))) { token += 2; float xyz[3]; parseFloat3(xyz[0], xyz[1], xyz[2], token); positions.Add(FVector(xyz[0], xyz[1], xyz[2])); continue; } // normal if (token[0] == 'v' && token[1] == 'n' && isSpace((token[2]))) { token += 3; float xyz[3]; parseFloat3(xyz[0], xyz[1], xyz[2], token); normals.Add(FVector(xyz[0], xyz[1], xyz[2])); continue; } // texcoord if (token[0] == 'v' && token[1] == 't' && isSpace((token[2]))) { token += 3; float uv[2]; parseFloat2(uv[0], uv[1], token); uvs.Add(FVector2D(uv[0], 1.0f - uv[1])); continue; } // face if (token[0] == 'f' && isSpace((token[1]))) { token += 2; token += strspn(token, " \t"); std::vector<vertex_index> face; int tmp[3]; int tmp_index = 0; while (!isNewLine(token[0])) { vertex_index vi = parseTriple(token, 3, 3, 2); tmp[tmp_index] = vi.v_idx; tmp_index++; int n = strspn(token, " \t\r"); token += n; } indices.Add(tmp[2]); indices.Add(tmp[1]); indices.Add(tmp[0]); continue; } // use mtl if ((0 == strncmp(token, "usemtl", 6)) && isSpace((token[6]))) { continue; } // load mtl if ((0 == strncmp(token, "mtllib", 6)) && isSpace((token[6]))) { continue; } // group name if (token[0] == 'g' && isSpace((token[1]))) { continue; } // object name if (token[0] == 'o' && isSpace((token[1]))) { continue; } // Ignore unknown command. } }
std::string LoadMtl ( std::map<std::string, int>& material_map, std::vector<material_t>& materials, std::istream& inStream) { material_map.clear(); std::stringstream err; material_t material; int maxchars = 8192; // Alloc enough size. std::vector<char> buf(maxchars); // Alloc enough size. while (inStream.peek() != -1) { inStream.getline(&buf[0], maxchars); std::string linebuf(&buf[0]); // Trim newline '\r\n' or '\n' if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\r') linebuf.erase(linebuf.size()-1); } // Skip if empty line. if (linebuf.empty()) { continue; } // Skip leading space. const char* token = linebuf.c_str(); token += strspn(token, " \t"); assert(token); if (token[0] == '\0') continue; // empty line if (token[0] == '#') continue; // comment line // new mtl if ((0 == strncmp(token, "newmtl", 6)) && isSpace((token[6]))) { // flush previous material. if (!material.name.empty()) { material_map.insert(std::pair<std::string, int>(material.name, materials.size())); materials.push_back(material); } // initial temporary material InitMaterial(material); // set new mtl name char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); material.name = namebuf; continue; } // ambient if (token[0] == 'K' && token[1] == 'a' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.ambient[0] = r; material.ambient[1] = g; material.ambient[2] = b; continue; } // diffuse if (token[0] == 'K' && token[1] == 'd' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.diffuse[0] = r; material.diffuse[1] = g; material.diffuse[2] = b; continue; } // specular if (token[0] == 'K' && token[1] == 's' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.specular[0] = r; material.specular[1] = g; material.specular[2] = b; continue; } // transmittance if (token[0] == 'K' && token[1] == 't' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.transmittance[0] = r; material.transmittance[1] = g; material.transmittance[2] = b; continue; } // ior(index of refraction) if (token[0] == 'N' && token[1] == 'i' && isSpace((token[2]))) { token += 2; material.ior = parseFloat(token); continue; } // emission if(token[0] == 'K' && token[1] == 'e' && isSpace(token[2])) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.emission[0] = r; material.emission[1] = g; material.emission[2] = b; continue; } // shininess if(token[0] == 'N' && token[1] == 's' && isSpace(token[2])) { token += 2; material.shininess = parseFloat(token); continue; } // illum model if (0 == strncmp(token, "illum", 5) && isSpace(token[5])) { token += 6; material.illum = parseInt(token); continue; } // dissolve if ((token[0] == 'd' && isSpace(token[1]))) { token += 1; material.dissolve = parseFloat(token); continue; } if (token[0] == 'T' && token[1] == 'r' && isSpace(token[2])) { token += 2; material.dissolve = parseFloat(token); continue; } // ambient texture if ((0 == strncmp(token, "map_Ka", 6)) && isSpace(token[6])) { token += 7; material.ambient_texname = token; continue; } // diffuse texture if ((0 == strncmp(token, "map_Kd", 6)) && isSpace(token[6])) { token += 7; material.diffuse_texname = token; continue; } // specular texture if ((0 == strncmp(token, "map_Ks", 6)) && isSpace(token[6])) { token += 7; material.specular_texname = token; continue; } // normal texture if ((0 == strncmp(token, "map_Ns", 6)) && isSpace(token[6])) { token += 7; material.normal_texname = token; continue; } // normal texture (I ADDED THIS) if ((0 == strncmp(token, "map_bump", 8)) && isSpace(token[8])) { token += 9; material.normal_texname = token; continue; } // unknown parameter const char* _space = strchr(token, ' '); if(!_space) { _space = strchr(token, '\t'); } if(_space) { int len = _space - token; std::string key(token, len); std::string value = _space + 1; material.unknown_parameter.insert(std::pair<std::string, std::string>(key, value)); } } // flush last material. material_map.insert(std::pair<std::string, int>(material.name, materials.size())); materials.push_back(material); return err.str(); }
bool CMonsterService::LoadMonsterBaseData() { dwt::ifstream stream("Data\\怪物\\怪物配置表.txt"); if (!stream.is_open()) { rfalse("无法打开怪物配置表!"); return false; } char buffer[2048]; SMonsterBaseData *pData = 0; while (!stream.eof()) { stream.getline(buffer, sizeof(buffer)); if (0 == buffer[0] || '//' == (*(LPWORD)buffer)) continue; std::strstream linebuf(buffer, (std::streamsize)strlen(buffer)); pData = new SMonsterBaseData; DWORD temp = 0; linebuf >> pData->m_ID >> pData->m_Name; pData->m_LookID = ((linebuf >> temp), temp); temp = 0; pData->m_level = ((linebuf >> temp), temp); temp = 0; pData->m_MaxHP = ((linebuf >> temp), temp); temp = 0; pData->m_MaxMP = ((linebuf >> temp), temp); temp = 0; pData->m_Orbit = ((linebuf >> temp), temp); temp = 0; pData->m_WalkSpeed = ((linebuf >> temp), temp); temp = 0; pData->m_FightSpeed = ((linebuf >> temp), temp); temp = 0; pData->m_ReBirthInterval = ((linebuf >> temp), temp); temp = 0; pData->m_PartolRadius = ((linebuf >> temp), temp); temp = 0; pData->m_BodySize = ((linebuf >> temp), temp); temp = 0; pData->m_ActiveRadius = ((linebuf >> temp), temp); temp = 0; pData->m_TailLength = ((linebuf >> temp), temp); temp = 0; pData->m_GongJi = ((linebuf >> temp), temp); temp = 0; pData->m_FangYu = ((linebuf >> temp), temp); temp = 0; pData->m_ShanBi = ((linebuf >> temp), temp); temp = 0; pData->m_BaoJi = ((linebuf >> temp), temp); temp = 0; pData->m_AtkSpeed = ((linebuf >> temp), temp); temp = 0; pData->m_LevelType = ((linebuf >> temp), temp); temp = 0; pData->m_AttType = ((linebuf >> temp), temp); temp = 0; pData->m_Exp = ((linebuf >> temp), temp); temp = 0; pData->m_Sp = ((linebuf >> temp), temp); temp = 0; pData->m_BloodMute = ((linebuf >> temp), temp); temp = 0; pData->m_AttMute = ((linebuf >> temp), temp); temp = 0; pData->m_DefenceMute = ((linebuf >> temp), temp); temp = 0; pData->m_AttInterval = ((linebuf >> temp), temp); temp = 0; pData->m_KillTaskID = ((linebuf >> temp), temp); temp = 0; pData->m_Direction = ((linebuf >> temp), temp); temp = 0; pData->m_EndTailCondition = ((linebuf >> temp), temp); temp = 0; pData->m_MoveType = ((linebuf >> temp), temp); temp = 0; pData->m_SearchTargetInterval = ((linebuf >> temp), temp); temp = 0; pData->m_StayTimeMin = ((linebuf >> temp), temp); temp = 0; pData->m_StayTimeMax = ((linebuf >> temp), temp); temp = 0; ///读取怪物技能ID int i=0; while(i<MAX_MONTER_SKILLCOUNT) { pData->m_SkillID[i] = ((linebuf >> temp), temp); temp = 0; i++; } pData->m_StaticAI = ((linebuf >> temp), temp); temp = 0; pData->m_GroupID = ((linebuf >> temp), temp); temp = 0; pData->m_uncrit = ((linebuf >> temp), temp); temp = 0; pData->m_wreck = ((linebuf >> temp), temp); temp = 0; pData->m_unwreck = ((linebuf >> temp), temp); temp = 0; pData->m_puncture = ((linebuf >> temp), temp); temp = 0; pData->m_unpuncture = ((linebuf >> temp), temp); temp = 0; pData->m_Hit = ((linebuf >> temp), temp); temp = 0; std::pair<MonsterBaseData::iterator, bool> result; result = m_baseData.insert(make_pair(pData->m_ID, pData)); if (false == result.second) { rfalse("发现了一个重复的怪物ID号!"); delete pData; } } stream.close(); return true; }
void VfkStream::ScanFile(int fx) { RTIMING("VfkStream::ScanFile"); Stream& strm = streams[fx]; int64 last_line = strm.GetSize(); while(last_line > 0) { strm.Seek(last_line - 1); if(strm.Get() == '\n') break; last_line--; } strm.Seek(0); try { int c; int64 rowpos = strm.GetPos(); while((c = strm.Get()) == '&' && ((c = strm.Get()) == 'H' || c == 'D') && IsAlpha(strm.Term())) { char type = c; int64 begin = strm.GetPos(); SkipRow(strm); rowpos = strm.GetPos(); int len = (int)(strm.GetPos() - begin); StringBuffer linebuf(len + 1); strm.Seek(begin); strm.Get(linebuf, len); linebuf[len] = 0; const char *b = linebuf; const char *id = b; while(IsIdent(*++b)) ; String ident(id, b); if(*b++ != ';') throw Exc(NFormat("';' expected after '%s' (found: '%c', %2:02x)", ident, *b)); if(type == 'D') { String fident = "X_" + ident; int f = tables.Find(fident); if(f < 0) throw Exc(NFormat("unexpected data for filter table '%s'", ident)); // b = ScanRow(b, tables[f]); } else if(IsAlpha(*b)) { String fident = "X_" + ident; Table& tbl = tables.GetAdd(fident); tbl.name = tbl.rawname = fident; tbl.row_count = 0; ScanHeader(b, tbl); } else { do { Vector<Value> row; row.SetCount(HDR_COUNT); if(*b == '\"') { WString text = ReadString(b, &b); if(IsDateTime(ident) && !IsNull(text)) { Time dt = VfkReadTime(text.ToString(), NULL); if(IsNull(dt)) throw Exc(NFormat("invalid date/time value %s", AsCString(text.ToString()))); row[HDR_DTM] = dt; } else { row[HDR_STR] = text; if(ident == "CODEPAGE") if(text == WString("EE8MSWIN1250")) charset = CHARSET_WIN1250; } } else { double num = ScanDouble(b, &b); if(IsNull(num)) throw Exc("invalid numeric value"); row[HDR_NUM] = num; } int l = header.FindLast(ident); row[HDR_ID] = ident; row[HDR_ORD] = (l >= 0 ? (int)header[l][HDR_ORD] + 1 : 0); header.Add(ident) = row; } while(*b++ == ';'); b--; } } strm.Seek(rowpos); while(strm.Get() == '&' && strm.Get() == 'B' && IsAlpha(strm.Term())) { int64 header_offset = strm.GetPos(); SkipRow(strm); int64 begin_offset = strm.GetPos(); int len = (int)(begin_offset - header_offset); Buffer<char> linebuf(len + 1); strm.Seek(header_offset); strm.Get(linebuf, len); linebuf[len] = 0; const char *b = linebuf; const char *id = b; while(IsIdent(*++b)) ; int idlen = b - id; String ident(id, b); if(*b++ != ';') throw Exc(NFormat("';' expected after '%s' (found: '%c', %2:02x)", ident, *b)); String name = ident; for(const VFKLongName *ln = vfk_long_names; ln->shortname; ln++) if(name == ln->shortname) { name = ln->longname; break; } Table& tbl = tables.GetAdd(name); tbl.name = name; tbl.rawname = ident; ScanHeader(b, tbl); int64 p = begin_offset, e = last_line; Buffer<char> idbuf(idlen + 3); while(p < e) { int64 m = (p + e) >> 1; while(m > p) { char part[100]; int partsize = (int)min<int64>(m - p, sizeof(part)); strm.Seek(m - partsize); strm.Get(part, partsize); const char *x = &part[partsize]; while(x > part && x[-1] != '\n') x--; int lfpos = x - part; if(x > part && --x > part && x[-1] == '\r') x--; m -= partsize - lfpos; if(x <= part) continue; if(*--x != '\xA4') break; m -= lfpos - (x - part); } strm.Seek(m); if(strm.Get(idbuf, idlen + 3) != idlen + 3 || idbuf[0] != '&' || idbuf[1] != 'D' || memcmp(~idbuf + 2, id, idlen) || idbuf[idlen + 2] != ';') e = m; else { SkipRow(strm); p = strm.GetPos(); } } int xgrp = file_groups.GetKey(fx); int f; for(f = 0; f < tbl.file_index.GetCount(); f++) if(file_groups.GetKey(tbl.file_index[f]) == xgrp) break; if(f >= tbl.file_index.GetCount()) { tbl.file_index.Add(fx); tbl.begin_offset.Add(begin_offset); tbl.end_offset.Add(p); } strm.Seek(p); } } catch(Exc e) { throw Exc(NFormat("%s (offset %n): %s", file_groups[fx], strm.GetPos(), e)); } }
int main() { filtering_streambuf<line_inserter> linebuf(std::cout.rdbuf()); std::ostream os(&linebuf); os << "Hello" << std::endl << "World"; }
bool CGloryAndTitleServer::Init() { //加载荣耀基本数据 dwt::ifstream stream("Data\\荣耀和称号\\GloryTable.txt"); if (!stream.is_open()) return false; char buffer[2048]; SGloryBaseData *pData = 0; while (!stream.eof()) { stream.getline(buffer, sizeof(buffer)); if (0 == buffer[0] || '//' == (*(LPWORD)buffer)) continue; std::strstream linebuf(buffer, (std::streamsize)strlen(buffer)); pData = new SGloryBaseData; DWORD temp = 0; pData->m_GloryID= ((linebuf >> temp), temp); temp = 0; linebuf >> pData->m_GloryName; pData->m_GloryType = ((linebuf >> temp), temp); temp = 0; for (int i = 0; i < GLORY_AMAX; i++) linebuf >> pData->m_AwardFactor[i]; for (int i = 0; i < GLORY_CMAX; i++) linebuf >> pData->m_GetConditionFactor[i]; pData->m_GloryConditionIndex = ((linebuf >> temp), temp); temp = 0; linebuf >> pData->m_ConditionDetail; pData->m_GloryIcon = ((linebuf >> temp), temp); temp = 0; m_GloryBaseData.insert(make_pair(pData->m_GloryID, pData)); } //加载称号基本数据 dwt::ifstream stream1("Data\\荣耀和称号\\TitleTable.txt"); if (!stream1.is_open()) return false; char buffer1[2048]; STitleBaseData *pData1 = 0; while (!stream1.eof()) { stream1.getline(buffer1, sizeof(buffer1)); if (0 == buffer1[0] || '//' == (*(LPWORD)buffer1)) continue; std::strstream linebuf1(buffer1, (std::streamsize)strlen(buffer1)); pData1 = new STitleBaseData; DWORD temp = 0; pData1->m_TitleID = ((linebuf1 >> temp), temp); temp = 0; linebuf1 >> pData1->m_TitleName; for (int i = 0; i < TITLE_AMAX; i++) linebuf1 >> pData1->m_AddFactor[i]; for (int i = 0; i < TITLE_CMAX; i++) linebuf1 >> pData1->m_ConsumeFactor[i]; pData1->m_ConsumeItemID = ((linebuf1 >> temp), temp); temp = 0; pData1->m_TitleIcon = ((linebuf1 >> temp), temp); temp = 0; linebuf1 >> pData1->m_TitleDescript; m_TitleBaseData.insert(make_pair(pData1->m_TitleID, pData1)); } return true; }
/// Read the ASCII formatted disctionary. This is meant to be the reverse /// of toASCII, where each line of the input stream contains a positve /// integer followed by a string value, with an optioinal ':' (plus white /// space) as separators. /// /// The new entries read from the incoming I/O stream are merged with the /// existing dictioinary. If the string has already been assigned a code, /// the existing code will be used. If the given code has been used for /// another string, the incoming string will be assined a new code. /// Warning messages will be printed to the logging channel when such a /// conflict is encountered. int ibis::dictionary::fromASCII(std::istream &in) { ibis::fileManager::buffer<char> linebuf(MAX_LINE); if (! in) { LOGGER(ibis::gVerbose > 0) << "Warning -- dictionary::fromASCII can not proceed because " "the input I/O stream is in an error state"; return -1; } int ierr; const char *str; bool more = true; const char *delim = ":,; \t\v"; while (more) { std::streampos linestart = in.tellg(); // read the next line while (! in.getline(linebuf.address(), linebuf.size())) { if (in.eof()) { // end of file, no more to read *(linebuf.address()) = 0; more = false; break; } // more to read, linebuf needs to be increased const size_t nold = (linebuf.size() > 0 ? linebuf.size() : MAX_LINE); if (nold+nold != linebuf.resize(nold+nold)) { LOGGER(ibis::gVerbose > 0) << "Warning -- dictionary::fromASCII failed to allocate " "linebuf of " << nold+nold << " bytes"; more = false; return -2; } in.clear(); // clear the error bit // go back to the beginning of the line if (! in.seekg(linestart, std::ios::beg)) { LOGGER(ibis::gVerbose > 0) << "Warning -- dictionary::fromASCII failed to seek back " "to the beginning of a line of text"; *(linebuf.address()) = 0; more = false; return -3; } } // got a line of text str = linebuf.address(); if (str == 0) break; while (*str != 0 && isspace(*str)) ++ str; // skip leading space if (*str == 0 || *str == '#' || (*str == '-' && str[1] == '-')) { // skip comment line (shell style comment and SQL style comments) continue; } uint64_t posi; ierr = ibis::util::readUInt(posi, str, delim); if (ierr < 0) { LOGGER(ibis::gVerbose > 3) << "Warning -- dictionary::fromASCII could not extract a " "number from \"" << linebuf.address() << '"'; posi = 0; } str += strspn(str, delim); // skip delimiters if (posi > 0 && posi < 0X7FFFFFFF) { insert(ibis::util::getString(str), static_cast<uint32_t>(posi)); } else { LOGGER(ibis::gVerbose > 3 && posi > 0) << "Warning -- dictionary::fromASCII can not use a code (" << posi << ") that is larger than 2^31"; insert(ibis::util::getString(str)); } } // while (more) return 0; } // ibis::dictionary::fromASCII