TerrainDefPointStore TerrainParser::parseTerrain(const Atlas::Message::Element& terrain, const WFMath::Point<3>& offset) const { //_fpreset(); if (!terrain.isMap()) { S_LOG_FAILURE("Terrain is not a map"); } const Atlas::Message::MapType & tmap = terrain.asMap(); Atlas::Message::MapType::const_iterator I = tmap.find("points"); if (I == tmap.end()) { S_LOG_FAILURE("No terrain points"); } Terrain::TerrainDefPointStore pointStore; if (I->second.isList()) { // Legacy support for old list format. const Atlas::Message::ListType& plist = I->second.asList(); Atlas::Message::ListType::const_iterator J = plist.begin(); for (; J != plist.end(); ++J) { if (!J->isList()) { S_LOG_INFO("Non list in points"); continue; } const Atlas::Message::ListType & point = J->asList(); if (point.size() != 3) { S_LOG_INFO("Point without 3 nums."); continue; } Terrain::TerrainDefPoint defPoint(static_cast<int> (point[0].asNum() + offset.x()), static_cast<int> (point[1].asNum() + offset.y()), static_cast<float> (point[3].asNum() + offset.z())); pointStore.push_back(defPoint); } } else if (I->second.isMap()) { const Atlas::Message::MapType& plist = I->second.asMap(); Atlas::Message::MapType::const_iterator J = plist.begin(); for (; J != plist.end(); ++J) { if (!J->second.isList()) { S_LOG_INFO("Non list in points."); continue; } const Atlas::Message::ListType & point = J->second.asList(); if (point.size() != 3) { S_LOG_INFO("Point without 3 nums."); continue; } int x = static_cast<int> (point[0].asNum()); int y = static_cast<int> (point[1].asNum()); float z = point[2].asNum(); Terrain::TerrainDefPoint defPoint(x + offset.x(), y + offset.y(), z + offset.z()); pointStore.push_back(defPoint); } } else { S_LOG_FAILURE("Terrain is the wrong type"); } return pointStore; }
void TerrainEntity::updateTerrain() { if (!hasAttr("terrain")) { std::cerr << "Entity has no terrain" << std::endl << std::flush; std::cerr << "Entity id " << getId() << std::endl << std::flush; return; } const Atlas::Message::Element &terrain = valueOfAttr("terrain"); if (!terrain.isMap()) { std::cerr << "Terrain is not a map" << std::endl << std::flush; } const Atlas::Message::MapType & tmap = terrain.asMap(); Atlas::Message::MapType::const_iterator I = tmap.find("points"); int xmin = 0, xmax = 0, ymin = 0, ymax = 0; if (I == tmap.end()) { std::cerr << "No terrain points" << std::endl << std::flush; } else { if (I->second.isList()) { // Legacy support for old list format. const Atlas::Message::ListType & plist = I->second.asList(); Atlas::Message::ListType::const_iterator J = plist.begin(); Atlas::Message::ListType::const_iterator Jend = plist.end(); for(; J != Jend; ++J) { if (!J->isList()) { std::cout << "Non list in points" << std::endl << std::flush; continue; } const Atlas::Message::ListType & point = J->asList(); if (point.size() != 3) { std::cout << "point without 3 nums" << std::endl << std::flush; continue; } int x = (int)point[0].asNum(); int y = (int)point[1].asNum(); xmin = std::min(xmin, x); xmax = std::max(xmax, x); ymin = std::min(ymin, y); ymax = std::max(ymax, y); Environment::getInstance().setBasePoint(x,y,point[2].asNum()); } } else if (I->second.isMap()) { const Atlas::Message::MapType & plist = I->second.asMap(); Atlas::Message::MapType::const_iterator J = plist.begin(); Atlas::Message::MapType::const_iterator Jend = plist.end(); for(; J != Jend; ++J) { if (!J->second.isList()) { std::cout << "Non list in points" << std::endl << std::flush; continue; } const Atlas::Message::ListType & point = J->second.asList(); if (point.size() != 3) { std::cout << "point without 3 nums" << std::endl << std::flush; continue; } int x = (int)point[0].asNum(); int y = (int)point[1].asNum(); xmin = std::min(xmin, x); xmax = std::max(xmax, x); ymin = std::min(ymin, y); ymax = std::max(ymax, y); Environment::getInstance().setBasePoint(x,y,point[2].asNum()); } } else { std::cerr << "Terrain is the wrong type" << std::endl << std::flush; } } // Read surfaces data Atlas::Message::MapType::const_iterator J = tmap.find("surfaces"); if (J == tmap.end()) { std::cerr << "Terrain surfaces does not exist" << std::endl; return; } if (J->second.isList() == false) { std::cerr << "Terrain surfaces is not a list" << std::endl; return; } const Atlas::Message::ListType & plist = J->second.asList(); Atlas::Message::ListType::const_iterator K = plist.begin(); Atlas::Message::ListType::const_iterator Kend = plist.end(); for(; K != Kend; ++K) { if (!(*K).isMap()) { std::cerr << "Surfaces entry is not a map" << std::endl; continue; } const Atlas::Message::MapType &L = K->asMap(); Atlas::Message::MapType::const_iterator name_itr = L.find("name"); Atlas::Message::MapType::const_iterator pattern_itr = L.find("pattern"); Atlas::Message::MapType::const_iterator params_itr = L.find("params"); if (name_itr == L.end() || pattern_itr == L.end()) { std::cerr << "Required params not here" << std::endl; continue; } const std::string &name = name_itr->second.asString(); const std::string &pattern = pattern_itr->second.asString(); printf("Name: %s - Pattern %s\n", name.c_str(), pattern.c_str()); Mercator::Shader::Parameters params; if (params_itr != L.end()) { const Atlas::Message::MapType & mlist = params_itr->second.asMap(); Atlas::Message::MapType::const_iterator M = mlist.begin(); Atlas::Message::MapType::const_iterator Mend = mlist.end(); for(; M != Mend; ++M) { // TODO: Check type first params[M->first] = M->second.asNum(); } } Environment::getInstance().setSurface(name, pattern, params); } }