mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
loading lights from map scripts
This commit is contained in:
@@ -87,6 +87,33 @@ namespace battleship{
|
||||
Root::getSingleton()->createSkybox(path);
|
||||
}
|
||||
|
||||
void Map::loadLights(){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
sol::table lightsTbl = SOL_LUA_VIEW[mapTable]["lights"];
|
||||
int numLights = lightsTbl.size();
|
||||
|
||||
for(int i = 0; i < numLights; i++){
|
||||
int id = i + 1;
|
||||
Light::Type type = (Light::Type)lightsTbl[id]["type"];
|
||||
sol::table colTbl = lightsTbl[id]["color"];
|
||||
|
||||
Light *light = new Light(type);
|
||||
light->setColor(Vector3(colTbl["x"], colTbl["y"], colTbl["z"]));
|
||||
|
||||
Node *lightNode = new Node();
|
||||
lightNode->addLight(light);
|
||||
lights.push_back(light);
|
||||
|
||||
if(type == Light::Type::DIRECTIONAL){
|
||||
sol::table dirTbl = lightsTbl[id]["dir"];
|
||||
Vector3 dir = Vector3(dirTbl["x"], dirTbl["y"], dirTbl["z"]).norm();
|
||||
lightNode->lookAt(dir);
|
||||
}
|
||||
|
||||
Root::getSingleton()->getRootNode()->attachChild(lightNode);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::loadTerrainObject(int id){
|
||||
string texPath = "", albedoPath = "";
|
||||
Quad *quad = nullptr;
|
||||
@@ -288,25 +315,24 @@ namespace battleship{
|
||||
|
||||
if(!empty){
|
||||
SOL_LUA_STATE.script_file(path + "Models/Maps/" + mapName + "/" + mapName + ".lua");
|
||||
sol::table sizeTable = SOL_LUA_STATE[mapTable]["size"];
|
||||
mapSize = Vector3(sizeTable["x"], sizeTable["y"], sizeTable["z"]);
|
||||
int numWaterbodies = SOL_LUA_STATE[mapTable]["numWaterBodies"];
|
||||
sol::optional<sol::table> lightsOpt = SOL_LUA_STATE[mapTable]["lights"];
|
||||
|
||||
if(lightsOpt != sol::nullopt)
|
||||
loadLights();
|
||||
|
||||
loadSpawnPoints();
|
||||
loadSkybox();
|
||||
loadCells();
|
||||
loadTerrainObject(-1);
|
||||
|
||||
sol::table sizeTable = SOL_LUA_STATE[mapTable]["size"];
|
||||
mapSize = Vector3(sizeTable["x"], sizeTable["y"], sizeTable["z"]);
|
||||
int numWaterbodies = SOL_LUA_STATE[mapTable]["numWaterBodies"];
|
||||
|
||||
for(int i = 0; i < numWaterbodies; i++)
|
||||
loadTerrainObject(i);
|
||||
}
|
||||
|
||||
Light *light = new Light(Light::Type::AMBIENT);
|
||||
light->setColor(Vector3::VEC_IJK * .3);
|
||||
|
||||
Node *lightNode = new Node();
|
||||
lightNode->addLight(light);
|
||||
Root::getSingleton()->getRootNode()->attachChild(lightNode);
|
||||
}
|
||||
|
||||
//TODO unload skybox assets
|
||||
@@ -314,6 +340,14 @@ namespace battleship{
|
||||
Root::getSingleton()->removeSkybox();
|
||||
}
|
||||
|
||||
void Map::unloadLights(){
|
||||
while(!lights.empty()){
|
||||
Root::getSingleton()->getRootNode()->removeLight(lights[0]);
|
||||
delete lights[0];
|
||||
lights.erase(lights.begin());
|
||||
}
|
||||
}
|
||||
|
||||
void Map::unloadCells(){
|
||||
while(cellNode->getNumChildren() > 0){
|
||||
Node *node = cellNode->getChild(0);
|
||||
@@ -360,6 +394,7 @@ namespace battleship{
|
||||
|
||||
void Map::unload(){
|
||||
unloadSkybox();
|
||||
unloadLights();
|
||||
unloadCells();
|
||||
unloadTerrainObjects();
|
||||
unloadPlayerObjects();
|
||||
|
||||
Reference in New Issue
Block a user