diff --git a/map.cpp b/map.cpp index b8dc108..b119597 100755 --- a/map.cpp +++ b/map.cpp @@ -40,14 +40,14 @@ namespace battleship{ void Map::loadSkybox(LuaManager *luaManager){ int numPaths = 6; - string table = "skybox", basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; + string skyTable = "skybox", basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; string path[] = { - basePath + luaManager->getStringFromTable(table, vector{Index("left", true)}), - basePath + luaManager->getStringFromTable(table, vector{Index("right", true)}), - basePath + luaManager->getStringFromTable(table, vector{Index("up", true)}), - basePath + luaManager->getStringFromTable(table, vector{Index("down", true)}), - basePath + luaManager->getStringFromTable(table, vector{Index("front", true)}), - basePath + luaManager->getStringFromTable(table, vector{Index("back", true)}) + basePath + luaManager->getStringFromTable(terrTable, vector{Index(skyTable), Index("left")}), + basePath + luaManager->getStringFromTable(terrTable, vector{Index(skyTable), Index("right")}), + basePath + luaManager->getStringFromTable(terrTable, vector{Index(skyTable), Index("up")}), + basePath + luaManager->getStringFromTable(terrTable, vector{Index(skyTable), Index("down")}), + basePath + luaManager->getStringFromTable(terrTable, vector{Index(skyTable), Index("front")}), + basePath + luaManager->getStringFromTable(terrTable, vector{Index(skyTable), Index("back")}) }; for(int i = 0; i < numPaths; i++) @@ -57,8 +57,15 @@ namespace battleship{ } void Map::loadTerrain(LuaManager *luaManager){ - string terrainFile = luaManager->getString("model"); - string albedoFile = luaManager->getString("albedoMap"); + string terrainFile = luaManager->getStringFromTable(terrTable, vector{Index("model")}); + string albedoFile = luaManager->getStringFromTable(terrTable, vector{Index("albedoMap")}); + + string table = "size"; + size = Vector3( + luaManager->getFloatFromTable(terrTable, vector{Index(table), Index("x")}), + luaManager->getFloatFromTable(terrTable, vector{Index(table), Index("y")}), + luaManager->getFloatFromTable(terrTable, vector{Index(table), Index("z")}) + ); AssetManager *assetManager = AssetManager::getSingleton(); string basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; @@ -81,34 +88,33 @@ namespace battleship{ } void Map::loadWaterbodies(LuaManager *luaManager){ - //TODO : replace the magic value - int numWaterBodies = 1; + int numWaterBodies = luaManager->getIntFromTable(terrTable, vector{Index("numWaterBodies")}); string table = "waterBodies"; Root *root = Root::getSingleton(); - for(int i = 0; i < numWaterBodies; i++){ - float sizeX = luaManager->getFloatFromTable(table, vector{Index("sizeX", true)}); - float sizeY = luaManager->getFloatFromTable(table, vector{Index("sizeY", true)}); + for(int i = 1; i <= numWaterBodies; i++){ + float sizeX = luaManager->getFloatFromTable(terrTable, vector{Index(table), Index(i), Index("sizeX")}); + float sizeY = luaManager->getFloatFromTable(terrTable, vector{Index(table), Index(i), Index("sizeY")}); Quad *quad = new Quad(Vector3(sizeX, sizeY, 1) * 1, true); Material *mat = new Material(root->getLibPath() + "texture"); mat->addBoolUniform("texturingEnabled", false); mat->addVec4Uniform("diffuseColor", Vector4(0, 0, 1, 0.5)); mat->addBoolUniform("lightingEnabled", false); - string fr[]{GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + luaManager->getStringFromTable(table, vector{Index("albedoMap", true)})}; + string fr[]{GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + luaManager->getStringFromTable(terrTable, vector{Index(table), Index(i), Index("albedoMap")})}; AssetManager::getSingleton()->load(fr[0]); Texture *t = new Texture(fr, 1, false); mat->addTexUniform("textures[0]", t, true); quad->setMaterial(mat); - bool rect = luaManager->getBoolFromTable(table, vector{Index("rect", true)}); + bool rect = luaManager->getBoolFromTable(terrTable, vector{Index(table), Index("rect")}); Node *waterNode = new Node(); waterNode->attachMesh(quad); root->getRootNode()->attachChild(waterNode); - float posX = luaManager->getFloatFromTable(table, vector{Index("posX", true)}); - float posY = luaManager->getFloatFromTable(table, vector{Index("posY", true)}); - float posZ = luaManager->getFloatFromTable(table, vector{Index("posZ", true)}); + float posX = luaManager->getFloatFromTable(terrTable, vector{Index(table), Index(i), Index("posX")}); + float posY = luaManager->getFloatFromTable(terrTable, vector{Index(table), Index(i), Index("posY")}); + float posZ = luaManager->getFloatFromTable(terrTable, vector{Index(table), Index(i), Index("posZ")}); waterNode->setPosition(Vector3(posX, posY, posZ)); waterNode->setOrientation(Quaternion(-1.57, Vector3::VEC_I)); nodeParent->attachChild(waterNode); @@ -139,10 +145,6 @@ namespace battleship{ Camera *cam = root->getCamera(); cam->setPosition(Vector3(1, 1, 1) * 40); cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); - - //TODO replace hardcoded values - size = Vector3(100, 33, 100); - bottom = 33; } void Map::unload() {} diff --git a/map.h b/map.h index 800349d..c368b6e 100755 --- a/map.h +++ b/map.h @@ -40,14 +40,13 @@ namespace battleship{ inline vb01::Model* getTerrainModel(){return terrainModel;} inline vb01::Node* getNodeParent(){return nodeParent;} inline vb01::Vector3 getSize(){return size;} - inline float getBottom(){return bottom;} private: + std::string terrTable = "terrain"; vb01::Node *nodeParent = nullptr; vb01::Model *terrainModel = nullptr; std::string mapName; std::vector waterBodies; vb01::Vector3 size; - float bottom; Map(){} void loadSkybox(gameBase::LuaManager*); diff --git a/unitDataManager.cpp b/unitDataManager.cpp index 9c8da61..373e699 100644 --- a/unitDataManager.cpp +++ b/unitDataManager.cpp @@ -45,33 +45,33 @@ namespace battleship{ unitCuboidDimensions = new Vector3*[numUnits]; for(int i = 0; i < numUnits; i++){ - health[i] = luaManager->getIntFromTable("health", vector{Index(to_string(i + 1), false)}); - speed[i] = luaManager->getFloatFromTable("speed", vector{Index(to_string(i + 1), false)}); - unitClass[i] = (UnitClass)luaManager->getIntFromTable("unitClass", vector{Index(to_string(i + 1), false)}); - destinationOffset[i] = luaManager->getFloatFromTable("destinationOffset", vector{Index(to_string(i + 1), false)}); - unitType[i] = (UnitType)luaManager->getIntFromTable("unitType", vector{Index(to_string(i + 1), false)}); - anglePrecision[i] = luaManager->getFloatFromTable("anglePrecision", vector{Index(to_string(i + 1), false)}); - cost[i] = luaManager->getIntFromTable("cost", vector{Index(to_string(i + 1), false)}); - maxTurnAngle[i] = luaManager->getFloatFromTable("maxTurnAngle", vector{Index(to_string(i + 1), false)}); - range[i] = luaManager->getFloatFromTable("range", vector{Index(to_string(i + 1), false)}); - unitAxisLength[i] = luaManager->getFloatFromTable("unitAxisLength", vector{Index(to_string(i + 1), false)}); - lineOfSight[i] = luaManager->getFloatFromTable("lineOfSight", vector{Index(to_string(i + 1), false)}); - name[i] = luaManager->getStringFromTable("name", vector{Index(to_string(i + 1), false)}); - meshPath[i] = luaManager->getStringFromTable("meshPath", vector{Index(to_string(i + 1), false)}); - basePath[i] = luaManager->getStringFromTable("basePath", vector{Index(to_string(i + 1), false)}); + health[i] = luaManager->getIntFromTable("health", vector{Index(i + 1)}); + speed[i] = luaManager->getFloatFromTable("speed", vector{Index(i + 1)}); + unitClass[i] = (UnitClass)luaManager->getIntFromTable("unitClass", vector{Index(i + 1)}); + destinationOffset[i] = luaManager->getFloatFromTable("destinationOffset", vector{Index(i + 1)}); + unitType[i] = (UnitType)luaManager->getIntFromTable("unitType", vector{Index(i + 1)}); + anglePrecision[i] = luaManager->getFloatFromTable("anglePrecision", vector{Index(i + 1)}); + cost[i] = luaManager->getIntFromTable("cost", vector{Index(i + 1)}); + maxTurnAngle[i] = luaManager->getFloatFromTable("maxTurnAngle", vector{Index(i + 1)}); + range[i] = luaManager->getFloatFromTable("range", vector{Index(i + 1)}); + unitAxisLength[i] = luaManager->getFloatFromTable("unitAxisLength", vector{Index(i + 1)}); + lineOfSight[i] = luaManager->getFloatFromTable("lineOfSight", vector{Index(i + 1)}); + name[i] = luaManager->getStringFromTable("name", vector{Index(i + 1)}); + meshPath[i] = luaManager->getStringFromTable("meshPath", vector{Index(i + 1)}); + basePath[i] = luaManager->getStringFromTable("basePath", vector{Index(i + 1)}); unitCornerPoints[i] = new Vector3[8]; unitCuboidDimensions[i] = new Vector3[8]; for(int j = 0; j < 8; j++){ - float cornerX = luaManager->getFloatFromTable("unitCornerPoints", vector{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("x", true)}); - float cornerY = luaManager->getFloatFromTable("unitCornerPoints", vector{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("y", true)}); - float cornerZ = luaManager->getFloatFromTable("unitCornerPoints", vector{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("z", true)}); + float cornerX = luaManager->getFloatFromTable("unitCornerPoints", vector{Index(i + 1), Index(j + 1), Index("x")}); + float cornerY = luaManager->getFloatFromTable("unitCornerPoints", vector{Index(i + 1), Index(j + 1), Index("y")}); + float cornerZ = luaManager->getFloatFromTable("unitCornerPoints", vector{Index(i + 1), Index(j + 1), Index("z")}); unitCornerPoints[i][j] = Vector3(cornerX, cornerY, cornerZ); - float dimX = luaManager->getFloatFromTable("unitCuboidDimensions", vector{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("x", true)}); - float dimY = luaManager->getFloatFromTable("unitCuboidDimensions", vector{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("y", true)}); - float dimZ = luaManager->getFloatFromTable("unitCuboidDimensions", vector{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("z", true)}); + float dimX = luaManager->getFloatFromTable("unitCuboidDimensions", vector{Index(i + 1), Index(j + 1), Index("x")}); + float dimY = luaManager->getFloatFromTable("unitCuboidDimensions", vector{Index(i + 1), Index(j + 1), Index("y")}); + float dimZ = luaManager->getFloatFromTable("unitCuboidDimensions", vector{Index(i + 1), Index(j + 1), Index("z")}); unitCuboidDimensions[i][j] = Vector3(dimX, dimY, dimZ); } }