Merge branch 'develop' into bf-2-pathfinding

This commit is contained in:
devZoGok
2023-09-10 11:38:19 +03:00
4 changed files with 100 additions and 41 deletions
+8 -7
View File
@@ -48,13 +48,14 @@ mappings = {
{bind = 36, trigger = 312, action = false, bindType = 2, inOptions = false},
{bind = 37, trigger = 313, action = false, bindType = 2, inOptions = false},
{bind = 38, trigger = 71, action = true, bindType = 0, inOptions = false},
{bind = 39, trigger = 256, action = true, bindType = 0, inOptions = false},
{bind = 40, trigger = 90, action = true, bindType = 0, inOptions = false},
{bind = 41, trigger = 89, action = true, bindType = 0, inOptions = false},
{bind = 42, trigger = 88, action = true, bindType = 0, inOptions = false},
{bind = 43, trigger = 87, action = true, bindType = 0, inOptions = false},
{bind = 44, trigger = 72, action = true, bindType = 0, inOptions = false},
{bind = 45, trigger = 68, action = true, bindType = 0, inOptions = false},
{bind = 39, trigger = 83, action = true, bindType = 0, inOptions = false},
{bind = 40, trigger = 256, action = true, bindType = 0, inOptions = false},
{bind = 41, trigger = 90, action = true, bindType = 0, inOptions = false},
{bind = 42, trigger = 89, action = true, bindType = 0, inOptions = false},
{bind = 43, trigger = 88, action = true, bindType = 0, inOptions = false},
{bind = 44, trigger = 87, action = true, bindType = 0, inOptions = false},
{bind = 45, trigger = 72, action = true, bindType = 0, inOptions = false},
{bind = 46, trigger = 68, action = true, bindType = 0, inOptions = false},
}
graphics = {
resolution = {x = 1920, y = 1080}
+4 -3
View File
@@ -42,10 +42,11 @@ namespace battleship{
PUSH_VERTS_UP,
PUSH_VERTS_DOWN,
MOVE_TERR_OBJ,
SCALE_TERR_OBJ,
STOP_TERR_OBJ,
MOVE_X_AXIS,
MOVE_Y_AXIS,
MOVE_Z_AXIS,
ENABLE_X_AXIS,
ENABLE_Y_AXIS,
ENABLE_Z_AXIS,
CREATE_WATERBODY,
GENERATE_WEIGHTS,
TOGGLE_CELL_MARKERS
+78 -25
View File
@@ -118,28 +118,52 @@ namespace battleship{
}
void MapEditorAppState::MapEditor::moveTerrainObject(float strength){
Vector3 pos = selectedTerrainNode->getPosition();
if(fabs(strength) < .00001) return;
switch(movementAxis){
case MovementAxis::X_AXIS:
pos += strength * Vector3::VEC_I;
Vector3 axis;
switch(transformAxis){
case TransformAxis::X_AXIS:
axis = Vector3::VEC_I;
break;
case MovementAxis::Y_AXIS:
pos += strength * Vector3::VEC_J;
case TransformAxis::Y_AXIS:
axis = -Vector3::VEC_J;
break;
case MovementAxis::Z_AXIS:
pos += strength * Vector3::VEC_K;
case TransformAxis::Z_AXIS:
axis = Vector3::VEC_K;
break;
}
Vector3 pos = selectedTerrainNode->getPosition() + 10 * strength * axis;
selectedTerrainNode->setPosition(pos);
}
void MapEditorAppState::MapEditor::scaleTerrainObject(float strength){
if(fabs(strength) < .00001) return;
Vector2 axis;
switch(transformAxis){
case TransformAxis::X_AXIS:
axis = Vector2::VEC_I;
break;
case TransformAxis::Z_AXIS:
axis = Vector2::VEC_J;
break;
}
Quad *quad = (Quad*)selectedTerrainNode->getMesh(0);
Vector3 size = quad->getSize() + 10 * strength * Vector3(axis.x, axis.y, 0);
quad->setSize(Vector3(size.x, size.y, 1));
quad->updateVerts(quad->getMeshBase());
}
void MapEditorAppState::MapEditor::pushLandmassVerts(float strength){
Mesh *mesh = map->getNodeParent()->getChild(0)->getMesh(0);
MeshData meshData = mesh->getMeshBase();
MeshData::Vertex *verts = meshData.vertices;
int numVerts = meshData.numTris * 3;
pushPos.y += 10 * strength;
for(int i = 0; i < numVerts; i++){
Vector3 distVec = verts[i].pos - pushPos;
@@ -147,7 +171,7 @@ namespace battleship{
float dist = distVec.getLength();
if(dist < circleRadius)
verts[i].pos.y += 10 * strength * dist / circleRadius;
verts[i].pos.y = oldLandmassVertHeights[i] + pushPos.y - (pushPos.y / circleRadius) * dist;
}
mesh->updateVerts(meshData);
@@ -166,6 +190,8 @@ namespace battleship{
Node *node = new Node();
node->attachMesh(mesh);
map->getNodeParent()->attachChild(node);
oldLandmassVertHeights = new float[3 * mesh->getMeshBase().numTris];
}
void MapEditorAppState::MapEditor::prepareTextures(string basePath, bool skybox, vector<Texture*> &textures){
@@ -488,6 +514,18 @@ namespace battleship{
generateMapScript();
}
void MapEditorAppState::MapEditor::togglePush(bool push){
this->pushing = push;
if(push){
MeshData meshData = map->getNodeParent()->getChild(0)->getMesh(0)->getMeshBase();
int numVerts = 3 * meshData.numTris;
for(int i = 0; i < numVerts; i++)
oldLandmassVertHeights[i] = meshData.vertices[i].pos.y;
}
}
MapEditorAppState::MapEditorAppState(string name, Vector2 size, bool newMap) : AbstractAppState(
AppStateType::MAP_EDITOR,
configData::calcSumBinds(AppStateType::MAP_EDITOR, true),
@@ -574,10 +612,9 @@ namespace battleship{
Ray::retrieveCollisions(startPos, (endPos - startPos).norm(), Root::getSingleton()->getRootNode(), results);
Ray::sortResults(results);
if(cursorPos.y < GameManager::getSingleton()->getHeight() - mapEditor->getGuiThreshold()){
bool push = !results.empty();
mapEditor->setPushing(push);
mapEditor->togglePush(push);
if(push)
mapEditor->setPushPos(results[0].pos);
@@ -585,27 +622,39 @@ namespace battleship{
mapEditor->castSelectionRay();
}
else
mapEditor->setPushing(false);
mapEditor->togglePush(false);
}
else
mapEditor->setPushing(false);
mapEditor->togglePush(false);
break;
case Bind::CREATE_WATERBODY:
if(isPressed) mapEditor->createWaterbody();
break;
case Bind::MOVE_TERR_OBJ:
if(isPressed) mapEditor->setMovingTerrainObject(true);
break;
if(isPressed){
mapEditor->setMovingTerrainObject(true);
mapEditor->setScalingTerrainObject(false);
break;
}
case Bind::SCALE_TERR_OBJ:
if(isPressed){
mapEditor->setMovingTerrainObject(false);
mapEditor->setScalingTerrainObject(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:
if(isPressed && mapEditor->isMovingTerrainObject()){
MapEditor::MovementAxis axis = MapEditor::MovementAxis((int)bind - (int)Bind::MOVE_X_AXIS);
mapEditor->setMovementAxis(axis);
if(isPressed){
mapEditor->setMovingTerrainObject(false);
mapEditor->setScalingTerrainObject(false);
break;
}
case Bind::ENABLE_X_AXIS:
case Bind::ENABLE_Y_AXIS:
case Bind::ENABLE_Z_AXIS:
if(isPressed && (mapEditor->isMovingTerrainObject() || mapEditor->isScalingTerrainObject())){
MapEditor::TransformAxis axis = MapEditor::TransformAxis((int)bind - (int)Bind::ENABLE_X_AXIS);
mapEditor->setTransformAxis(axis);
}
break;
@@ -634,8 +683,12 @@ namespace battleship{
case Bind::PUSH_VERTS_UP:
case Bind::PUSH_VERTS_DOWN:
if(mapEditor->isPushing()) mapEditor->pushLandmassVerts(strength);
else if(mapEditor->isMovingTerrainObject() && mapEditor->getSelectedNode() != Map::getSingleton()->getNodeParent()->getChild(0))
mapEditor->moveTerrainObject(strength);
else if(mapEditor->getSelectedNode() != Map::getSingleton()->getNodeParent()->getChild(0)){
if(mapEditor->isScalingTerrainObject())
mapEditor->scaleTerrainObject(strength);
else if(mapEditor->isMovingTerrainObject())
mapEditor->moveTerrainObject(strength);
}
break;
}
+10 -6
View File
@@ -23,7 +23,7 @@ namespace battleship{
public:
class MapEditor{
public:
enum MovementAxis{
enum TransformAxis{
X_AXIS,
Y_AXIS,
Z_AXIS
@@ -35,18 +35,21 @@ namespace battleship{
void castSelectionRay();
void createWaterbody();
void moveTerrainObject(float);
void scaleTerrainObject(float);
void exportMap();
void prepareTerrainObjects(int = 0, int = -1);
void togglePush(bool);
inline vb01::Node* getSelectedNode(){return selectedTerrainNode;}
inline float getGuiThreshold(){return guiThreshold;}
inline float getCircleRadius(){return circleRadius;}
inline bool isPushing(){return pushing;}
inline void setPushing(bool p){pushing = p;}
inline void setPushPos(vb01::Vector3 p){pushPos = p;}
inline bool isMovingTerrainObject(){return movingTerrainObject;}
inline void setMovingTerrainObject(bool m){movingTerrainObject = m;}
inline MovementAxis getMovementAxis(){return movementAxis;}
inline void setMovementAxis(MovementAxis m){movementAxis = m;}
inline bool isScalingTerrainObject(){return scalingTerrainObject;}
inline void setScalingTerrainObject(bool s){scalingTerrainObject = s;}
inline TransformAxis getTransformAxis(){return transformAxis;}
inline void setTransformAxis(TransformAxis m){transformAxis = m;}
inline bool isWeightsGenerated(){return weightsGenerated;}
inline vb01::Texture* getSkyTexture(int i){return skyTextures[i];}
inline vb01::Texture* getLandmassTexture(int i){return landmassTextures[i];}
@@ -61,9 +64,10 @@ namespace battleship{
Map *map;
vb01::Node *selectedTerrainNode = nullptr;
MovementAxis movementAxis = X_AXIS;
TransformAxis transformAxis = X_AXIS;
vb01Gui::Listbox *skyListbox = nullptr;
bool pushing = false, movingTerrainObject = false, weightsGenerated = false, newMap, cellMarkersVisible = false;
float *oldLandmassVertHeights = nullptr;
bool pushing = false, movingTerrainObject = false, scalingTerrainObject = false, weightsGenerated = false, newMap, cellMarkersVisible = false;
const float MIN_RADIUS = 1, MAX_RADIUS = 100, INCREASE_RATE = 1;
const int NUM_SUBDIVS = 100;
float circleRadius = MIN_RADIUS, guiThreshold = 200;