bool LoaderIDE::load(const std::string &filename) { std::ifstream str(filename); if ( ! str.is_open()) return false; SectionTypes section = NONE; while( ! str.eof()) { std::string line; getline(str, line); line.erase(std::find_if(line.rbegin(), line.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), line.end()); if ( ! line.empty() && line[0] == '#') continue; if (line == "end") { section = NONE; } else if(section == NONE) { if (line == "objs") { section = OBJS; } else if (line == "tobj") { section = TOBJ; } else if (line == "peds") { section = PEDS; } else if (line == "cars") { section = CARS; } else if (line == "hier") { section = HIER; } else if (line == "2dfx") { section = TWODFX; } else if (line == "path") { section = PATH; } } else { // Remove ALL the whitespace!! line.erase(remove_if(line.begin(), line.end(), isspace), line.end()); std::stringstream strstream(line); switch (section) { default: break; case OBJS: case TOBJ: { // Supports Type 1, 2 and 3 std::shared_ptr<ObjectData> objs(new ObjectData); std::string id, numClumps, flags, modelName, textureName; // Read the content of the line getline(strstream, id, ','); getline(strstream, modelName, ','); getline(strstream, textureName, ','); getline(strstream, numClumps, ','); objs->numClumps = atoi(numClumps.c_str()); for (size_t i = 0; i < objs->numClumps; i++) { std::string drawDistance; getline(strstream, drawDistance, ','); objs->drawDistance[i] = atoi(drawDistance.c_str()); } getline(strstream, flags, ','); // Keep reading TOBJ data if(section == LoaderIDE::TOBJ) { std::string buff; getline(strstream, buff, ','); objs->timeOn = atoi(buff.c_str()); getline(strstream, buff, ','); objs->timeOff = atoi(buff.c_str()); } else { objs->timeOff = objs->timeOn = 0; } // Put stuff in our struct objs->ID = atoi(id.c_str()); objs->flags = atoi(flags.c_str()); objs->modelName = modelName; objs->textureName = textureName; objs->LOD = false; if(modelName.find("LOD", 0,3) != modelName.npos && modelName != "LODistancoast01") { objs->LOD = true; } objects.insert({objs->ID, objs}); break; } case CARS: { std::shared_ptr<VehicleData> cars(new VehicleData); std::string id, type, classType, frequency, lvl, comprules, wheelModelID, wheelScale; getline(strstream, id, ','); getline(strstream, cars->modelName, ','); getline(strstream, cars->textureName, ','); getline(strstream, type, ','); getline(strstream, cars->handlingID, ','); getline(strstream, cars->gameName, ','); getline(strstream, classType, ','); getline(strstream, frequency, ','); getline(strstream, lvl, ','); getline(strstream, comprules, ','); getline(strstream, wheelModelID, ','); getline(strstream, wheelScale, ','); cars->ID = atoi(id.c_str()); cars->frequency = atoi(frequency.c_str()); cars->lvl = atoi(lvl.c_str()); cars->comprules = atoi(comprules.c_str()); if (type == "car") { cars->type = VehicleData::CAR; cars->wheelModelID = atoi(wheelModelID.c_str()); cars->wheelScale = atof(wheelScale.c_str()); } else if (type == "boat") { cars->type = VehicleData::BOAT; } else if (type == "train") { cars->type = VehicleData::TRAIN; cars->modelLOD = atoi(wheelModelID.c_str()); } else if (type == "plane") { cars->type = VehicleData::PLANE; } else if (type == "heli") { cars->type = VehicleData::HELI; } const std::map<VehicleData::VehicleClass, std::string> classTypes{ {VehicleData::IGNORE, "ignore"}, {VehicleData::NORMAL, "normal"}, {VehicleData::POORFAMILY, "poorfamily"}, {VehicleData::RICHFAMILY, "richfamily"}, {VehicleData::EXECUTIVE, "executive"}, {VehicleData::WORKER, "worker"}, {VehicleData::BIG, "big"}, {VehicleData::TAXI, "taxi"}, {VehicleData::MOPED, "moped"}, {VehicleData::MOTORBIKE, "motorbike"}, {VehicleData::LEISUREBOAT, "leisureboat"}, {VehicleData::WORKERBOAT, "workerboat"}, {VehicleData::BICYCLE, "bicycle"}, {VehicleData::ONFOOT, "onfoot"}, }; for (auto &a : classTypes) { if (classType == a.second) { cars->classType = a.first; break; } } objects.insert({cars->ID, cars}); break; } case PEDS: { std::shared_ptr<CharacterData> peds(new CharacterData); std::string id, driveMask; getline(strstream, id, ','); getline(strstream, peds->modelName, ','); getline(strstream, peds->textureName, ','); getline(strstream, peds->type, ','); getline(strstream, peds->behaviour, ','); getline(strstream, peds->animGroup, ','); getline(strstream, driveMask, ','); peds->ID = atoi(id.c_str()); peds->driveMask = atoi(driveMask.c_str()); objects.insert({peds->ID, peds}); break; } case PATH: { PathData path; std::string type; getline(strstream, type, ','); if( type == "ped" ) { path.type = PathData::PATH_PED; } else if( type == "car") { path.type = PathData::PATH_CAR; } std::string id; getline(strstream, id, ','); path.ID = atoi(id.c_str()); getline(strstream, path.modelName); std::string linebuff, buff; for( size_t p = 0; p < 12; ++p ) { PathNode node; getline(str, linebuff); std::stringstream buffstream(linebuff); getline(buffstream, buff, ','); switch(atoi(buff.c_str())) { case 0: node.type = PathNode::EMPTY; break; case 2: node.type = PathNode::INTERNAL; break; case 1: node.type = PathNode::EXTERNAL; break; } if( node.type == PathNode::EMPTY ) { continue; } getline(buffstream, buff, ','); node.next = atoi(buff.c_str()); getline(buffstream, buff, ','); // "Always 0" getline(buffstream, buff, ','); node.position.x = atof(buff.c_str()) * 1/16.f; getline(buffstream, buff, ','); node.position.y = atof(buff.c_str()) * 1/16.f; getline(buffstream, buff, ','); node.position.z = atof(buff.c_str()) * 1/16.f; getline(buffstream, buff, ','); node.size = atof(buff.c_str()) * 1/16.f; getline(buffstream, buff, ','); node.other_thing = atoi(buff.c_str()); getline(buffstream, buff, ','); node.other_thing2 = atoi(buff.c_str()); path.nodes.push_back(node); } auto& object = objects[path.ID]; auto instance = std::dynamic_pointer_cast<ObjectData>(object); instance->paths.push_back(path); break; } case HIER: { std::shared_ptr<CutsceneObjectData> cut(new CutsceneObjectData); std::string id; getline(strstream, id, ','); getline(strstream, cut->modelName, ','); getline(strstream, cut->textureName, ','); cut->ID = atoi(id.c_str()); objects.insert({cut->ID, cut}); break; } } } } return true; }
int main(int csize, char** cline ) { seal::PluginManager::get()->initialise(); seal::TimingReport timRep; try { // Loads the seal message stream LockMutex::Mutex mutex; pool::POOLContext::loadComponent( "SEAL/Services/MessageService" ); pool::POOLContext::loadComponent( "POOL/Services/EnvironmentAuthenticationService" ); pool::URIParser p; p.parse(); pool::IFileCatalog lcat; pool::IFileCatalog * cat = &lcat; cat->setWriteCatalog(p.contactstring()); cat->connect(); cat->start(); own_ptr<pool::IPersistencySvc> oriper; own_ptr<pool::IPersistencySvc> safeper; own_ptr<pool::IDataSvc> datasvc; // Persil::TCPGetter tcpGetter; Persil::TCPGetterFactory tcpGetter; pool::IPersistencySvcFactory* psfactory = pool::IPersistencySvcFactory::get(); oriper.reset(psfactory->create( "PersistencySvc", lcat )); safeper.reset(new StreamPersistencySvc(*oriper.get(), tcpGetter, mutex)); datasvc.reset(pool::DataSvcFactory::instance(safeper.get())); pool::IDataSvc *svc = datasvc.get(); Persil::currentCache() = &svc->cacheSvc(); svc->transaction().start(pool::ITransaction::READ); if (csize==2) { // peds std::string iovToken(cline[1]); svc->transaction().start(pool::ITransaction::READ); pool::Ref<CalibTests::IOV> iov(svc,iovToken); std::cout << "first iov " << (*iov->iov.begin()).first << " " << (*iov->iov.begin()).second << std::endl; std::cout << "last iov " << (*iov->iov.rbegin()).first << " " << (*iov->iov.rbegin()).second << std::endl; for (int t=253; t<290; t+=15) { std::cout << "at time " << t << " used " << (*iov->iov.lower_bound(t)).first << std::endl; std::string pedCid = (*iov->iov.lower_bound(t)).second; std::cout << "ped Cid " << pedCid << std::endl; pool::Ref<CalibTests::SimplePedestals> peds(svc,pedCid); std::cout << "peds size " << peds->m_pedestals.size() << std::endl; int l=2000; int le=2050; std::cout << "peds from " << l; for (CalibTests::SimplePedestals::ItemIterator p= peds->m_pedestals.begin()+l; p!= peds->m_pedestals.begin()+le;p++) std::cout << " " << (*p).m_mean << "," << (*p).m_variance; std::cout << std::endl; } /* std::string iovToken(cline[1]); pool::Ref<CalibTests::IOV> iov(svc,iovToken); std::string pedCid = (*iov->iov.lower_bound(253)).second; std::cout << "ped Cid " << pedCid << std::endl; pool::Ref<CalibTests::Pedestals> peds(svc,pedCid); int l=2000; CalibTests::Pedestals::ItemRange r=peds->get(l); std::cout << "peds from " << l; for (CalibTests::Pedestals::ItemIterator p=r.first; p!=r.second;p++) std::cout << " " << (*p).m_mean << "," << (*p).m_variance; std::cout << std::endl; */ } if (csize==3) { // align std::string iovAToken(cline[1]); std::string iovIToken(cline[2]); pool::Ref<CalibTests::IOV> iovA(svc,iovAToken); pool::Ref<CalibTests::IOV> iovI(svc,iovIToken); std::cout << "iov size " << iovA->iov.size() << std::endl; std::string alignCid = (*iovA->iov.lower_bound(25)).second; std::string indexCid = (*iovI->iov.lower_bound(25)).second; std::cout << "align Cid " << alignCid << std::endl; std::cout << "index Cid " << indexCid << std::endl; pool::Ref<Alignments> align(svc,alignCid); pool::Ref<Geom2Index> index(svc,indexCid); Geom2Index::GeomId id=500+20+7; std::cout << "align for " << id; int i= index->m_indexTable[id]; std::cout << " " << (*align).m_align[i].translation() << "," << (*align).m_align[i].eulerAngles(); std::cout << std::endl; } svc->transaction().commit(); svc->session().disconnectAll(); std::cout << "committed" << std::endl; std::cout << "commit catalog" << std::endl; cat->commit(); } catch ( seal::Exception& e ) { std::cout << "seal error " << e.what() << std::endl; return 1; } catch ( std::exception& e ) { std::cout << "std error " << e.what() << std::endl; return 1; } catch ( ... ) { std::cout << "Funny error" << std::endl; return 1; } return 0; }