Skip to content

Commit

Permalink
organize
Browse files Browse the repository at this point in the history
move nav mesh generation code to its own class. Start creating the nav mesh structure.
  • Loading branch information
wootguy committed Oct 27, 2023
1 parent fcdb1a2 commit f832fcb
Show file tree
Hide file tree
Showing 8 changed files with 492 additions and 297 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ set(SOURCE_FILES
src/util/mat4x4.h src/util/mat4x4.cpp
src/util/Polygon3D.h src/util/Polygon3D.cpp
src/util/PolyOctree.h src/util/PolyOctree.cpp
src/bsp/NavMesh.h src/bsp/NavMesh.cpp
src/bsp/NavMeshGenerator.h src/bsp/NavMeshGenerator.cpp

# OpenGL rendering
src/gl/shaders.h src/gl/shaders.cpp
Expand Down Expand Up @@ -89,8 +91,8 @@ if(MSVC)
add_subdirectory(glfw)

# compile using the static runtime
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /wd4244 /wd4018")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /wd4244 /wd4018 /W0")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /W0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /wd4244 /wd4018")

# Disable C++ exceptions
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT bspguy)
Expand Down
43 changes: 43 additions & 0 deletions src/bsp/NavMesh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "NavMesh.h"
#include "GLFW/glfw3.h"
#include "PolyOctree.h"
#include "Clipper.h"

NavMesh::NavMesh() {
clear();
}

void NavMesh::clear() {
memset(nodes, 0, sizeof(NavPolyNode) * MAX_NAV_POLYS);

for (int i = 0; i < MAX_NAV_POLYS; i++) {
polys[i] = Polygon3D();
}
}

NavMesh::NavMesh(vector<Polygon3D> faces) {
clear();

for (int i = 0; i < faces.size(); i++) {
polys[i] = faces[i];
if (faces[i].verts.size() > MAX_NAV_POLY_VERTS)
logf("Error: Face %d has %d verts (max is %d)\n", i, faces[i].verts.size(), MAX_NAV_POLY_VERTS);
}
numPolys = faces.size();

logf("Created nav mesh with %d polys (x%d = %d KB)\n",
numPolys, sizeof(NavPolyNode), (sizeof(NavPolyNode)*numPolys) / 1024);

logf("NavPolyNode = %d bytes, NavLink = %d bytes\n",
sizeof(NavPolyNode), sizeof(NavLink));
}

vector<Polygon3D> NavMesh::getPolys() {
vector<Polygon3D> ret;

for (int i = 0; i < numPolys; i++) {
ret.push_back(polys[i]);
}

return ret;
}
38 changes: 38 additions & 0 deletions src/bsp/NavMesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include "Polygon3D.h"
#include "PolyOctree.h"
#include <set>
#include "Bsp.h"

#define MAX_NAV_POLYS 8192
#define MAX_NAV_POLY_VERTS 12
#define MAX_EDGE_LINKS 8

struct NavLink {
uint16_t node; // which poly is linked to. 0 = end of links
int16_t zDist; // minimum height difference between the connecting edges
};

struct NavPolyNode {
NavLink edges[MAX_NAV_POLY_VERTS][MAX_EDGE_LINKS];
uint32_t flags;
};


class NavMesh {
public:
NavPolyNode nodes[MAX_NAV_POLYS];
Polygon3D polys[MAX_NAV_POLYS];

int numPolys;

NavMesh();

NavMesh(vector<Polygon3D> polys);

void clear();

vector<Polygon3D> getPolys();

private:
};
Loading

0 comments on commit f832fcb

Please sign in to comment.