diff --git a/Assets/Models/Maps/a/a.blend1 b/Assets/Models/Maps/a/a.blend1 deleted file mode 100644 index 6a859f8..0000000 Binary files a/Assets/Models/Maps/a/a.blend1 and /dev/null differ diff --git a/Assets/Models/Maps/a/a.lua b/Assets/Models/Maps/a/a.lua index 2bcdbda..2aef43d 100644 --- a/Assets/Models/Maps/a/a.lua +++ b/Assets/Models/Maps/a/a.lua @@ -1,6 +1,22 @@ map = { numWaterBodies = 2, impassibleNodeValue = 65535, + numPlayers = 2, + numSpawnPoints = 1, + spawnPoints = { + {x = 0, y = 0, z = 0} + }, + players = { + { + spawnPointId = 0, + numUnits = 0 + }, + { + spawnPointId = 0, + numUnits = 1, + units = {{id = 0, pos = {x = 0, y = 0, z = 0}, rot = {w = 1, x = 0, y = 0, z = 0}}} + } + }, terrain = { model = "a.xml", albedoMap = "a.jpg", @@ -16,7 +32,7 @@ weights = { } } }, - skybox = {left = "left.jpg", right = "right.jpg", up = "up.jpg", down = "down.jpg", front = "front.jpg", back = "back.jpg"}, + skybox = "Skybox1", waterBodies = { { pos = {x = -20.925153732299805, y = 11.0, z = -21.885021209716797}, @@ -51,4 +67,4 @@ weights = { } } } -} \ No newline at end of file +} diff --git a/Assets/Models/Maps/a/a.xml b/Assets/Models/Maps/a/a.xml index a0164d9..3bf8d58 100644 --- a/Assets/Models/Maps/a/a.xml +++ b/Assets/Models/Maps/a/a.xml @@ -1,5 +1,5 @@ - - + + @@ -71613,4 +71613,4 @@ - \ No newline at end of file + diff --git a/Assets/Models/Maps/a/back.jpg b/Assets/Models/Maps/a/back.jpg deleted file mode 100755 index fc8524a..0000000 Binary files a/Assets/Models/Maps/a/back.jpg and /dev/null differ diff --git a/Assets/Models/Maps/a/down.jpg b/Assets/Models/Maps/a/down.jpg deleted file mode 100755 index 57a084f..0000000 Binary files a/Assets/Models/Maps/a/down.jpg and /dev/null differ diff --git a/Assets/Models/Maps/a/front.jpg b/Assets/Models/Maps/a/front.jpg deleted file mode 100755 index aa0df39..0000000 Binary files a/Assets/Models/Maps/a/front.jpg and /dev/null differ diff --git a/Assets/Models/Maps/a/left.jpg b/Assets/Models/Maps/a/left.jpg deleted file mode 100755 index 01eca00..0000000 Binary files a/Assets/Models/Maps/a/left.jpg and /dev/null differ diff --git a/Assets/Models/Maps/a/right.jpg b/Assets/Models/Maps/a/right.jpg deleted file mode 100755 index 4b45eea..0000000 Binary files a/Assets/Models/Maps/a/right.jpg and /dev/null differ diff --git a/Assets/Models/Maps/a/up.jpg b/Assets/Models/Maps/a/up.jpg deleted file mode 100755 index dc646c7..0000000 Binary files a/Assets/Models/Maps/a/up.jpg and /dev/null differ diff --git a/Assets/Models/Maps/a/water.jpg b/Assets/Models/Maps/a/water.jpg deleted file mode 100755 index 0d28b8a..0000000 Binary files a/Assets/Models/Maps/a/water.jpg and /dev/null differ diff --git a/Assets/Models/Maps/b/b.lua b/Assets/Models/Maps/b/b.lua index f5ddb31..4e014ce 100644 --- a/Assets/Models/Maps/b/b.lua +++ b/Assets/Models/Maps/b/b.lua @@ -1,6 +1,22 @@ map = { numWaterBodies = 1, impassibleNodeValue = 65535, + numPlayers = 2, + numSpawnPoints = 1, + spawnPoints = { + {x = 0, y = 0, z = 0} + }, + players = { + { + spawnPointId = 0, + numUnits = 0 + }, + { + spawnPointId = 0, + numUnits = 1, + units = {{id = 0, pos = {x = 0, y = 0, z = 0}, rot = {w = 1, x = 0, y = 0, z = 0}}} + } + }, terrain = { model = "b.xml", albedoMap = "b.jpg", @@ -16,10 +32,10 @@ weights = { } } }, - skybox = {left = "left.jpg", right = "right.jpg", up = "up.jpg", down = "down.jpg", front = "front.jpg", back = "back.jpg"}, + skybox = "Skybox1", waterBodies = { { - pos = {x = 0.0, y = -5.0, z = -0.0}, + pos = {x = 0.0, y = 0, z = -0.0}, size = {x = 81.36312866210938, y = 0, z = 81.36312866210938}, rect = true, albedoMap = "water.jpg", @@ -35,4 +51,4 @@ weights = { } } } -} \ No newline at end of file +} diff --git a/Assets/Models/Maps/b/b.xml b/Assets/Models/Maps/b/b.xml index 677653a..bd76562 100644 --- a/Assets/Models/Maps/b/b.xml +++ b/Assets/Models/Maps/b/b.xml @@ -1,5 +1,5 @@ - - + + @@ -71613,4 +71613,4 @@ - \ No newline at end of file + diff --git a/Assets/Models/Maps/b/back.jpg b/Assets/Models/Maps/b/back.jpg deleted file mode 100755 index fc8524a..0000000 Binary files a/Assets/Models/Maps/b/back.jpg and /dev/null differ diff --git a/Assets/Models/Maps/b/down.jpg b/Assets/Models/Maps/b/down.jpg deleted file mode 100755 index 57a084f..0000000 Binary files a/Assets/Models/Maps/b/down.jpg and /dev/null differ diff --git a/Assets/Models/Maps/b/front.jpg b/Assets/Models/Maps/b/front.jpg deleted file mode 100755 index aa0df39..0000000 Binary files a/Assets/Models/Maps/b/front.jpg and /dev/null differ diff --git a/Assets/Models/Maps/b/left.jpg b/Assets/Models/Maps/b/left.jpg deleted file mode 100755 index 01eca00..0000000 Binary files a/Assets/Models/Maps/b/left.jpg and /dev/null differ diff --git a/Assets/Models/Maps/b/right.jpg b/Assets/Models/Maps/b/right.jpg deleted file mode 100755 index 4b45eea..0000000 Binary files a/Assets/Models/Maps/b/right.jpg and /dev/null differ diff --git a/Assets/Models/Maps/b/up.jpg b/Assets/Models/Maps/b/up.jpg deleted file mode 100755 index dc646c7..0000000 Binary files a/Assets/Models/Maps/b/up.jpg and /dev/null differ diff --git a/Assets/Models/Maps/b/water.jpg b/Assets/Models/Maps/b/water.jpg deleted file mode 100755 index 0d28b8a..0000000 Binary files a/Assets/Models/Maps/b/water.jpg and /dev/null differ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b08430..5b2a724 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ set(CORE gameManager.cpp defConfigs.cpp ${CONTROLLERS}) set(PROJECTILES projectile.cpp) set(FX explosion.cpp) set(VEHICLES vehicle.cpp engineer.cpp) -set(UNITS unit.cpp structure.cpp ${VEHICLES}) +set(UNITS unitFactory.cpp unit.cpp structure.cpp ${VEHICLES}) set(CONTENT player.cpp pathfinder.cpp map.cpp ${UNITS} ${PROJECTILES} ${FX}) set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL}) diff --git a/consoleCommand.cpp b/consoleCommand.cpp index 580b139..99bb170 100755 --- a/consoleCommand.cpp +++ b/consoleCommand.cpp @@ -9,7 +9,7 @@ #include "consoleCommand.h" #include "inGameAppState.h" #include "player.h" -#include "engineer.h" +#include "unitFactory.h" using namespace std; using namespace vb01; @@ -70,20 +70,6 @@ namespace battleship{ void ConsoleCommand::executeAddUnit(int playerId, int unitId, Vector3 pos, Quaternion rot) { Player* player = Map::getSingleton()->getPlayer(playerId); - Vehicle *vehicle = nullptr; - - LuaManager *luaManager = LuaManager::getSingleton(); - int unitClass = luaManager->getIntFromTable("unitClass", vector{Index(unitId + 1)}); - - switch((UnitClass)unitClass){ - case UnitClass::ENGINEER: - vehicle = new Engineer(player, unitId, pos, rot); - break; - default: - vehicle = new Vehicle(player, unitId, pos, rot); - break; - } - - player->addUnit(vehicle); + player->addUnit(UnitFactory::createUnit(player, unitId, pos, rot)); } } diff --git a/inGameAppState.cpp b/inGameAppState.cpp index d4d772c..5d771c3 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include @@ -154,7 +156,7 @@ namespace battleship{ configData::calcSumBinds(AppStateType::IN_GAME_STATE, true), configData::calcSumBinds(AppStateType::IN_GAME_STATE, false), GameManager::getSingleton()->getPath() + "Scripts/options.lua"){ - this->playerId = 0; + this->playerId = 1; this->difficultyLevels = difficultyLevels; this->factions = factions; this->mapName = mapName; @@ -189,6 +191,10 @@ namespace battleship{ map->addPlayer(p); } + Camera *cam = Root::getSingleton()->getCamera(); + cam->setPosition(map->getSpawnPoint(playerId - 1) + Vector3(1, 1, 1) * 40); + cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); + mainPlayer = map->getPlayer(playerId); GameManager *gm = GameManager::getSingleton(); @@ -196,10 +202,6 @@ namespace battleship{ guiState = ((GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE)); activeState = new ActiveGameState(guiState, playerId); stateManager->attachAppState(activeState); - - AssetManager *assetManager = AssetManager::getSingleton(); - assetManager->load(DEFAULT_TEXTURE); - assetManager->load(gm->getPath() + LuaManager::getSingleton()->getString("modelPrefix"), true); } void InGameAppState::onDettached() {} diff --git a/map.cpp b/map.cpp index 6a10f95..eed8b6d 100755 --- a/map.cpp +++ b/map.cpp @@ -8,6 +8,7 @@ #include "map.h" #include "player.h" +#include "unitFactory.h" #include "pathfinder.h" #include "gameManager.h" #include "defConfigs.h" @@ -33,16 +34,20 @@ namespace battleship{ p->update(); } - void Map::loadSkybox(LuaManager *luaManager){ - int numPaths = 6; - string skyTable = "skybox", basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; - string path[] = { - basePath + luaManager->getStringFromTable(mapTable, vector{Index(skyTable), Index("left")}), - basePath + luaManager->getStringFromTable(mapTable, vector{Index(skyTable), Index("right")}), - basePath + luaManager->getStringFromTable(mapTable, vector{Index(skyTable), Index("up")}), - basePath + luaManager->getStringFromTable(mapTable, vector{Index(skyTable), Index("down")}), - basePath + luaManager->getStringFromTable(mapTable, vector{Index(skyTable), Index("front")}), - basePath + luaManager->getStringFromTable(mapTable, vector{Index(skyTable), Index("back")}) + void Map::loadSkybox(){ + LuaManager *lm = LuaManager::getSingleton(); + + string skyboxName = lm->getStringFromTable(mapTable, vector{Index("skybox")}); + string basePath = GameManager::getSingleton()->getPath() + "Textures/Skyboxes/" + skyboxName; + + const int numPaths = 6; + string path[numPaths] = { + basePath + "/left.jpg", + basePath + "/right.jpg", + basePath + "/up.jpg", + basePath + "/down.jpg", + basePath + "/front.jpg", + basePath + "/back.jpg" }; for(int i = 0; i < numPaths; i++) @@ -51,7 +56,8 @@ namespace battleship{ Root::getSingleton()->createSkybox(path); } - void Map::loadTerrainObject(LuaManager *luaManager, int id){ + void Map::loadTerrainObject(int id){ + LuaManager *luaManager = LuaManager::getSingleton(); string terrainTable = (id == -1 ? "terrain" : "waterBodies"); vector baseIndices = (id == -1 ? vector{Index(terrainTable)} : vector{Index(terrainTable), Index(id + 1)}); Vector3 pos = Vector3::VEC_ZERO, size = Vector3::VEC_ZERO; @@ -137,14 +143,23 @@ namespace battleship{ Node *node = nullptr; Quad *quad = nullptr; TerrainObject::Type type; - string basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; + string basePath = GameManager::getSingleton()->getPath(); + string texPath = basePath; + //TODO remove this quick fix for landmass model loading if(id == -1){ type = TerrainObject::LANDMASS; - string terrainFile = basePath + luaManager->getStringFromTable(mapTable, vector{terrInd, Index("model")}); + string mapPathSuffix = "Models/Maps/" + mapName + "/"; + texPath += mapPathSuffix; + string terrainFile = basePath + mapPathSuffix + luaManager->getStringFromTable(mapTable, vector{terrInd, Index("model")}); + AssetManager::getSingleton()->load(terrainFile); - node = new Model(terrainFile); + node = (Model*)((new Model(terrainFile))->getChild(0)); + + Node *par = node->getParent(); + par->dettachChild(node); + delete par; } else{ type = TerrainObject::RECT_WATERBODY; @@ -152,6 +167,8 @@ namespace battleship{ quad = new Quad(Vector3(size.x, size.z, 1), true); node->attachMesh(quad); node->setOrientation(Quaternion(-1.57, Vector3::VEC_I)); + + texPath += "Textures/Water/"; } nodeParent->attachChild(node); @@ -163,7 +180,9 @@ namespace battleship{ ind = baseIndices; ind.push_back(Index("albedoMap")); - string fr[]{basePath + luaManager->getStringFromTable(mapTable, ind)}; + texPath += luaManager->getStringFromTable(mapTable, ind); + + string fr[]{texPath}; AssetManager::getSingleton()->load(fr[0]); Texture *t = new Texture(fr, 1, false); @@ -177,6 +196,54 @@ namespace battleship{ 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("numSpawnPoints")}); + string spawnPointInd = "spawnPoints"; + + for(int i = 0; i < numSpawnPoints; i++){ + float x = lm->getFloatFromTable(mapTable, vector{Index(spawnPointInd), Index(i + 1), Index("x")}); + float y = lm->getFloatFromTable(mapTable, vector{Index(spawnPointInd), Index(i + 1), Index("y")}); + float z = lm->getFloatFromTable(mapTable, vector{Index(spawnPointInd), Index(i + 1), Index("z")}); + spawnPoints.push_back(Vector3(x, y, z)); + } + } + + //TODO simplify the dubplicatory field extraction statements + void Map::loadPlayers(){ + AssetManager *assetManager = AssetManager::getSingleton(); + assetManager->load(DEFAULT_TEXTURE); + LuaManager *lm = LuaManager::getSingleton(); + assetManager->load(GameManager::getSingleton()->getPath() + lm->getString("modelPrefix"), true); + + int numPlayers = lm->getIntFromTable(mapTable, vector{Index("numPlayers")}); + string playerInd = "players", unitInd = "units", spawnPointInd = "spawnPointId", posInd = "pos", rotInd = "rot"; + + for(int i = 0; i < numPlayers; i++){ + int spawnPointId = lm->getIntFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index(spawnPointId)}); + int numUnits = lm->getIntFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index("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(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(posInd), Index("x")}); + float posY = lm->getFloatFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(posInd), Index("y")}); + float posZ = lm->getFloatFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(posInd), Index("z")}); + Vector3 pos = Vector3(posX, posY, posZ); + + float rotW = lm->getFloatFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(rotInd), Index("w")}); + float rotX = lm->getFloatFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(rotInd), Index("x")}); + float rotY = lm->getFloatFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(rotInd), Index("y")}); + float rotZ = lm->getFloatFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index(unitInd), Index(j + 1), Index(rotInd), Index("z")}); + Quaternion rot = Quaternion(rotW, rotX, rotY, rotZ); + + int id = lm->getIntFromTable(mapTable, vector{Index(playerInd), Index(i + 1), Index(unitInd), Index("id")}); + + players[i]->addUnit(UnitFactory::createUnit(players[i], id, pos, rot)); + } + } + } + void Map::preprareScene(){ nodeParent = new Node(); Root *root = Root::getSingleton(); @@ -199,11 +266,13 @@ namespace battleship{ lm->buildScript(vector{GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua"}); int numWaterbodies = lm->getIntFromTable(mapTable, vector{Index("numWaterBodies")}); - loadSkybox(lm); - loadTerrainObject(lm, -1); + loadSpawnPoints(); + loadPlayers(); + loadSkybox(); + loadTerrainObject(-1); for(int i = 0; i < numWaterbodies; i++) - loadTerrainObject(lm, i); + loadTerrainObject(i); } } diff --git a/map.h b/map.h index 0c15dc7..d2ff1ab 100755 --- a/map.h +++ b/map.h @@ -66,18 +66,23 @@ namespace battleship{ inline Player* getPlayer(int i){return players[i];} inline void addPlayer(Player *p){players.push_back(p);} inline int getNumPlayers(){return players.size();} + inline vb01::Vector3 getSpawnPoint(int i){return spawnPoints[i];} + inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);} private: std::string mapTable = "map"; vb01::Node *nodeParent = nullptr; std::string mapName; std::vector terrainObjects; vb01::Vector3 cellSize; + std::vector spawnPoints; std::vector players; Map(){} void preprareScene(); - void loadSkybox(gameBase::LuaManager*); - void loadTerrainObject(gameBase::LuaManager*, int); + void loadSpawnPoints(); + void loadPlayers(); + void loadSkybox(); + void loadTerrainObject(int); }; } diff --git a/unitFactory.cpp b/unitFactory.cpp new file mode 100644 index 0000000..46d83be --- /dev/null +++ b/unitFactory.cpp @@ -0,0 +1,32 @@ +#include "unitFactory.h" +#include "player.h" +#include "vehicle.h" +#include "engineer.h" + +#include + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace gameBase; + + Unit* UnitFactory::createUnit(Player *player, int id, Vector3 pos, Quaternion rot){ + Unit *unit = nullptr; + + LuaManager *luaManager = LuaManager::getSingleton(); + int unitClass = luaManager->getIntFromTable("unitClass", vector{Index(id + 1)}); + + switch((UnitClass)unitClass){ + case UnitClass::ENGINEER: + unit = new Engineer(player, id, pos, rot); + break; + default: + unit = new Vehicle(player, id, pos, rot); + break; + } + + return unit; + } +} diff --git a/unitFactory.h b/unitFactory.h new file mode 100644 index 0000000..79b3524 --- /dev/null +++ b/unitFactory.h @@ -0,0 +1,18 @@ +#ifndef UNIT_FACTORY_H +#define UNIT_FACTORY_H + +#include +#include + +namespace battleship{ + class Unit; + class Player; + + class UnitFactory{ + public: + static Unit* createUnit(Player*, int, vb01::Vector3, vb01::Quaternion); + private: + }; +} + +#endif