diff --git a/Assets/Models/Maps/a/a.lua b/Assets/Models/Maps/a/a.lua
new file mode 100644
index 0000000..dddd6a1
--- /dev/null
+++ b/Assets/Models/Maps/a/a.lua
@@ -0,0 +1,22 @@
+--terrain = {
+ model = "terrain.xml"
+ albedoMap = "terrain.jpg"
+ numWaterBodies = 1
+ skybox = {
+ left = "left.jpg",
+ right = "right.jpg",
+ up = "up.jpg",
+ down = "down.jpg",
+ front = "front.jpg",
+ back = "back.jpg"
+ }
+ waterBodies = {
+ posX = 0,
+ posY = 0,
+ posZ = 0,
+ sizeX = 100,
+ sizeY = 100,
+ rect = true,
+ albedoMap = "water.jpg"
+ }
+--}
diff --git a/Assets/Models/Maps/a/back.jpg b/Assets/Models/Maps/a/back.jpg
new file mode 100755
index 0000000..fc8524a
Binary files /dev/null and b/Assets/Models/Maps/a/back.jpg differ
diff --git a/Assets/Models/Maps/a/down.jpg b/Assets/Models/Maps/a/down.jpg
new file mode 100755
index 0000000..57a084f
Binary files /dev/null and b/Assets/Models/Maps/a/down.jpg differ
diff --git a/Assets/Models/Maps/a/front.jpg b/Assets/Models/Maps/a/front.jpg
new file mode 100755
index 0000000..aa0df39
Binary files /dev/null and b/Assets/Models/Maps/a/front.jpg differ
diff --git a/Assets/Models/Maps/a/left.jpg b/Assets/Models/Maps/a/left.jpg
new file mode 100755
index 0000000..01eca00
Binary files /dev/null and b/Assets/Models/Maps/a/left.jpg differ
diff --git a/Assets/Models/Maps/a/right.jpg b/Assets/Models/Maps/a/right.jpg
new file mode 100755
index 0000000..4b45eea
Binary files /dev/null and b/Assets/Models/Maps/a/right.jpg differ
diff --git a/Assets/Models/Maps/a/terrain.blend b/Assets/Models/Maps/a/terrain.blend
new file mode 100644
index 0000000..8e103db
Binary files /dev/null and b/Assets/Models/Maps/a/terrain.blend differ
diff --git a/Assets/Models/Maps/a/terrain.blend1 b/Assets/Models/Maps/a/terrain.blend1
new file mode 100644
index 0000000..760ae8b
Binary files /dev/null and b/Assets/Models/Maps/a/terrain.blend1 differ
diff --git a/Assets/Models/Maps/a/terrain.jpg b/Assets/Models/Maps/a/terrain.jpg
new file mode 100755
index 0000000..a1451cc
Binary files /dev/null and b/Assets/Models/Maps/a/terrain.jpg differ
diff --git a/Assets/Models/Maps/a/terrain.xml b/Assets/Models/Maps/a/terrain.xml
new file mode 100644
index 0000000..f77c667
--- /dev/null
+++ b/Assets/Models/Maps/a/terrain.xml
@@ -0,0 +1,876 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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..dc646c7
Binary files /dev/null and b/Assets/Models/Maps/a/up.jpg differ
diff --git a/Assets/Models/Maps/a/water.jpg b/Assets/Models/Maps/a/water.jpg
new file mode 100755
index 0000000..0d28b8a
Binary files /dev/null and b/Assets/Models/Maps/a/water.jpg differ
diff --git a/inGameAppState.cpp b/inGameAppState.cpp
index 8fdffbf..e24e32f 100755
--- a/inGameAppState.cpp
+++ b/inGameAppState.cpp
@@ -175,7 +175,7 @@ namespace battleship{
void InGameAppState::SubmarineCreationButton::onClick() {
}
- InGameAppState::InGameAppState(vector difficultyLevels, vector factions) : AbstractAppState(
+ InGameAppState::InGameAppState(vector difficultyLevels, vector factions, string mapName) : AbstractAppState(
AppStateType::IN_GAME_STATE,
configData::calcSumBinds(AppStateType::IN_GAME_STATE, true),
configData::calcSumBinds(AppStateType::IN_GAME_STATE, false),
@@ -183,6 +183,8 @@ namespace battleship{
this->playerId = 0;
this->difficultyLevels = difficultyLevels;
this->factions = factions;
+
+ map = new Map(mapName);
}
InGameAppState::~InGameAppState() {
@@ -191,7 +193,6 @@ namespace battleship{
void InGameAppState::onAttached() {
AbstractAppState::onAttached();
- map = new Map();
map->load();
for (int i = 0; i < factions.size(); i++) {
@@ -226,8 +227,10 @@ namespace battleship{
string *basePaths = unitDataManager->getBasePath();
string *meshPaths = unitDataManager->getMeshPath();
+ /*
for(int i = 0; i < numUnits; ++i)
AssetManager::getSingleton()->load(basePaths[i] + meshPaths[i]);
+ */
}
void InGameAppState::onDettached() {
diff --git a/inGameAppState.h b/inGameAppState.h
index da77a5b..c5089c8 100755
--- a/inGameAppState.h
+++ b/inGameAppState.h
@@ -20,7 +20,7 @@ namespace battleship{
class InGameAppState : public gameBase::AbstractAppState {
public:
- InGameAppState(std::vector, std::vector);
+ InGameAppState(std::vector, std::vector, std::string);
~InGameAppState();
void onAttached();
void onDettached();
diff --git a/map.cpp b/map.cpp
index dbaee01..af6dbcc 100755
--- a/map.cpp
+++ b/map.cpp
@@ -1,21 +1,24 @@
#include
#include
-#include
+#include
#include
#include
+#include
+
#include "map.h"
#include "gameManager.h"
#include "defConfigs.h"
using namespace std;
using namespace vb01;
+using namespace gameBase;
namespace battleship{
using namespace configData;
- Map::Map() {
- size = Vector2(50, 50);
+ Map::Map(string mapName) {
+ this->mapName = mapName;
}
Map::~Map() {
@@ -24,41 +27,88 @@ namespace battleship{
void Map::update() {
}
- void Map::load() {
+ void Map::loadSkybox(LuaManager *luaManager){
int numPaths = 6;
+ string table = "skybox", basePath = configData::PATH + "Models/Maps/" + mapName + "/";
string path[] = {
- PATH + "Textures/left.jpg",
- PATH + "Textures/right.jpg",
- PATH + "Textures/top.jpg",
- PATH + "Textures/bottom.jpg",
- PATH + "Textures/front.jpg",
- PATH + "Textures/back.jpg"
+ 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)})
};
for(int i = 0; i < numPaths; i++)
AssetManager::getSingleton()->load(path[i]);
- Root *root = Root::getSingleton();
- root->createSkybox(path);
+ Root::getSingleton()->createSkybox(path);
+ }
- Quad *quad = new Quad(Vector3(size.x, size.y, 1) * 1, true);
+ void Map::loadTerrain(LuaManager *luaManager){
+ string terrainFile = luaManager->getString("model");
+ string albedoFile = luaManager->getString("albedoMap");
+
+ AssetManager *assetManager = AssetManager::getSingleton();
+ string basePath = configData::PATH + "Models/Maps/" + mapName + "/";
+ assetManager->load(basePath + terrainFile);
+ assetManager->load(basePath + albedoFile);
+
+ Root *root = Root::getSingleton();
+ Model *model = new Model(basePath + terrainFile);
Material *mat = new Material(root->getLibPath() + "texture");
mat->addBoolUniform("texturingEnabled", true);
mat->addBoolUniform("lightingEnabled", false);
- string fr[]{PATH + "Textures/water.jpg"};
- AssetManager::getSingleton()->load(fr[0]);
+ string fr[]{basePath + albedoFile};
Texture *t = new Texture(fr, 1, false);
mat->addTexUniform("textures[0]", t, true);
- quad->setMaterial(mat);
+ model->setMaterial(mat);
+ root->getRootNode()->attachChild(model);
+ }
- waterNode = new Node();
- waterNode->attachMesh(quad);
- root->getRootNode()->attachChild(waterNode);
- waterNode->setOrientation(Quaternion(-1.57, Vector3::VEC_I));
+ void Map::loadWaterbodies(LuaManager *luaManager){
+ //TODO : replace the magic value when it's possible to extract fields from nested tables
+ int numWaterBodies = 1;
+ string table = "waterBodies";
+ Root *root = Root::getSingleton();
- Camera *cam = root->getCamera();
+ 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)});
+ Quad *quad = new Quad(Vector3(sizeX, sizeY, 1) * 1, true);
+ Material *mat = new Material(root->getLibPath() + "texture");
+ mat->addBoolUniform("texturingEnabled", true);
+ mat->addBoolUniform("lightingEnabled", false);
+
+ string fr[]{PATH + "Models/Maps/" + mapName + "/" + luaManager->getStringFromTable(table, vector{Index("albedoMap", true)})};
+ AssetManager::getSingleton()->load(fr[0]);
+ Texture *t = new Texture(fr, 1, false);
+
+ mat->addTexUniform("textures[0]", t, true);
+ quad->setMaterial(mat);
+
+ 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)});
+ waterNode->setPosition(Vector3(posX, posY, posZ));
+ waterNode->setOrientation(Quaternion(-1.57, Vector3::VEC_I));
+ }
+ }
+
+ void Map::load() {
+ LuaManager *luaManager = LuaManager::getSingleton();
+ luaManager->buildScript(vector{configData::PATH + "Models/Maps/" + mapName + "/" + mapName + ".lua"});
+
+ loadSkybox(luaManager);
+ loadTerrain(luaManager);
+ loadWaterbodies(luaManager);
+
+ Camera *cam = Root::getSingleton()->getCamera();
cam->setPosition(Vector3(1, 1, 1) * 10);
cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm());
}
diff --git a/map.h b/map.h
index 25ded27..a24a7ff 100755
--- a/map.h
+++ b/map.h
@@ -2,21 +2,30 @@
#ifndef MAP_H
#define MAP_H
+#include
+
#include
+namespace gameBase{
+ class LuaManager;
+}
+
namespace battleship{
class Map {
public:
- Map();
+ Map(std::string);
~Map();
void update();
void load();
void unload();
- inline vb01::Vector2 getSize(){return size;}
inline vb01::Node* getWaterNode(){return waterNode;}
private:
- vb01::Vector2 size;
vb01::Node *waterNode = nullptr;
+ std::string mapName;
+
+ void loadSkybox(gameBase::LuaManager*);
+ void loadTerrain(gameBase::LuaManager*);
+ void loadWaterbodies(gameBase::LuaManager*);
};
}
diff --git a/unitDataManager.cpp b/unitDataManager.cpp
index 8a08dcc..d0e0a00 100644
--- a/unitDataManager.cpp
+++ b/unitDataManager.cpp
@@ -11,8 +11,6 @@ namespace battleship{
using namespace vb01;
using namespace gameBase;
- typedef LuaManager::Index Index;
-
UnitDataManager *unitDataManager = nullptr;
UnitDataManager* UnitDataManager::getSingleton(){
diff --git a/util.cpp b/util.cpp
index 5f5524d..801f2d7 100755
--- a/util.cpp
+++ b/util.cpp
@@ -47,13 +47,14 @@ namespace battleship{
class PlayButton : public Button {
public:
- PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_P, separate) {
+ PlayButton(Listbox **difficulties, Listbox **factions, Listbox *mapListbox, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_P, separate) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::GUI_STATE));
- this->lengths[0]=lengths[0];
- this->lengths[1]=lengths[1];
+ this->lengths[0] = lengths[0];
+ this->lengths[1] = lengths[1];
- difficultiesListboxes=difficulties;
- factionsListboxes=factions;
+ difficultiesListboxes = difficulties;
+ factionsListboxes = factions;
+ this->mapListbox = mapListbox;
}
void onClick() {
@@ -66,18 +67,21 @@ namespace battleship{
for(int i = 0; i < lengths[1]; i++)
factions.push_back(to_string(factionsListboxes[i]->getSelectedOption()));
+
delete[] difficultiesListboxes;
delete[] factionsListboxes;
StateManager *stateManager = gm->getStateManager();
- stateManager->attachAppState(new InGameAppState(difficulties, factions));
+ int selectedMap = mapListbox->getSelectedOption();
+ string mapName = wstringToString(mapListbox->getContents()[selectedMap]);
+ stateManager->attachAppState(new InGameAppState(difficulties, factions, mapName));
state->removeAllListboxes();
state->removeButton("Back");
state->removeButton("Play");
}
private:
GuiAppState *state;
- Listbox **difficultiesListboxes, **factionsListboxes;
+ Listbox **difficultiesListboxes, **factionsListboxes, *mapListbox = nullptr;
int lengths[2];
};
@@ -131,15 +135,15 @@ namespace battleship{
int numMinDirs = 3;
int numShowDirs = folders.size() < numMinDirs ? folders.size() : numMinDirs;
Listbox *map = new Listbox(Vector2(pos.x + 110, pos.y + 100), Vector2(100, 20), folders, numShowDirs, font);
- Listbox **difficultyListboxes=new Listbox*[1];
- Listbox **factionListboxes=new Listbox*[2];
+ Listbox **difficultyListboxes = new Listbox*[1];
+ Listbox **factionListboxes = new Listbox*[2];
- difficultyListboxes[0]=cpuDifficulty;
- factionListboxes[0]=playerFaction;
- factionListboxes[1]=cpuFaction;
+ difficultyListboxes[0] = cpuDifficulty;
+ factionListboxes[0] = playerFaction;
+ factionListboxes[1] = cpuFaction;
- int lengths[]{1,2};
- PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, lengths, Vector2(50, gm->getHeight() - 150), Vector2(140, 50), "Play", true);
+ int lengths[]{1, 2};
+ PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, map, lengths, Vector2(50, gm->getHeight() - 150), Vector2(140, 50), "Play", true);
ReturnButton *returnButton = new ReturnButton(state, Vector2(200, gm->getHeight() - 150), Vector2(140, 50), "Back", true);
state->addButton(playButton);
state->addButton(returnButton);