Made heightmap path configurable from level.
This commit is contained in:
parent
7e0394df00
commit
370135fca8
@ -13208,6 +13208,7 @@
|
||||
</directionalLight>
|
||||
|
||||
<terrain>
|
||||
<heightmap>heightmapLvl1.png</heightmap>
|
||||
<texture>sand.png</texture>
|
||||
<ambientFactor>0.13</ambientFactor>
|
||||
<diffuseFactor>0.8</diffuseFactor>
|
||||
|
@ -19,13 +19,11 @@ void Application::init()
|
||||
graphics.renderLoadingScreen();
|
||||
// init random generator
|
||||
std::srand(std::time(NULL));
|
||||
// choose Level TODO: Choose this in a menu
|
||||
}
|
||||
|
||||
void Application::initLevel() {
|
||||
std::string heightmapFilePath = heightmapPath + "heightmapLvl1.png";
|
||||
std::string levelXmlFilePath = levelXmlPath + "Level1.xml";
|
||||
this->level = Level(heightmapFilePath, levelXmlFilePath);
|
||||
this->level = Level(levelXmlFilePath);
|
||||
level.getPhysics()->init(geometryPath);
|
||||
// Don't change this!
|
||||
ignoredMouseUpdates = 0;
|
||||
@ -38,7 +36,7 @@ void Application::initLevel() {
|
||||
level.load();
|
||||
Loader loader = Loader();
|
||||
|
||||
loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath, geometryPath, texturePath);
|
||||
loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath, geometryPath, texturePath, heightmapPath);
|
||||
graphics.init(&level);
|
||||
|
||||
// just in case: check for errors
|
||||
|
@ -2,8 +2,7 @@
|
||||
#include "loader.hh"
|
||||
#include <string>
|
||||
|
||||
Level::Level(std::string heightmapFilePath, std::string xmlFilePath){
|
||||
this->terrain = Terrain(heightmapFilePath);
|
||||
Level::Level(std::string xmlFilePath){
|
||||
// default value
|
||||
skydomeSize = 50.0f;
|
||||
physics = Physics();
|
||||
@ -341,3 +340,7 @@ void Level::activateEndgame(){
|
||||
void Level::setWaterPlane(Object* water) {
|
||||
this->waterPlane = water;
|
||||
}
|
||||
|
||||
void Level::setTerrain(Terrain terrain) {
|
||||
this->terrain = terrain;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ extern "C" {
|
||||
|
||||
class Level {
|
||||
public:
|
||||
Level(std::string heightmapFilePath, std::string xmlFilePath);
|
||||
Level(std::string xmlFilePath);
|
||||
Level();
|
||||
~Level();
|
||||
void load();
|
||||
@ -73,6 +73,7 @@ class Level {
|
||||
void setPlayerIndex(int index);
|
||||
void forceMove(float x, float y, float z, unsigned indice);
|
||||
void activateEndgame();
|
||||
void setTerrain(Terrain terrain);
|
||||
private:
|
||||
lua_State* luaState=nullptr;
|
||||
std::vector<Object*> objects;
|
||||
|
@ -52,7 +52,9 @@ void Loader::loadConfig(Application* application) {
|
||||
}
|
||||
}
|
||||
|
||||
void Loader::load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath, std::string globalGeometryPath, std::string globalTexturePath) {
|
||||
void Loader::load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath,
|
||||
std::string globalGeometryPath, std::string globalTexturePath, std::string heightmapPath) {
|
||||
struct stat buf;
|
||||
//Loading from xml:
|
||||
XMLDocument* doc = new XMLDocument();
|
||||
const char* xmlFile = filePath.c_str();
|
||||
@ -68,15 +70,22 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
||||
level->setStrength(strength);
|
||||
|
||||
// load the terrain
|
||||
XMLElement* terrainElement = doc->FirstChildElement("terrain");
|
||||
std::string levelHeightmapPath = heightmapPath + queryString(terrainElement, "heightmap");
|
||||
if(stat(levelHeightmapPath.c_str(), &buf) != 0){
|
||||
std::cout << "The heightmap file " << levelHeightmapPath << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
Terrain terrain = Terrain(levelHeightmapPath);
|
||||
level->setTerrain(terrain);
|
||||
// Because object gets copied a lot load it when it has reached it's final destination
|
||||
level->getTerrain()->load();
|
||||
Model terrainModel = Model(level->getTerrain()->getModel());
|
||||
XMLElement* terrainElement = doc->FirstChildElement("terrain");
|
||||
std::string terrainTexture = queryString(terrainElement, "texture");
|
||||
float terrainAmbientFactor = queryFloat(terrainElement, "ambientFactor");
|
||||
float terrainDiffuseFactor = queryFloat(terrainElement, "diffuseFactor");
|
||||
float terrainSpecularFactor = queryFloat(terrainElement, "specularFactor");
|
||||
float terrainShininess = queryFloat(terrainElement, "shininess");
|
||||
struct stat buf;
|
||||
std::string terrainTexturePath = "../" + globalTexturePath + terrainTexture;
|
||||
if(stat(terrainTexturePath.c_str(), &buf) != 0){
|
||||
std::cout << "The texture file " << terrainTexturePath << " does not exist." << std::endl;
|
||||
|
@ -10,7 +10,9 @@ class Loader {
|
||||
public:
|
||||
Loader();
|
||||
void loadConfig(Application* application);
|
||||
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath, std::string geometryPath, std::string texturePath);
|
||||
void load(std::string filePath, Level* level, std::string compositionsPath,
|
||||
std::string scriptPath, std::string geometryPath, std::string texturePath,
|
||||
std::string heightmapPath);
|
||||
glm::vec3 reloadPlayerPosition(std::string filePath, Level* level);
|
||||
private:
|
||||
float queryFloat(XMLElement* element, const char* attribute);
|
||||
|
Loading…
Reference in New Issue
Block a user