コード例 #1
0
ファイル: TerrainParser.cpp プロジェクト: Arsakes/ember
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;

}
コード例 #2
0
void TerrainShaderParser::createShaders(const Atlas::Message::Element& surfaces)
{
  Terrain::TerrainLayerDefinitionManager& terrainManager = Terrain::TerrainLayerDefinitionManager::getSingleton();
  bool isValid = false;
  if (surfaces.isList()) {
    const Atlas::Message::ListType & slist(surfaces.asList());
    for (Atlas::Message::ListType::const_iterator I = slist.begin(); I != slist.end(); ++I) {
      if (I->isMap()) {
        std::string name;
        std::string pattern;
        const Atlas::Message::MapType& surfaceMap(I->asMap());

        Mercator::Shader::Parameters params;
        if (surfaceMap.count("params")) {
          const Atlas::Message::Element& paramsElem(surfaceMap.find("params")->second);
          if (paramsElem.isMap()) {
            for (Atlas::Message::MapType::const_iterator J = paramsElem.asMap().begin(); J != paramsElem.asMap().end(); ++J) {
              if (J->second.isNum()) {
                params[J->first] = J->second.asNum();
              }
            }
          }
        }

        if (surfaceMap.count("name")) {
          const Atlas::Message::Element& nameElem(surfaceMap.find("name")->second);
          if (nameElem.isString()) {
            const std::string& name = nameElem.asString();
            Terrain::TerrainLayerDefinition* def(terrainManager.getDefinitionForShader(name));
            if (def) {
              if (surfaceMap.count("pattern")) {
                const Atlas::Message::Element& patternElem(surfaceMap.find("pattern")->second);
                if (patternElem.isString()) {
                  const std::string& pattern = patternElem.asString();
                  Mercator::Shader* shader = Mercator::ShaderFactories::instance().newShader(pattern, params);
                  if (shader) {
                    isValid = true;
                    mTerrainHandler.createShader(def, shader);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if (!isValid) {
    createDefaultShaders();
  }
}
コード例 #3
0
ファイル: EmberEntity.cpp プロジェクト: Laefy/ember
std::vector<std::string> EmberEntity::getActions()
{
	//get the actions from Eris and return them a simple vector of strings
	std::vector<std::string> actions;

	if (hasAttr("actions")) {
		const Atlas::Message::Element& operations = valueOfAttr("actions");
		if (operations.isList()) {
			const Atlas::Message::ListType& list = operations.asList();
			actions.reserve(list.size());
			Atlas::Message::ListType::const_iterator J = list.begin();
			for (; J != list.end(); ++J) {
				if (J->isString()) {
					actions.push_back(J->asString());
				}
			}
		}
	}

	return actions;
}
コード例 #4
0
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);
  }
}