updated Lua script data extraction invocations

This commit is contained in:
devZoGok
2022-09-24 09:43:08 +03:00
parent 900cd0e8c8
commit 678923390b
3 changed files with 46 additions and 45 deletions
+25 -23
View File
@@ -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>{Index("left", true)}),
basePath + luaManager->getStringFromTable(table, vector<Index>{Index("right", true)}),
basePath + luaManager->getStringFromTable(table, vector<Index>{Index("up", true)}),
basePath + luaManager->getStringFromTable(table, vector<Index>{Index("down", true)}),
basePath + luaManager->getStringFromTable(table, vector<Index>{Index("front", true)}),
basePath + luaManager->getStringFromTable(table, vector<Index>{Index("back", true)})
basePath + luaManager->getStringFromTable(terrTable, vector<Index>{Index(skyTable), Index("left")}),
basePath + luaManager->getStringFromTable(terrTable, vector<Index>{Index(skyTable), Index("right")}),
basePath + luaManager->getStringFromTable(terrTable, vector<Index>{Index(skyTable), Index("up")}),
basePath + luaManager->getStringFromTable(terrTable, vector<Index>{Index(skyTable), Index("down")}),
basePath + luaManager->getStringFromTable(terrTable, vector<Index>{Index(skyTable), Index("front")}),
basePath + luaManager->getStringFromTable(terrTable, vector<Index>{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>{Index("model")});
string albedoFile = luaManager->getStringFromTable(terrTable, vector<Index>{Index("albedoMap")});
string table = "size";
size = Vector3(
luaManager->getFloatFromTable(terrTable, vector<Index>{Index(table), Index("x")}),
luaManager->getFloatFromTable(terrTable, vector<Index>{Index(table), Index("y")}),
luaManager->getFloatFromTable(terrTable, vector<Index>{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>{Index("numWaterBodies")});
string table = "waterBodies";
Root *root = Root::getSingleton();
for(int i = 0; i < numWaterBodies; i++){
float sizeX = luaManager->getFloatFromTable(table, vector<Index>{Index("sizeX", true)});
float sizeY = luaManager->getFloatFromTable(table, vector<Index>{Index("sizeY", true)});
for(int i = 1; i <= numWaterBodies; i++){
float sizeX = luaManager->getFloatFromTable(terrTable, vector<Index>{Index(table), Index(i), Index("sizeX")});
float sizeY = luaManager->getFloatFromTable(terrTable, vector<Index>{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>{Index("albedoMap", true)})};
string fr[]{GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + luaManager->getStringFromTable(terrTable, vector<Index>{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>{Index("rect", true)});
bool rect = luaManager->getBoolFromTable(terrTable, vector<Index>{Index(table), Index("rect")});
Node *waterNode = new Node();
waterNode->attachMesh(quad);
root->getRootNode()->attachChild(waterNode);
float posX = luaManager->getFloatFromTable(table, vector<Index>{Index("posX", true)});
float posY = luaManager->getFloatFromTable(table, vector<Index>{Index("posY", true)});
float posZ = luaManager->getFloatFromTable(table, vector<Index>{Index("posZ", true)});
float posX = luaManager->getFloatFromTable(terrTable, vector<Index>{Index(table), Index(i), Index("posX")});
float posY = luaManager->getFloatFromTable(terrTable, vector<Index>{Index(table), Index(i), Index("posY")});
float posZ = luaManager->getFloatFromTable(terrTable, vector<Index>{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() {}
+1 -2
View File
@@ -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<WaterBody> waterBodies;
vb01::Vector3 size;
float bottom;
Map(){}
void loadSkybox(gameBase::LuaManager*);
+20 -20
View File
@@ -45,33 +45,33 @@ namespace battleship{
unitCuboidDimensions = new Vector3*[numUnits];
for(int i = 0; i < numUnits; i++){
health[i] = luaManager->getIntFromTable("health", vector<Index>{Index(to_string(i + 1), false)});
speed[i] = luaManager->getFloatFromTable("speed", vector<Index>{Index(to_string(i + 1), false)});
unitClass[i] = (UnitClass)luaManager->getIntFromTable("unitClass", vector<Index>{Index(to_string(i + 1), false)});
destinationOffset[i] = luaManager->getFloatFromTable("destinationOffset", vector<Index>{Index(to_string(i + 1), false)});
unitType[i] = (UnitType)luaManager->getIntFromTable("unitType", vector<Index>{Index(to_string(i + 1), false)});
anglePrecision[i] = luaManager->getFloatFromTable("anglePrecision", vector<Index>{Index(to_string(i + 1), false)});
cost[i] = luaManager->getIntFromTable("cost", vector<Index>{Index(to_string(i + 1), false)});
maxTurnAngle[i] = luaManager->getFloatFromTable("maxTurnAngle", vector<Index>{Index(to_string(i + 1), false)});
range[i] = luaManager->getFloatFromTable("range", vector<Index>{Index(to_string(i + 1), false)});
unitAxisLength[i] = luaManager->getFloatFromTable("unitAxisLength", vector<Index>{Index(to_string(i + 1), false)});
lineOfSight[i] = luaManager->getFloatFromTable("lineOfSight", vector<Index>{Index(to_string(i + 1), false)});
name[i] = luaManager->getStringFromTable("name", vector<Index>{Index(to_string(i + 1), false)});
meshPath[i] = luaManager->getStringFromTable("meshPath", vector<Index>{Index(to_string(i + 1), false)});
basePath[i] = luaManager->getStringFromTable("basePath", vector<Index>{Index(to_string(i + 1), false)});
health[i] = luaManager->getIntFromTable("health", vector<Index>{Index(i + 1)});
speed[i] = luaManager->getFloatFromTable("speed", vector<Index>{Index(i + 1)});
unitClass[i] = (UnitClass)luaManager->getIntFromTable("unitClass", vector<Index>{Index(i + 1)});
destinationOffset[i] = luaManager->getFloatFromTable("destinationOffset", vector<Index>{Index(i + 1)});
unitType[i] = (UnitType)luaManager->getIntFromTable("unitType", vector<Index>{Index(i + 1)});
anglePrecision[i] = luaManager->getFloatFromTable("anglePrecision", vector<Index>{Index(i + 1)});
cost[i] = luaManager->getIntFromTable("cost", vector<Index>{Index(i + 1)});
maxTurnAngle[i] = luaManager->getFloatFromTable("maxTurnAngle", vector<Index>{Index(i + 1)});
range[i] = luaManager->getFloatFromTable("range", vector<Index>{Index(i + 1)});
unitAxisLength[i] = luaManager->getFloatFromTable("unitAxisLength", vector<Index>{Index(i + 1)});
lineOfSight[i] = luaManager->getFloatFromTable("lineOfSight", vector<Index>{Index(i + 1)});
name[i] = luaManager->getStringFromTable("name", vector<Index>{Index(i + 1)});
meshPath[i] = luaManager->getStringFromTable("meshPath", vector<Index>{Index(i + 1)});
basePath[i] = luaManager->getStringFromTable("basePath", vector<Index>{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>{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("x", true)});
float cornerY = luaManager->getFloatFromTable("unitCornerPoints", vector<Index>{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("y", true)});
float cornerZ = luaManager->getFloatFromTable("unitCornerPoints", vector<Index>{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("z", true)});
float cornerX = luaManager->getFloatFromTable("unitCornerPoints", vector<Index>{Index(i + 1), Index(j + 1), Index("x")});
float cornerY = luaManager->getFloatFromTable("unitCornerPoints", vector<Index>{Index(i + 1), Index(j + 1), Index("y")});
float cornerZ = luaManager->getFloatFromTable("unitCornerPoints", vector<Index>{Index(i + 1), Index(j + 1), Index("z")});
unitCornerPoints[i][j] = Vector3(cornerX, cornerY, cornerZ);
float dimX = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("x", true)});
float dimY = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("y", true)});
float dimZ = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(to_string(i + 1), false), Index(to_string(j + 1), false), Index("z", true)});
float dimX = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(i + 1), Index(j + 1), Index("x")});
float dimY = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(i + 1), Index(j + 1), Index("y")});
float dimZ = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(i + 1), Index(j + 1), Index("z")});
unitCuboidDimensions[i][j] = Vector3(dimX, dimY, dimZ);
}
}