From 80dc5503be2552ce422ba7b1fc9d814e5514324b Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 19 Aug 2023 15:05:01 +0300 Subject: [PATCH] removed TerrainObject struct --- activeGameState.cpp | 2 ++ landTextureListbox.cpp | 2 +- map.cpp | 27 ++++---------------- map.h | 55 +++++++++++++---------------------------- mapEditorAppState.cpp | 36 ++++++++++++++++++++++----- mapEditorAppState.h | 11 ++++----- player.cpp | 6 ++--- unitFrameController.cpp | 4 +-- vehicle.cpp | 6 +++++ 9 files changed, 70 insertions(+), 79 deletions(-) diff --git a/activeGameState.cpp b/activeGameState.cpp index c9815cf..3dd9a7a 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -276,6 +276,7 @@ namespace battleship{ Map *map = Map::getSingleton(); + /* for(Unit *u : mainPlayer->getSelectedUnits()) if(u->getType() == UnitType::UNDERWATER){ for(int i = 1; i < map->getNumTerrainObjects(); i++){ @@ -289,6 +290,7 @@ namespace battleship{ } } } + */ targets.push_back(Order::Target((it != unitData.end() ? unitData[node] : unit), results[0].pos)); } diff --git a/landTextureListbox.cpp b/landTextureListbox.cpp index e831f26..64a1dba 100644 --- a/landTextureListbox.cpp +++ b/landTextureListbox.cpp @@ -22,7 +22,7 @@ namespace battleship{ MapEditorAppState::MapEditor *mapEditor = ((MapEditorAppState*)sm->getAppStateByType((int)AppStateType::MAP_EDITOR))->getMapEditor(); Map *map = Map::getSingleton(); - Material *mat = map->getTerrainObject(0).node->getMesh(0)->getMaterial(); + Material *mat = map->getNodeParent()->getChild(0)->getMesh(0)->getMaterial(); Material::BoolUniform *texturingUniform = (Material::BoolUniform*)mat->getUniform("texturingEnabled"); Texture *landTex = mapEditor->getLandmassTexture(selectedOption); string texUni = "textures[0]"; diff --git a/map.cpp b/map.cpp index d8762ca..7be13a6 100755 --- a/map.cpp +++ b/map.cpp @@ -240,9 +240,9 @@ namespace battleship{ } void Map::preprareScene(){ - nodeParent = new Node(); + terrainNode = new Node(); Root *root = Root::getSingleton(); - root->getRootNode()->attachChild(nodeParent); + root->getRootNode()->attachChild(terrainNode); Camera *cam = root->getCamera(); cam->setPosition(Vector3(1, 1, 1) * 40); @@ -251,7 +251,6 @@ namespace battleship{ void Map::load(string mapName, bool empty) { this->mapName = mapName; - cellSize = Vector3(7, 6, 7); Pathfinder::getSingleton()->setImpassibleNodeVal(u16(0 - 1)); preprareScene(); @@ -274,6 +273,7 @@ namespace battleship{ void Map::unload() {} int Map::getCellId(Vector3 pos, int id){ + /* Vector3 regionSize = terrainObjects[id].size; Vector3 regionPos = terrainObjects[id].pos; Vector3 cellSize = terrainObjects[id].cellSize; @@ -287,24 +287,7 @@ namespace battleship{ int z = fabs(pos.z - initPos.z) / cellSize.z; return (numCellsX * numCellsZ * y + (numCellsX * z + x)); - } - - bool Map::isPointWithinTerrainObject(Vector3 p, int id){ - bool within; - Vector3 pos = terrainObjects[id].pos, size = terrainObjects[id].size; - - if(terrainObjects[id].type == TerrainObject::RECT_WATERBODY) - within = (fabs(pos.x - p.x) < 0.5 * size.x && fabs(pos.z - p.z) < 0.5 * size.z); - else if(terrainObjects[id].type == TerrainObject::ROUND_WATERBODY) - within = Vector2(pos.x, pos.z).getDistanceFrom(Vector2(p.x, p.z)) < size.x; - else - within = true; - - return within; - } - - void Map::addTerrainObject(TerrainObject obj){ - nodeParent->attachChild(obj.node); - terrainObjects.push_back(obj); + */ + return 0; } } diff --git a/map.h b/map.h index 4aad4cd..993228b 100755 --- a/map.h +++ b/map.h @@ -8,10 +8,6 @@ #include #include -namespace gameBase{ - class LuaManager; -} - namespace vb01{ class Model; class Node; @@ -19,35 +15,22 @@ namespace vb01{ namespace battleship{ class Player; + struct Cell; - struct Cell{ - bool land, impassible; - vb01::Vector3 pos; - - Cell(){} - Cell(vb01::Vector3 p, bool l, bool i): pos(p), land(l), impassible(i){} + struct Edge{ + Cell *cellA, *cellB; + int weight; }; - struct TerrainObject{ - enum Type{LANDMASS, RECT_WATERBODY, ROUND_WATERBODY}; - vb01::Vector3 pos, size, cellSize; - Type type; - vb01::Node *node = nullptr; - std::vector cellMarkers; - int numCells; - Cell *cells = nullptr; - vb01::u32 **weights = nullptr; + struct Cell{ + enum Type{LAND, WATER}; - TerrainObject(){} - TerrainObject(vb01::Vector3 p, vb01::Vector3 s, vb01::Vector3 cs, Type t, vb01::Node *n, int num, Cell *c, vb01::u32 **w) : - pos(p), - size(s), - cellSize(cs), - type(t), - node(n), - numCells(num), - cells(c), - weights(w){} + Type type; + vb01::Vector3 pos; + std::vector edges; + + Cell(){} + Cell(vb01::Vector3 p, Type t): pos(p), type(t){} }; class Map { @@ -59,13 +42,9 @@ namespace battleship{ void unload(); int getCellId(vb01::Vector3, int); bool isPointWithinTerrainObject(vb01::Vector3, int); - void addTerrainObject(TerrainObject); inline std::string getMapName(){return mapName;} - inline TerrainObject& getTerrainObject(int i){return terrainObjects[i];} - inline int getNumTerrainObjects(){return terrainObjects.size();} - inline vb01::Node* getNodeParent(){return nodeParent;} - inline vb01::Vector3 getCellSize(){return cellSize;} - inline std::vector& getTerrainObjects(){return terrainObjects;} + inline vb01::Node* getNodeParent(){return terrainNode;} + inline vb01::Vector3 getCellSize(){return CELL_SIZE;} inline std::vector getPlayers() {return players;} inline Player* getPlayer(int i){return players[i];} inline void addPlayer(Player *p){players.push_back(p);} @@ -75,12 +54,12 @@ namespace battleship{ inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);} private: std::string mapTable = "map"; - vb01::Node *nodeParent = nullptr; + vb01::Node *terrainNode = nullptr; std::string mapName; - std::vector terrainObjects; - vb01::Vector3 cellSize; + vb01::Vector3 CELL_SIZE = vb01::Vector3(7, 7, 7); std::vector spawnPoints; std::vector players; + std::vector cells; Map(){} void preprareScene(); diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 2a00eb9..0a480a5 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -67,12 +67,15 @@ namespace battleship{ circleRadius = MIN_RADIUS; } + /* void MapEditorAppState::MapEditor::toggleSelection(TerrainObject *obj, bool select){ obj->node->getMesh(0)->setWireframe(select); selectedTerrainObject = (select ? obj : nullptr); } + */ void MapEditorAppState::MapEditor::castSelectionRay(){ + /* Camera *cam = Root::getSingleton()->getCamera(); Vector3 startPos = cam->getPosition(); Vector3 endPos = screenToSpace(getCursorPos()); @@ -92,9 +95,11 @@ namespace battleship{ break; } } + */ } void MapEditorAppState::MapEditor::createWaterbody(){ + /* Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); mat->addBoolUniform("lightingEnabled", false); mat->addBoolUniform("texturingEnabled", true); @@ -118,10 +123,11 @@ namespace battleship{ prepareTerrainObjects(objId - 1, 1); prepareCellMarkers(obj); + */ } void MapEditorAppState::MapEditor::moveTerrainObject(float strength){ - Vector3 pos = selectedTerrainObject->node->getPosition(); + Vector3 pos = selectedTerrainNode->getPosition(); switch(movementAxis){ case MovementAxis::X_AXIS: @@ -135,12 +141,11 @@ namespace battleship{ break; } - selectedTerrainObject->node->setPosition(pos); - selectedTerrainObject->pos = pos; + selectedTerrainNode->setPosition(pos); } void MapEditorAppState::MapEditor::pushLandmassVerts(float strength){ - Mesh *mesh = map->getTerrainObject(0).node->getMesh(0); + Mesh *mesh = map->getNodeParent()->getChild(0)->getMesh(0); MeshData meshData = mesh->getMeshBase(); MeshData::Vertex *verts = meshData.vertices; int numVerts = meshData.numTris * 3; @@ -169,13 +174,16 @@ namespace battleship{ Node *node = new Node(); node->attachMesh(mesh); + map->getNodeParent()->attachChild(node); + /* TerrainObject::Type type = TerrainObject::LANDMASS; Vector3 pos = Vector3::VEC_ZERO, s = Vector3(size.x, 0, size.y); map->addTerrainObject(TerrainObject(pos, s, Vector3(14, 6, 14), type, node, 0, nullptr, nullptr)); prepareTerrainObjects(0, 1); prepareCellMarkers(map->getTerrainObject(0)); + */ } void MapEditorAppState::MapEditor::prepareTextures(string basePath, bool skybox, vector &textures){ @@ -227,7 +235,7 @@ namespace battleship{ XMLNode *nodeTag = rootTag->InsertEndChild(nodeEl); XMLElement *meshEl = doc->NewElement("mesh"); - MeshData meshData = map->getTerrainObject(0).node->getMesh(0)->getMeshBase(); + MeshData meshData; meshEl->SetAttribute("name", "mesh"); meshEl->SetAttribute("num_faces", meshData.numTris); meshEl->SetAttribute("num_vertex_groups", 0); @@ -275,6 +283,7 @@ namespace battleship{ } void MapEditorAppState::MapEditor::prepareTerrainObject(u32 **weights, Cell *cells, int cellsByDim[3], float height, bool land){ + /* const int numCells = cellsByDim[0] * cellsByDim[1] * cellsByDim[2]; Vector3 initPos = -.5 * Vector3(mapSize.x, -height, mapSize.y); @@ -371,9 +380,11 @@ namespace battleship{ weights[i][j] = 1; } } + */ } void MapEditorAppState::MapEditor::prepareTerrainObjects(int startId, int numObjs){ + /* if(numObjs == -1) numObjs = map->getNumTerrainObjects(); @@ -400,8 +411,10 @@ namespace battleship{ prepareTerrainObject(weights, cells, cellsByDim, (i > 0 ? obj.pos.y : 0), i == 0); } + */ } + /* string MapEditorAppState::MapEditor::parseTerrainObject(TerrainObject &terrObj){ string terrObjStr = "{\n"; @@ -435,8 +448,10 @@ namespace battleship{ return terrObjStr; } + */ void MapEditorAppState::MapEditor::parseMapScript(){ + /* int numTerrObjs = map->getNumTerrainObjects(); string mapScript = "map = {\nnumWaterBodies = " + to_string(numTerrObjs) + ",\n"; mapScript += "impassibleNodeValue = " + to_string(IMPASS_NODE_VAL) + ",\n"; @@ -510,16 +525,20 @@ namespace battleship{ std::ofstream outFile(file); outFile << mapScript; outFile.close(); + */ } void MapEditorAppState::MapEditor::toggleCellMarkers(){ + /* cellMarkersVisible = !cellMarkersVisible; for(TerrainObject &obj : map->getTerrainObjects()) for(Node *cellMarker : obj.cellMarkers) cellMarker->setVisible(cellMarkersVisible); + */ } + /* void MapEditorAppState::MapEditor::prepareCellMarkers(TerrainObject &obj){ Root *root = Root::getSingleton(); Node *rootNode = root->getRootNode(); @@ -540,6 +559,7 @@ namespace battleship{ obj.cellMarkers.push_back(cellMarker); } } + */ void MapEditorAppState::MapEditor::exportMap(){ string assetsPath = GameManager::getSingleton()->getPath(); @@ -635,7 +655,7 @@ namespace battleship{ Vector3 endPos = screenToSpace(cursorPos); vector results; - Ray::retrieveCollisions(startPos, (endPos - startPos).norm(), Map::getSingleton()->getTerrainObject(0).node, results); + Ray::retrieveCollisions(startPos, (endPos - startPos).norm(), Root::getSingleton()->getRootNode(), results); Ray::sortResults(results); @@ -658,12 +678,14 @@ namespace battleship{ case Bind::CREATE_WATERBODY: if(isPressed) mapEditor->createWaterbody(); break; + /* case Bind::MOVE_TERR_OBJ: if(isPressed) mapEditor->setMovingTerrainObject(true); break; case Bind::STOP_TERR_OBJ: if(isPressed) mapEditor->setMovingTerrainObject(false); break; + */ case Bind::MOVE_X_AXIS: case Bind::MOVE_Y_AXIS: case Bind::MOVE_Z_AXIS: @@ -701,6 +723,7 @@ namespace battleship{ camCtr->orientCamera(Vector3(0, 1, 0), strength); break; + /* case Bind::PUSH_VERTS_UP: case Bind::PUSH_VERTS_DOWN: if(mapEditor->isPushing()) mapEditor->pushLandmassVerts(strength); @@ -708,6 +731,7 @@ namespace battleship{ mapEditor->moveTerrainObject(strength); break; + */ } } } diff --git a/mapEditorAppState.h b/mapEditorAppState.h index 7a17369..f0f630c 100644 --- a/mapEditorAppState.h +++ b/mapEditorAppState.h @@ -18,7 +18,6 @@ namespace vb01{ namespace battleship{ class MapEditor; - class TerrainObject; class MapEditorAppState : public gameBase::AbstractAppState{ public: @@ -39,7 +38,7 @@ namespace battleship{ void exportMap(); void prepareTerrainObjects(int = 0, int = -1); void toggleCellMarkers(); - inline TerrainObject* getSelectedTerrainObject(){return selectedTerrainObject;} + inline vb01::Node* getSelectedNode(){return selectedTerrainNode;} inline float getGuiThreshold(){return guiThreshold;} inline float getCircleRadius(){return circleRadius;} inline bool isPushing(){return pushing;} @@ -55,16 +54,16 @@ namespace battleship{ private: void generatePlane(vb01::Vector2); void prepareTextures(std::string, bool, std::vector&); - void toggleSelection(TerrainObject*, bool); + //void toggleSelection(TerrainObject*, bool); void parseLandmass(); - std::string parseTerrainObject(TerrainObject&); + //std::string parseTerrainObject(TerrainObject&); void parseMapScript(); void deleteWeights(); void prepareTerrainObject(vb01::u32**, Cell*, int[3], float, bool); - void prepareCellMarkers(TerrainObject&); + //void prepareCellMarkers(TerrainObject&); Map *map; - TerrainObject *selectedTerrainObject = nullptr; + vb01::Node *selectedTerrainNode = nullptr; MovementAxis movementAxis = X_AXIS; vb01Gui::Listbox *skyListbox = nullptr; bool pushing = false, movingTerrainObject = false, weightsGenerated = false, newMap, cellMarkersVisible = false; diff --git a/player.cpp b/player.cpp index dc81dba..8076040 100755 --- a/player.cpp +++ b/player.cpp @@ -13,16 +13,14 @@ namespace battleship{ this->spawnPoint = spawnPoint; this->id = id; - sol::state_view SOL_LUA_STATE = generateView(); - SOL_LUA_STATE.script("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() { - sol::state_view SOL_LUA_STATE = generateView(); - SOL_LUA_STATE.script("players[" + to_string(id + 1) + "]:update()"); + //SOL_LUA_STATE.script("players[" + to_string(id + 1) + "]:update()"); for(Unit *u : units) u->update(); diff --git a/unitFrameController.cpp b/unitFrameController.cpp index e73db16..0427bcf 100644 --- a/unitFrameController.cpp +++ b/unitFrameController.cpp @@ -43,7 +43,7 @@ namespace battleship{ //TODO implement terrain evenness check void UnitFrameController::update(){ Map *map = Map::getSingleton(); - MeshData meshData = map->getTerrainObject(0).node->getMesh(0)->getMeshBase(); + MeshData meshData; MeshData::Vertex *verts = meshData.vertices; int numVerts = 3 * meshData.numTris; @@ -56,7 +56,7 @@ namespace battleship{ for(UnitFrame &s : unitFrames){ vector results; - Ray::retrieveCollisions(startPos, (endPos - startPos).norm(), map->getTerrainObject(0).node, results); + Ray::retrieveCollisions(startPos, (endPos - startPos).norm(), map->getNodeParent()->getChild(0), results); Ray::sortResults(results); if(!results.empty()){ diff --git a/vehicle.cpp b/vehicle.cpp index f627c78..1b66bb7 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -108,6 +108,7 @@ namespace battleship{ } void Vehicle::alignToSurface(){ + /* Map *map = Map::getSingleton(); TerrainObject terr = map->getTerrainObject(0); vector res; @@ -122,6 +123,7 @@ namespace battleship{ Quaternion rotQuat = Quaternion(angle, axis); orientUnit(rotQuat * rot); } + */ } void Vehicle::move(Order order) { @@ -138,6 +140,7 @@ namespace battleship{ int srcObjId = 0, destObjId = 0; Map *map = Map::getSingleton(); + /* for(int i = 1; i < map->getNumTerrainObjects(); i++){ if(map->isPointWithinTerrainObject(pos, i)) srcObjId = i; @@ -145,6 +148,7 @@ namespace battleship{ if(map->isPointWithinTerrainObject(order.targets[0].pos, i)) destObjId = i; } + */ if(srcObjId != destObjId) return; @@ -152,6 +156,7 @@ namespace battleship{ int source = map->getCellId(pos, srcObjId); int dest = map->getCellId(order.targets[0].pos, destObjId); + /* Pathfinder *pathfinder = Pathfinder::getSingleton(); u32 **weights = map->getTerrainObject(srcObjId).weights; vector path = pathfinder->findPath(weights, map->getTerrainObject(srcObjId).numCells, source, dest); @@ -166,5 +171,6 @@ namespace battleship{ if(!(impassibleNodePresent || path.empty())) for(int p : path) pathPoints.push_back(map->getTerrainObject(srcObjId).cells[p].pos); + */ } }