updated lua invocations using sol3

This commit is contained in:
devZoGok
2023-08-19 10:23:00 +03:00
parent 5cf511d0fd
commit 06e1ec54aa
20 changed files with 238 additions and 201 deletions
+2
View File
@@ -9,6 +9,8 @@ gui = {
pos = {x = 110, y = 40},
size = {x = 100, y = 10},
guiType = GuiType.SLIDER,
minValue = 0,
maxValue = 100,
numDependencies = 1,
dependencies = {
{id = 0}
+48
View File
@@ -0,0 +1,48 @@
Size = {x = 150, y = 40}
numGui = 6
gui = {
{
pos = {x = 110, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Controls',
buttonType = ButtonType.CONTROLS_TAB
},
{
pos = {x = 270, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Mouse',
buttonType = ButtonType.MOUSE_TAB
},
{
pos = {x = 430, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Video',
buttonType = ButtonType.VIDEO_TAB
},
{
pos = {x = 590, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Audio',
buttonType = ButtonType.AUDIO_TAB
},
{
pos = {x = 750, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Multiplayer',
buttonType = ButtonType.MULTIPLAYER_TAB
},
{
pos = {x = 910, y = 100},
size = Size,
guiType = GuiType.BUTTON,
name = 'Back',
screen = 'gamePaused.lua',
buttonType = ButtonType.BACK
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ gui = {
buttonType = ButtonType.LOAD_MAP_OK,
numDependencies = 1,
dependencies = {
{dep = 0}
{id = 0}
}
},
{
+48
View File
@@ -0,0 +1,48 @@
Size = {x = 150, y = 40}
numGui = 6
gui = {
{
pos = {x = 110, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Controls',
buttonType = ButtonType.CONTROLS_TAB
},
{
pos = {x = 270, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Mouse',
buttonType = ButtonType.MOUSE_TAB
},
{
pos = {x = 430, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Video',
buttonType = ButtonType.VIDEO_TAB
},
{
pos = {x = 590, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Audio',
buttonType = ButtonType.AUDIO_TAB
},
{
pos = {x = 750, y = 40},
size = Size,
guiType = GuiType.BUTTON,
name = 'Multiplayer',
buttonType = ButtonType.MULTIPLAYER_TAB
},
{
pos = {x = 910, y = 100},
size = Size,
guiType = GuiType.BUTTON,
name = 'Back',
screen = 'mainMenu.lua',
buttonType = ButtonType.BACK
}
}
+2 -2
View File
@@ -8,8 +8,8 @@ gui = {
{
pos = {x = 110, y = 40},
size = {x = 300, y = 10},
minVal = 0,
maxVal = 2,
minValue = 0,
maxValue = 2,
guiType = GuiType.SLIDER,
numDependencies = 1,
dependencies = {
+3
View File
@@ -6,18 +6,21 @@ gui = {
pos = {x = 100, y = 100},
size = Size,
guiType = GuiType.LISTBOX,
numMaxDisplay = 3,
listboxType = ListboxType.CPU_DIFFICULTIES
},
{
pos = {x = 210, y = 100},
size = Size,
guiType = GuiType.LISTBOX,
numMaxDisplay = 3,
listboxType = ListboxType.FACTIONS
},
{
pos = {x = 100, y = 230},
size = Size,
guiType = GuiType.LISTBOX,
numMaxDisplay = 3,
listboxType = ListboxType.FACTIONS
},
{
+2 -3
View File
@@ -7,7 +7,7 @@
#include <ray.h>
#include <stateManager.h>
#include <luaManager.h>
#include <solUtil.h>
#include <algorithm>
#include <ctype.h>
@@ -420,8 +420,7 @@ namespace battleship{
//TODO fix the magic value
int id = 3;
LuaManager *lm = LuaManager::getSingleton();
string modelPath = lm->getStringFromTable("basePath", vector<Index>{Index(id + 1)}) + lm->getStringFromTable("meshPath", vector<Index>{Index(id + 1)});
string modelPath = (string)SOL_LUA_STATE["basePath"][id + 1] + (string)SOL_LUA_STATE["meshPath"][id + 1];
ufCtr->addUnitFrame(UnitFrameController::UnitFrame(modelPath, id, (int)UnitType::LAND));
ufCtr->setPlacingFrames(true);
+50 -78
View File
@@ -1,4 +1,4 @@
#include <luaManager.h>
#include <solUtil.h>
#include "concreteGuiManager.h"
#include "gameManager.h"
@@ -37,19 +37,16 @@ namespace battleship{
//TODO refactor player difficulty and faction listbox selection
Button* ConcreteGuiManager::parseButton(int guiId){
LuaManager *lm = LuaManager::getSingleton();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string guiTable = "gui", posTable = "pos", sizeTable = "size";
float posX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("x")});
float posY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("y")});
Vector2 pos = Vector2(posX, posY);
sol::table posTable = guiTable["pos"];
Vector2 pos = Vector2(posTable["x"], posTable["y"]);
float sizeX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("x")});
float sizeY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("y")});
Vector2 size = Vector2(sizeX, sizeY);
sol::table sizeTable = guiTable["size"];
Vector2 size = Vector2(sizeTable["x"], sizeTable["y"]);
string name = lm->getStringFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("name")});
ButtonType type = (ButtonType)lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("buttonType")});
string name = guiTable["name"];
ButtonType type = (ButtonType)guiTable["buttonType"];
Button *button = nullptr;
@@ -73,7 +70,7 @@ namespace battleship{
button = new DefaultsButton(pos, size, name);
break;
case BACK: {
string screen = lm->getStringFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("screen")});
string screen = guiTable["screen"];
button = new BackButton(pos, size, name, screen);
break;
}
@@ -97,11 +94,11 @@ namespace battleship{
button = new NewMapButton(pos, size);
break;
case NEW_MAP_OK:{
int numTextboxes = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("numDependencies")});
int numTextboxes = guiTable["numDependencies"];
vector<Textbox*> t;
for(int i = 0; i < numTextboxes; i++){
int tid = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(i + 1), Index("id")});
int tid = guiTable["dependencies"][i + 1]["id"];
t.push_back((Textbox*)guiElements[tid].second);
}
@@ -112,7 +109,7 @@ namespace battleship{
button = new LoadMapButton(pos, size);
break;
case LOAD_MAP_OK:{
int lid = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(1), Index("id")});
int lid = guiTable["dependencies"][1]["id"];
button = new LoadMapButton::OkButton(pos, size, (Listbox*)guiElements[lid].second);
break;
}
@@ -120,18 +117,18 @@ namespace battleship{
button = new ExportButton(pos, size);
break;
case PLAY:{
int did = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(1), Index("id")});
int did = guiTable["dependencies"][1]["id"];
vector<Listbox*> difficultyListboxes = vector<Listbox*>{(Listbox*)guiElements[did].second};
vector<Listbox*> factionsListboxes;
int numPlayers = 2;
for(int i = 0; i < numPlayers; i++){
int fid = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(i + 2), Index("id")});
factionsListboxes.push_back((Listbox*)guiElements[fid].second);
int did = guiTable["dependencies"][i + 2]["id"];
factionsListboxes.push_back((Listbox*)guiElements[did].second);
}
int mid = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(4), Index("id")});
int mid = guiTable["dependencies"][4]["id"];
Listbox *mapListbox = (Listbox*)guiElements[mid].second;
button = new PlayButton(difficultyListboxes, factionsListboxes, mapListbox, pos, size, name, true);
@@ -147,10 +144,10 @@ namespace battleship{
button = new MainMenuButton(pos, size, name);
break;
case CONSOLE_COMMAND_OK:{
int lid = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(1), Index("id")});
int lid = guiTable["dependencies"][1]["id"];
Listbox *listbox = (Listbox*)guiElements[lid].second;
int tid = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(2), Index("id")});
int tid = guiTable["dependencies"][2]["id"];
Textbox *textbox = (Textbox*)guiElements[tid].second;
button = new InGameAppState::ConsoleButton::ConsoleCommandEntryButton(textbox, listbox, pos, size, name);
@@ -165,19 +162,16 @@ namespace battleship{
}
Listbox* ConcreteGuiManager::parseListbox(int guiId){
LuaManager *lm = LuaManager::getSingleton();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string guiTable = "gui", posTable = "pos", sizeTable = "size";
float posX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("x")});
float posY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("y")});
Vector2 pos = Vector2(posX, posY);
string posTable = "pos";
Vector2 pos = Vector2(guiTable[posTable]["x"], guiTable[posTable]["y"]);
float sizeX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("x")});
float sizeY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("y")});
Vector2 size = Vector2(sizeX, sizeY);
string sizeTable = "size";
Vector2 size = Vector2(guiTable[sizeTable]["x"], guiTable[sizeTable]["y"]);
int numMaxDisplay = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("numMaxDisplay")});
ListboxType listboxType = (ListboxType)lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("listboxType")});
int numMaxDisplay = guiTable["numMaxDisplay"];
ListboxType listboxType = (ListboxType)guiTable["listboxType"];
vector<string> lines;
int maxDisplay, numLines;
@@ -200,10 +194,10 @@ namespace battleship{
break;
}
case RESOLUTION:{
numLines = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("numLines")});
numLines = guiTable["numLines"];
for(int i = 0; i < numLines; i++)
lines.push_back(lm->getStringFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("lines"), Index(i + 1)}));
lines.push_back(guiTable["lines"][i + 1]);
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
@@ -221,17 +215,14 @@ namespace battleship{
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable);
break;
case UNITS:{
bool vehicles = lm->getBoolFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("vehicles")});
int numUnits = lm->getInt("numUnits");
bool vehicles = guiTable["vehicles"];
int numUnits = SOL_LUA_STATE["numUnits"];
for(int i = 0; i < numUnits; i++){
bool v = lm->getBoolFromTable("isVehicle", vector<Index>{Index(i + 1)});
if(v == vehicles){
string name = lm->getStringFromTable("name", vector<Index>{Index(i + 1)});
lines.push_back(name);
}
bool v = SOL_LUA_STATE["isVehicle"][i + 1];
if(v == vehicles)
lines.push_back(SOL_LUA_STATE["name"][i + 1]);
}
numLines = lines.size();
@@ -291,15 +282,12 @@ namespace battleship{
}
Checkbox* ConcreteGuiManager::parseCheckbox(int guiId){
LuaManager *lm = LuaManager::getSingleton();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string guiTable = "gui", posTable = "pos", sizeTable = "size";
float posX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("x")});
float posY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("y")});
Vector2 pos = Vector2(posX, posY);
string posTable = "pos";
Vector2 pos = Vector2(guiTable[posTable]["x"], guiTable[posTable]["y"]);
string fontFile = "batang.ttf";
string fontPath = GameManager::getSingleton()->getPath() + "Fonts/" + fontFile;
string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf";
Checkbox *checkbox = new Checkbox(pos, fontPath);
int typeArr[2]{(int)GuiElementType::CHECKBOX, -1};
@@ -309,21 +297,13 @@ namespace battleship{
}
Slider* ConcreteGuiManager::parseSlider(int guiId){
LuaManager *lm = LuaManager::getSingleton();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string guiTable = "gui", posTable = "pos", sizeTable = "size";
float posX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("x")});
float posY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("y")});
Vector2 pos = Vector2(posX, posY);
string posTable = "pos", sizeTable = "size";
Vector2 pos = Vector2(guiTable[posTable]["x"], guiTable[posTable]["y"]);
Vector2 size = Vector2(guiTable[sizeTable]["x"], guiTable[sizeTable]["y"]);
float sizeX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("x")});
float sizeY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("y")});
Vector2 size = Vector2(sizeX, sizeY);
float minVal = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("minValue")});
float maxVal = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("maxValue")});
Slider *slider = new Slider(pos, size, minVal, maxVal);
Slider *slider = new Slider(pos, size, guiTable["minValue"], guiTable["maxValue"]);
int typeArr[2]{(int)GuiElementType::SLIDER, -1};
guiElements.push_back(make_pair(typeArr, (void*)slider));
@@ -332,19 +312,13 @@ namespace battleship{
}
Textbox* ConcreteGuiManager::parseTextbox(int guiId){
LuaManager *lm = LuaManager::getSingleton();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string guiTable = "gui", posTable = "pos", sizeTable = "size";
float posX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("x")});
float posY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("y")});
Vector2 pos = Vector2(posX, posY);
string posTable = "pos", sizeTable = "size";
Vector2 pos = Vector2(guiTable[posTable]["x"], guiTable[posTable]["y"]);
Vector2 size = Vector2(guiTable[sizeTable]["x"], guiTable[sizeTable]["y"]);
float sizeX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("x")});
float sizeY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("y")});
Vector2 size = Vector2(sizeX, sizeY);
string fontFile = "batang.ttf";
string fontPath = GameManager::getSingleton()->getPath() + "Fonts/" + fontFile;
string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf";
Textbox *textbox = new Textbox(pos, size, fontPath);
int typeArr[2]{(int)GuiElementType::TEXTBOX, -1};
@@ -358,16 +332,14 @@ namespace battleship{
guiElements.clear();
LuaManager *lm = LuaManager::getSingleton();
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
lm->buildScript(vector<string>{basePath + "main.lua", basePath + script});
SOL_LUA_STATE.script_file(basePath + "main.lua");
SOL_LUA_STATE.script_file(basePath + script);
int numGuiElements = lm->getInt("numGui");
int numGuiElements = SOL_LUA_STATE["numGui"];
for(int i = 0; i < numGuiElements; i++){
int guiTypeId = lm->getIntFromTable("gui", vector<Index>{Index(i + 1), Index("guiType")});
vector<Index> indices = vector<Index>{Index(i + 1)};
void *element = nullptr;
int guiTypeId = SOL_LUA_STATE["gui"][i + 1]["guiType"];
switch((GuiElementType)guiTypeId){
case BUTTON:
+2 -4
View File
@@ -4,7 +4,7 @@
#include <vector.h>
#include <stateManager.h>
#include <luaManager.h>
#include <solUtil.h>
#include "consoleCommand.h"
#include "inGameAppState.h"
@@ -62,9 +62,7 @@ namespace battleship{
int unitId = atoi(fullCommand[2].c_str());
LuaManager *lm = LuaManager::getSingleton();
if(!(0 <= unitId && unitId <= lm->getInt("numUnits")))
if(!(0 <= unitId && unitId <= (int)SOL_LUA_STATE["numUnits"]))
return;
}
+6 -9
View File
@@ -6,7 +6,7 @@
#include <assetManager.h>
#include <root.h>
#include <luaManager.h>
#include <solUtil.h>
#include "gameManager.h"
#include "guiAppState.h"
@@ -29,20 +29,17 @@ namespace battleship{
void GameManager::start(string gameDir) {
path = gameDir + "Assets/";
LuaManager *luaManager = LuaManager::getSingleton();
luaManager->executeCode("PATH = \"" + path + "\";");
gameBase::SOL_LUA_STATE.script("PATH = \"" + path + "\";");
vector<string> files = configData::scripts;
files.emplace(files.begin(), "Scripts/main.lua");
for(string &f : files)
f = path + f;
gameBase::SOL_LUA_STATE.script_file(path + f);
luaManager->buildScript(files);
string ind1 = "graphics", ind2 = "resolution";
width = luaManager->getIntFromTable(ind1, vector<Index>{Index(ind2), Index("x")});
height = luaManager->getIntFromTable(ind1, vector<Index>{Index(ind2), Index("y")});
sol::table resTable = SOL_LUA_STATE["graphics"]["resolution"];
width = resTable["x"];
height = resTable["y"];
Root *root = Root::getSingleton();
root->start(width, height, path + "../external/vb01/", "Battleship");
+2 -2
View File
@@ -8,7 +8,7 @@
#include <assetManager.h>
#include <stateManager.h>
#include <luaManager.h>
#include <solUtil.h>
#include "defConfigs.h"
#include "inGameAppState.h"
@@ -119,7 +119,7 @@ namespace battleship{
isMainMenuActive = false;
gm->getStateManager()->attachAppState(activeState);
AssetManager::getSingleton()->load(gm->getPath() + LuaManager::getSingleton()->getString("modelPrefix"), true);
AssetManager::getSingleton()->load(gm->getPath() + (string)SOL_LUA_STATE["modelPrefix"], true);
guiManager->readLuaScreenScript("inGame.lua");
+36 -45
View File
@@ -4,7 +4,7 @@
#include <material.h>
#include <assetManager.h>
#include <luaManager.h>
#include <solUtil.h>
#include "map.h"
#include "player.h"
@@ -35,9 +35,7 @@ namespace battleship{
}
void Map::loadSkybox(){
LuaManager *lm = LuaManager::getSingleton();
string skyboxName = lm->getStringFromTable(mapTable, vector<Index>{Index("skybox")});
string skyboxName = SOL_LUA_STATE[mapTable]["skybox"];
string basePath = GameManager::getSingleton()->getPath() + "Textures/Skyboxes/" + skyboxName;
const int numPaths = 6;
@@ -57,6 +55,7 @@ namespace battleship{
}
void Map::loadTerrainObject(int id){
/*
LuaManager *luaManager = LuaManager::getSingleton();
string terrainTable = (id == -1 ? "terrain" : "waterBodies");
vector<Index> baseIndices = (id == -1 ? vector<Index>{Index(terrainTable)} : vector<Index>{Index(terrainTable), Index(id + 1)});
@@ -193,18 +192,15 @@ namespace battleship{
quad->setMaterial(mat);
terrainObjects.push_back(TerrainObject(pos, size, Vector3(cellSize.x, (id == -1 ? 0 : cellSize.y), cellSize.z), type, node, numCells, cells, weights));
*/
}
void Map::loadSpawnPoints(){
LuaManager *lm = LuaManager::getSingleton();
int numSpawnPoints = lm->getIntFromTable(mapTable, vector<Index>{Index("numSpawnPoints")});
string spawnPointInd = "spawnPoints";
int numSpawnPoints = SOL_LUA_STATE[mapTable]["numSpawnPoints"];
for(int i = 0; i < numSpawnPoints; i++){
float x = lm->getFloatFromTable(mapTable, vector<Index>{Index(spawnPointInd), Index(i + 1), Index("x")});
float y = lm->getFloatFromTable(mapTable, vector<Index>{Index(spawnPointInd), Index(i + 1), Index("y")});
float z = lm->getFloatFromTable(mapTable, vector<Index>{Index(spawnPointInd), Index(i + 1), Index("z")});
spawnPoints.push_back(Vector3(x, y, z));
sol::table posTable = SOL_LUA_STATE[mapTable]["spawnPointInd"][i + 1];
spawnPoints.push_back(Vector3(posTable["x"], posTable["y"], posTable["z"]));
}
}
@@ -213,31 +209,27 @@ namespace battleship{
AssetManager *assetManager = AssetManager::getSingleton();
string path = GameManager::getSingleton()->getPath();
assetManager->load(path + DEFAULT_TEXTURE);
LuaManager *lm = LuaManager::getSingleton();
assetManager->load(path + lm->getString("modelPrefix"), true);
assetManager->load(path + (string)SOL_LUA_STATE["modelPrefix"], true);
int numPlayers = lm->getIntFromTable(mapTable, vector<Index>{Index("numPlayers")});
string playerInd = "players", unitInd = "units", spawnPointInd = "spawnPointId", posInd = "pos", rotInd = "rot";
int numPlayers = SOL_LUA_STATE[mapTable]["numPlayers"];
string playerInd = "players";
for(int i = 0; i < numPlayers; i++){
int spawnPointId = lm->getIntFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(spawnPointId)});
int numUnits = lm->getIntFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index("numUnits")});
int spawnPointId = SOL_LUA_STATE[mapTable]["spawnPointInd"][i + 1][spawnPointId];
int numUnits = SOL_LUA_STATE[mapTable][playerInd][i + 1]["numUnits"];
players.push_back(new Player(0, 0, 0, spawnPoints[i]));
for(int j = 0; j < numUnits; j++){
float posX = lm->getFloatFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(posInd), Index("x")});
float posY = lm->getFloatFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(posInd), Index("y")});
float posZ = lm->getFloatFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(posInd), Index("z")});
Vector3 pos = Vector3(posX, posY, posZ);
sol::table unitTable = SOL_LUA_STATE[mapTable][playerInd][i + 1]["units"][j + 1];
float rotW = lm->getFloatFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(rotInd), Index("w")});
float rotX = lm->getFloatFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(rotInd), Index("x")});
float rotY = lm->getFloatFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(rotInd), Index("y")});
float rotZ = lm->getFloatFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(rotInd), Index("z")});
Quaternion rot = Quaternion(rotW, rotX, rotY, rotZ);
string posInd = "pos";
Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]);
int id = lm->getIntFromTable(mapTable, vector<Index>{Index(playerInd), Index(i + 1), Index(unitInd), Index("id")});
string rotInd = "rot";
Quaternion rot = Quaternion(unitTable[rotInd]["w"], unitTable[rotInd]["x"], unitTable[rotInd]["x"], unitTable[rotInd]["x"]);
int id = unitTable["id"];
players[i]->addUnit(UnitFactory::createUnit(players[i], id, pos, rot));
}
@@ -255,25 +247,24 @@ namespace battleship{
}
void Map::load(string mapName, bool empty) {
this->mapName = mapName;
cellSize = Vector3(7, 6, 7);
Pathfinder::getSingleton()->setImpassibleNodeVal(u16(0 - 1));
preprareScene();
this->mapName = mapName;
cellSize = Vector3(7, 6, 7);
Pathfinder::getSingleton()->setImpassibleNodeVal(u16(0 - 1));
preprareScene();
if(!empty){
LuaManager *lm = LuaManager::getSingleton();
lm->buildScript(vector<string>{GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua"});
int numWaterbodies = lm->getIntFromTable(mapTable, vector<Index>{Index("numWaterBodies")});
loadSpawnPoints();
loadPlayers();
loadSkybox();
loadTerrainObject(-1);
for(int i = 0; i < numWaterbodies; i++)
loadTerrainObject(i);
}
if(!empty){
SOL_LUA_STATE.script_file(GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua");
int numWaterbodies = SOL_LUA_STATE[mapTable]["numWaterBodies"];
loadSpawnPoints();
loadPlayers();
loadSkybox();
loadTerrainObject(-1);
for(int i = 0; i < numWaterbodies; i++)
loadTerrainObject(i);
}
}
void Map::unload() {}
+1 -1
View File
@@ -17,7 +17,7 @@
#include <texture.h>
#include <assetManager.h>
#include <luaManager.h>
#include <util.h>
#include <listbox.h>
+3 -5
View File
@@ -1,6 +1,6 @@
#include "player.h"
#include <luaManager.h>
#include <solUtil.h>
using namespace vb01;
using namespace gameBase;
@@ -13,16 +13,14 @@ namespace battleship{
this->spawnPoint = spawnPoint;
this->id = id;
LuaManager *lm = LuaManager::getSingleton();
lm->executeCode("players[" + to_string(id + 1) + "] = Player:new({id = " + to_string(id + 1) + "})");
SOL_LUA_STATE.script("players[" + to_string(id + 1) + "] = Player:new({id = " + to_string(id + 1) + "})");
}
Player::~Player() {
}
void Player::update() {
LuaManager *lm = LuaManager::getSingleton();
lm->executeCode("players[" + to_string(id + 1) + "]:update()");
SOL_LUA_STATE.script("players[" + to_string(id + 1) + "]:update()");
for(Unit *u : units)
u->update();
+8 -13
View File
@@ -7,7 +7,7 @@
#include <ray.h>
#include <stateManager.h>
#include <luaManager.h>
#include <solUtil.h>
#include "map.h"
#include "unit.h"
@@ -44,24 +44,20 @@ namespace battleship{
}
void Projectile::initProperties(int weaponId){
LuaManager *lm = LuaManager::getSingleton();
vector<Index> indices = vector<Index>{Index(id + 1), Index(weaponTypeId + 1), Index(weaponId + 1)};
rayLength = lm->getFloatFromTable("rayLength", indices);
damage = lm->getIntFromTable("damage", indices);
speed = lm->getFloatFromTable("speed", indices);
rayLength = SOL_LUA_STATE["rayLength"][id + 1][weaponTypeId + 1][weaponId + 1];
damage = SOL_LUA_STATE["damage"][id + 1][weaponTypeId + 1][weaponId + 1];
speed = SOL_LUA_STATE["speed"][id + 1][weaponTypeId + 1][weaponId + 1];
}
void Projectile::initModel(Node *node){
if(!node){
LuaManager *lm = LuaManager::getSingleton();
vector<Index> indices = vector<Index>{Index(id + 1), Index(weaponTypeId + 1)};
string meshPath = lm->getStringFromTable("meshPath", indices);
string meshPath = SOL_LUA_STATE["meshPath"][id + 1][weaponTypeId + 1];
this->node = new Model(meshPath);
Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture");
mat->addBoolUniform("lightingEnabled", false);
string diffTexPath = lm->getStringFromTable("diffuseMapTextPath", indices);
string diffTexPath = SOL_LUA_STATE["diffuseMapTextPath"][id + 1][weaponTypeId + 1];
string f[]{diffTexPath};
Texture *diffuseTexture = new Texture(f, 1, false);
mat->addTexUniform("textures[0]", diffuseTexture, true);
@@ -74,10 +70,9 @@ namespace battleship{
void Projectile::initSound(){
GameManager *gm = GameManager::getSingleton();
LuaManager *lm = LuaManager::getSingleton();
string unitName = lm->getStringFromTable("name", vector<Index>{Index(id + 1)});
string projectileName = lm->getStringFromTable("projectileName", vector<Index>{Index(id + 1), Index(weaponTypeId + 1)});
string unitName = SOL_LUA_STATE["name"][id + 1];
string projectileName = SOL_LUA_STATE["projectileName"][id + 1][weaponTypeId + 1];
string p1 = gm->getPath() + "Sounds/" + unitName + "s/" + projectileName + ".ogg";
string p2 = gm->getPath() + "Sounds/Explosions/explosion03" + to_string(rand() % 4) + ".ogg";
+11 -16
View File
@@ -5,7 +5,7 @@
#include <ray.h>
#include <stateManager.h>
#include <luaManager.h>
#include <solUtil.h>
#include <glm.hpp>
#include <ext.hpp>
@@ -39,22 +39,19 @@ namespace battleship{
}
void Unit::initProperties(){
LuaManager *lm = LuaManager::getSingleton();
health = lm->getIntFromTable("health", vector<Index>{Index(id + 1)});
health = SOL_LUA_STATE["health"][id + 1];
maxHealth = health;
range = lm->getFloatFromTable("range", vector<Index>{Index(id + 1)});
lineOfSight = lm->getFloatFromTable("lineOfSight", vector<Index>{Index(id + 1)});
unitClass = (UnitClass)lm->getIntFromTable("unitClass", vector<Index>{Index(id + 1)});
type = (UnitType)lm->getIntFromTable("unitType", vector<Index>{Index(id + 1)});
range = SOL_LUA_STATE["range"][id + 1];
lineOfSight = SOL_LUA_STATE["lineOfSight"][id + 1];
unitClass = (UnitClass)SOL_LUA_STATE["unitClass"][id + 1];
type = (UnitType)SOL_LUA_STATE["unitType"][id + 1];
string cornerInd = "unitCornerPoints";
for(int i = 0; i < 8; i++){
float x = lm->getFloatFromTable(cornerInd, vector<Index>{Index(id + 1), Index(i + 1), Index("x")});
float y = lm->getFloatFromTable(cornerInd, vector<Index>{Index(id + 1), Index(i + 1), Index("y")});
float z = lm->getFloatFromTable(cornerInd, vector<Index>{Index(id + 1), Index(i + 1), Index("z")});
corners[i] = Vector3(x, y, z);
sol::table cornerTable = SOL_LUA_STATE[cornerInd][id + 1][i + 1];
corners[i] = Vector3(cornerTable["x"], cornerTable["y"], cornerTable["z"]);
}
width = corners[0].x - corners[1].x;
@@ -68,9 +65,8 @@ namespace battleship{
}
void Unit::initModel(){
LuaManager *lm = LuaManager::getSingleton();
string basePath = lm->getStringFromTable("basePath", vector<Index>{Index(id + 1)});
string meshPath = lm->getStringFromTable("meshPath", vector<Index>{Index(id + 1)});
string basePath = SOL_LUA_STATE["basePath"][id + 1];
string meshPath = SOL_LUA_STATE["meshPath"][id + 1];
model = new Model(basePath + meshPath);
Root *root = Root::getSingleton();
@@ -94,8 +90,7 @@ namespace battleship{
}
void Unit::initSound(){
LuaManager *lm = LuaManager::getSingleton();
string name = lm->getStringFromTable("name", vector<Index>{Index(id + 1)});
string name = SOL_LUA_STATE["name"][id + 1];
selectionSfxBuffer = new sf::SoundBuffer();
string p = GameManager::getSingleton()->getPath() + "Sounds/" + name + "s/selection.ogg";
+2 -4
View File
@@ -3,7 +3,7 @@
#include "vehicle.h"
#include "engineer.h"
#include <luaManager.h>
#include <solUtil.h>
#include <vector>
@@ -13,11 +13,9 @@ namespace battleship{
using namespace gameBase;
Unit* UnitFactory::createUnit(Player *player, int id, Vector3 pos, Quaternion rot){
int unitClass = SOL_LUA_STATE["unitClass"][id + 1];
Unit *unit = nullptr;
LuaManager *luaManager = LuaManager::getSingleton();
int unitClass = luaManager->getIntFromTable("unitClass", vector<Index>{Index(id + 1)});
switch((UnitClass)unitClass){
case UnitClass::ENGINEER:
unit = new Engineer(player, id, pos, rot);
+5 -10
View File
@@ -9,7 +9,7 @@
#include <root.h>
#include <ray.h>
#include <luaManager.h>
#include <solUtil.h>
#include <string>
@@ -47,9 +47,7 @@ namespace battleship{
MeshData::Vertex *verts = meshData.vertices;
int numVerts = 3 * meshData.numTris;
LuaManager *lm = LuaManager::getSingleton();
float maxUnevenness = lm->getFloat("maxUnevenness");
string table = "unitCornerPoints";
float maxUnevenness = SOL_LUA_STATE["maxUnevenness"];
Camera *cam = Root::getSingleton()->getCamera();
Vector3 startPos = cam->getPosition();
@@ -64,12 +62,9 @@ namespace battleship{
if(!rotatingStructure)
s.model->setPosition(results[0].pos);
float width =
lm->getFloatFromTable(table, vector<Index>{Index(s.id + 1), Index(1), Index("x")}) -
lm->getFloatFromTable(table, vector<Index>{Index(s.id + 1), Index(2), Index("x")});
float length =
lm->getFloatFromTable(table, vector<Index>{Index(s.id + 1), Index(4), Index("z")}) -
lm->getFloatFromTable(table, vector<Index>{Index(s.id + 1), Index(1), Index("z")});
sol::table unitTable = SOL_LUA_STATE["unitCornerPoints"][s.id + 1];
float width = (int)unitTable[1]["x"] - (int)unitTable[2]["x"];
float length = (int)unitTable[4]["z"] - (int)unitTable[1]["z"];
float unevenness = 0;
+2 -3
View File
@@ -2,7 +2,7 @@
#include "unit.h"
#include "unitFrameController.h"
#include <luaManager.h>
#include <solUtil.h>
namespace battleship{
using namespace std;
@@ -17,8 +17,7 @@ namespace battleship{
UnitFrameController *ufCtr = UnitFrameController::getSingleton();
int id = selectedOption;
LuaManager *lm = LuaManager::getSingleton();
string modelPath = lm->getStringFromTable("basePath", vector<Index>{Index(id + 1)}) + lm->getStringFromTable("meshPath", vector<Index>{Index(id + 1)});
string modelPath = (string)SOL_LUA_STATE["basePath"][id + 1] + (string)SOL_LUA_STATE["meshPath"][id + 1];
ufCtr->addUnitFrame(UnitFrameController::UnitFrame(modelPath, id, (int)UnitType::LAND));
ufCtr->setPlacingFrames(true);
+4 -5
View File
@@ -5,7 +5,7 @@
#include <model.h>
#include <quaternion.h>
#include <luaManager.h>
#include <solUtil.h>
#include "vehicle.h"
#include "pathfinder.h"
@@ -60,10 +60,9 @@ namespace battleship{
void Vehicle::initProperties(){
Unit::initProperties();
LuaManager *lm = LuaManager::getSingleton();
maxTurnAngle = lm->getFloatFromTable("maxTurnAngle", vector<Index>{Index(id + 1)});
speed = lm->getFloatFromTable("speed", vector<Index>{Index(id + 1)});
anglePrecision = lm->getFloatFromTable("anglePrecision", vector<Index>{Index(id + 1)});
maxTurnAngle = SOL_LUA_STATE["maxTurnAngle"][id + 1];
speed = SOL_LUA_STATE["speed"][id + 1];
anglePrecision = SOL_LUA_STATE["anglePrecision"][id + 1];
}
void Vehicle::navigate(Order order, float destOffset){