From 7cd73893f490835a34212aa94020865e052607fd Mon Sep 17 00:00:00 2001 From: Amos <48657826+Mauler125@users.noreply.github.com> Date: Sun, 13 Mar 2022 22:20:02 +0100 Subject: [PATCH] Build navmesh files to game directory And additional compiler improvements --- r5dev/naveditor/Pch.cpp | 8 - r5dev/naveditor/Sample.cpp | 272 ++++++++++++----------- r5dev/naveditor/Sample_TempObstacles.cpp | 1 - r5dev/naveditor/include/Pch.h | 47 ---- r5dev/naveditor/include/Sample.h | 2 +- r5dev/naveditor/main.cpp | 12 +- r5dev/thirdparty/recast/Pch.cpp | 9 +- r5dev/thirdparty/recast/Pch.h | 11 +- r5dev/vproj/naveditor.vcxproj | 10 +- r5dev/vproj/naveditor.vcxproj.filters | 12 +- 10 files changed, 176 insertions(+), 208 deletions(-) delete mode 100644 r5dev/naveditor/Pch.cpp delete mode 100644 r5dev/naveditor/include/Pch.h diff --git a/r5dev/naveditor/Pch.cpp b/r5dev/naveditor/Pch.cpp deleted file mode 100644 index ef981e3d..00000000 --- a/r5dev/naveditor/Pch.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// Pch.cpp : source file that includes just the standard includes -// *.pch will be the pre-compiled header -// Pch.obj will contain the pre-compiled type information - -#include "Pch.h" - -// TODO: reference any additional headers you need in PCH.H -// and not in this file diff --git a/r5dev/naveditor/Sample.cpp b/r5dev/naveditor/Sample.cpp index 3345a936..e8ba0ea6 100644 --- a/r5dev/naveditor/Sample.cpp +++ b/r5dev/naveditor/Sample.cpp @@ -161,7 +161,7 @@ void Sample::collectSettings(BuildSettings& settings) void Sample::resetCommonSettings() { m_cellSize = 15.0f; - m_cellHeight = 5.8f; + m_cellHeight = 5.85f; m_agentHeight = 2.0f; m_agentRadius = 0.6f; m_agentMaxClimb = 0.9f; @@ -429,6 +429,125 @@ void unpatch_tiletf2(dtMeshTile* t) coord_tf_unfix(t->offMeshCons[i].unk); } } +struct link_table_data +{ + //disjoint set algo from some crappy site because i'm too lazy to think + int set_count = 0; + std::vector rank; + std::vector parent; + void init(int size) + { + rank.resize(size); + parent.resize(size); + + for (int i = 0; i < parent.size(); i++) + parent[i] = i; + } + int insert_new() + { + rank.push_back(0); + parent.push_back(set_count); + return set_count++; + } + int find(int id) + { + if (parent[id] != id) + return find(parent[id]); + return id; + } + void set_union(int x, int y) + { + int sx = find(x); + int sy = find(y); + if (sx == sy) //same set already + return; + + if (rank[sx] < rank[sy]) + parent[sx] = sy; + else if (rank[sx] > rank[sy]) + parent[sy] = sx; + else + { + parent[sy] = sx; + rank[sx] += 1; + } + } +}; +void build_link_table(dtNavMesh* mesh, link_table_data& data) +{ + //clear all labels + for (int i = 0; i < mesh->getMaxTiles(); ++i) + { + dtMeshTile* tile = mesh->getTile(i); + if (!tile || !tile->header || !tile->dataSize) continue; + auto pcount = tile->header->polyCount; + for (int j = 0; j < pcount; j++) + { + auto& poly = tile->polys[j]; + poly.link_table_idx = -1; + } + } + //first pass + std::set nlabels; + for (int i = 0; i < mesh->getMaxTiles(); ++i) + { + dtMeshTile* tile = mesh->getTile(i); + if (!tile || !tile->header || !tile->dataSize) continue; + auto pcount = tile->header->polyCount; + for (int j = 0; j < pcount; j++) + { + auto& poly = tile->polys[j]; + auto plink = poly.firstLink; + while (plink != DT_NULL_LINK) + { + auto l = tile->links[plink]; + const dtMeshTile* t; + const dtPoly* p; + mesh->getTileAndPolyByRefUnsafe(l.ref, &t, &p); + + if (p->link_table_idx != (unsigned short)-1) + nlabels.insert(p->link_table_idx); + plink = l.next; + } + if (nlabels.empty()) + { + poly.link_table_idx = data.insert_new(); + } + else + { + auto l = *nlabels.begin(); + poly.link_table_idx = l; + for (auto nl : nlabels) + data.set_union(l, nl); + } + nlabels.clear(); + } + } + //second pass + for (int i = 0; i < mesh->getMaxTiles(); ++i) + { + dtMeshTile* tile = mesh->getTile(i); + if (!tile || !tile->header || !tile->dataSize) continue; + auto pcount = tile->header->polyCount; + for (int j = 0; j < pcount; j++) + { + auto& poly = tile->polys[j]; + auto id = data.find(poly.link_table_idx); + poly.link_table_idx = id; + } + } +} +void set_reachable(std::vector& data, int count, int id1, int id2, bool value) +{ + int w = ((count + 31) / 32); + auto& cell = data[id1 * w + id2 / 32]; + uint32_t value_mask = ~(1 << (id2 & 0x1f)); + if (!value) + cell = (cell & value_mask); + else + cell = (cell & value_mask) | (1 << (id2 & 0x1f)); +} + dtNavMesh* Sample::loadAll(const char* path) { @@ -505,133 +624,20 @@ dtNavMesh* Sample::loadAll(const char* path) return mesh; } -struct link_table_data -{ - //disjoint set algo from some crappy site because i'm too lazy to think - int set_count = 0; - std::vector rank; - std::vector parent; - void init(int size) - { - rank.resize(size); - parent.resize(size); - for (int i = 0; i < parent.size(); i++) - parent[i] = i; - } - int insert_new() - { - rank.push_back(0); - parent.push_back(set_count); - return set_count++; - } - int find(int id) - { - if (parent[id] != id) - return find(parent[id]); - return id; - } - void set_union(int x, int y) - { - int sx = find(x); - int sy = find(y); - if (sx == sy) //same set already - return; - - if (rank[sx] < rank[sy]) - parent[sx] = sy; - else if (rank[sx] > rank[sy]) - parent[sy] = sx; - else - { - parent[sy] = sx; - rank[sx] += 1; - } - } -}; -void build_link_table(dtNavMesh* mesh, link_table_data& data) +void Sample::saveAll(std::string path, dtNavMesh* mesh) { - //clear all labels - for (int i = 0; i < mesh->getMaxTiles(); ++i) - { - dtMeshTile* tile = mesh->getTile(i); - if (!tile || !tile->header || !tile->dataSize) continue; - auto pcount = tile->header->polyCount; - for (int j = 0; j < pcount; j++) - { - auto& poly = tile->polys[j]; - poly.link_table_idx = -1; - } - } - //first pass - std::set nlabels; - for (int i = 0; i < mesh->getMaxTiles(); ++i) - { - dtMeshTile* tile = mesh->getTile(i); - if (!tile || !tile->header || !tile->dataSize) continue; - auto pcount = tile->header->polyCount; - for (int j = 0; j < pcount; j++) - { - auto& poly = tile->polys[j]; - auto plink = poly.firstLink; - while (plink != DT_NULL_LINK) - { - auto l=tile->links[plink]; - const dtMeshTile *t; - const dtPoly *p; - mesh->getTileAndPolyByRefUnsafe(l.ref, &t, &p); - - if(p->link_table_idx != (unsigned short)-1) - nlabels.insert(p->link_table_idx); - plink = l.next; - } - if (nlabels.empty()) - { - poly.link_table_idx = data.insert_new(); - } - else - { - auto l = *nlabels.begin(); - poly.link_table_idx = l; - for (auto nl : nlabels) - data.set_union(l, nl); - } - nlabels.clear(); - } - } - //second pass - for (int i = 0; i < mesh->getMaxTiles(); ++i) - { - dtMeshTile* tile = mesh->getTile(i); - if (!tile || !tile->header || !tile->dataSize) continue; - auto pcount = tile->header->polyCount; - for (int j = 0; j < pcount; j++) - { - auto& poly = tile->polys[j]; - auto id = data.find(poly.link_table_idx); - poly.link_table_idx = id; - } - } -} -void set_reachable(std::vector& data,int count, int id1, int id2, bool value) -{ - int w = ((count + 31) / 32); - auto& cell = data[id1*w + id2 / 32]; - uint32_t value_mask = ~(1<<(id2 & 0x1f)); - if (!value) - cell = (cell & value_mask); - else - cell = (cell & value_mask) | (1 << (id2 & 0x1f)); -} -void Sample::saveAll(const char* path,dtNavMesh* mesh) -{ - - printf("%s\n", path); if (!mesh) return; - char buffer[256]; - sprintf(buffer, "%s_%s.nm", path, m_navmesh_name); - printf("%s\n", buffer); + std::filesystem::path p = "..\\maps\\navmesh\\"; + + if (std::filesystem::is_directory(p)) + { + path.insert(0, p.string()); + } + + char buffer[256]; + sprintf(buffer, "%s_%s.nm", path.c_str(), m_navmesh_name); FILE* fp = fopen(buffer, "wb"); if (!fp) @@ -642,7 +648,7 @@ void Sample::saveAll(const char* path,dtNavMesh* mesh) header.magic = NAVMESHSET_MAGIC; header.version = NAVMESHSET_VERSION; header.numTiles = 0; - + for (int i = 0; i < mesh->getMaxTiles(); ++i) { dtMeshTile* tile = mesh->getTile(i); @@ -653,7 +659,7 @@ void Sample::saveAll(const char* path,dtNavMesh* mesh) link_table_data link_data; build_link_table(mesh, link_data); - int table_size = ((link_data.set_count + 31) / 32)*link_data.set_count * 32; + int table_size = ((link_data.set_count + 31) / 32) * link_data.set_count * 32; header.params.disjoint_poly_group_count = link_data.set_count; header.params.reachability_table_count = m_count_reachability_tables; header.params.reachability_table_size = table_size; @@ -676,16 +682,16 @@ void Sample::saveAll(const char* path,dtNavMesh* mesh) fwrite(tile->data, tile->dataSize, 1, fp); if (*is_tf2)patch_tiletf2(const_cast(tile)); } - + //still dont know what this thing is... - int header_sth=0; - for(int i=0;i reachability(table_size,0); + std::vector reachability(table_size, 0); for (int i = 0; i < link_data.set_count; i++) set_reachable(reachability, link_data.set_count, i, i, true); - for(int i=0;i< header.params.reachability_table_count;i++) - fwrite(reachability.data(), sizeof(int), (table_size /4), fp); + for (int i = 0; i < header.params.reachability_table_count; i++) + fwrite(reachability.data(), sizeof(int), (table_size / 4), fp); fclose(fp); -} +} \ No newline at end of file diff --git a/r5dev/naveditor/Sample_TempObstacles.cpp b/r5dev/naveditor/Sample_TempObstacles.cpp index c1c9c154..c8417332 100644 --- a/r5dev/naveditor/Sample_TempObstacles.cpp +++ b/r5dev/naveditor/Sample_TempObstacles.cpp @@ -34,7 +34,6 @@ #include "NavEditor/Include/InputGeom.h" #include "NavEditor/Include/Sample.h" #include "NavEditor/Include/Sample_TempObstacles.h" -#include "thirdparty/fastlz/fastlz.h" // This value specifies how many layers (or "floors") each navmesh tile is expected to have. diff --git a/r5dev/naveditor/include/Pch.h b/r5dev/naveditor/include/Pch.h deleted file mode 100644 index 1e0bc4ce..00000000 --- a/r5dev/naveditor/include/Pch.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef DTPCH_H -#define DTPCH_H - -#define _USE_MATH_DEFINES -#include -#include -#include -#include -#include - -#include -#include - -#ifdef WIN32 -# include -#else // Linux, BSD, OSX -# include -# include -#endif - -#include -#include -#include -#include - -#include -#include -#include - -#include "thirdparty/sdl/include/SDL.h" -#include "thirdparty/sdl/include/SDL_syswm.h" -#include "thirdparty/sdl/include/SDL_opengl.h" - -#ifdef __APPLE__ -# include -#else -# include -#endif - -#ifdef WIN32 -# define snprintf _snprintf -#endif - -#include "NavEditor/Include/imgui.h" -#include "NavEditor/Include/imguiRenderGL.h" - -#endif // DTPCH_H diff --git a/r5dev/naveditor/include/Sample.h b/r5dev/naveditor/include/Sample.h index 47c8488f..6e9427da 100644 --- a/r5dev/naveditor/include/Sample.h +++ b/r5dev/naveditor/include/Sample.h @@ -144,7 +144,7 @@ protected: SampleDebugDraw m_dd; dtNavMesh* loadAll(const char* path); - void saveAll(const char* path,dtNavMesh* mesh); + void saveAll(std::string path,dtNavMesh* mesh); public: std::string m_model_name; diff --git a/r5dev/naveditor/main.cpp b/r5dev/naveditor/main.cpp index 11bc2a38..a7b7e49a 100644 --- a/r5dev/naveditor/main.cpp +++ b/r5dev/naveditor/main.cpp @@ -376,6 +376,10 @@ int not_main(int argc, char** argv) auto_load = argv[1]; } } + else + { + FreeConsole(); + } float t = 0.0f; float timeAcc = 0.0f; @@ -412,8 +416,8 @@ int not_main(int argc, char** argv) string sampleName = "Choose Sample..."; vector files; - const string meshesFolder = "Meshes"; - string meshName = "Choose Mesh..."; + const string meshesFolder = "Levels"; + string meshName = "Choose Level..."; float markerPosition[3] = {0, 0, 0}; bool markerPositionSet = false; @@ -835,8 +839,8 @@ int not_main(int argc, char** argv) imguiSeparator(); //if (imguiCheck("Import/Export TF2", tf2_transforms, true)) // tf2_transforms = !tf2_transforms; - imguiLabel("Input Mesh"); - if (imguiButton("Load mesh...")) + imguiLabel("Input Level"); + if (imguiButton("Load Level...")) { char szFile[260]; OPENFILENAMEA diag = { 0 }; diff --git a/r5dev/thirdparty/recast/Pch.cpp b/r5dev/thirdparty/recast/Pch.cpp index 7b9c1cf3..ef981e3d 100644 --- a/r5dev/thirdparty/recast/Pch.cpp +++ b/r5dev/thirdparty/recast/Pch.cpp @@ -1 +1,8 @@ -#include "NavEditor/Include/Pch.h" +// Pch.cpp : source file that includes just the standard includes +// *.pch will be the pre-compiled header +// Pch.obj will contain the pre-compiled type information + +#include "Pch.h" + +// TODO: reference any additional headers you need in PCH.H +// and not in this file diff --git a/r5dev/thirdparty/recast/Pch.h b/r5dev/thirdparty/recast/Pch.h index 87dcb0fb..b5a50097 100644 --- a/r5dev/thirdparty/recast/Pch.h +++ b/r5dev/thirdparty/recast/Pch.h @@ -1,3 +1,5 @@ +#ifndef DTPCH_H +#define DTPCH_H #define _USE_MATH_DEFINES #include @@ -11,7 +13,7 @@ #ifdef WIN32 # include -#else +#else // Linux, BSD, OSX # include # include #endif @@ -24,6 +26,9 @@ #include #include #include +#include + +#include "thirdparty/fastlz/fastlz.h" #include "thirdparty/sdl/include/SDL.h" #include "thirdparty/sdl/include/SDL_syswm.h" @@ -40,4 +45,6 @@ #endif #include "NavEditor/Include/imgui.h" -#include "NavEditor/Include/imguiRenderGL.h" \ No newline at end of file +#include "NavEditor/Include/imguiRenderGL.h" + +#endif // DTPCH_H diff --git a/r5dev/vproj/naveditor.vcxproj b/r5dev/vproj/naveditor.vcxproj index 1572967f..1a918a78 100644 --- a/r5dev/vproj/naveditor.vcxproj +++ b/r5dev/vproj/naveditor.vcxproj @@ -24,7 +24,6 @@ - @@ -35,6 +34,7 @@ + @@ -51,10 +51,6 @@ - - Create - Create - @@ -68,6 +64,10 @@ NotUsing NotUsing + + Create + Create + 16.0 diff --git a/r5dev/vproj/naveditor.vcxproj.filters b/r5dev/vproj/naveditor.vcxproj.filters index 9104df3c..5b7485fe 100644 --- a/r5dev/vproj/naveditor.vcxproj.filters +++ b/r5dev/vproj/naveditor.vcxproj.filters @@ -39,9 +39,6 @@ - - core\include - core\include @@ -111,6 +108,9 @@ contrib\include + + core\include + @@ -119,9 +119,6 @@ core - - core - core @@ -188,5 +185,8 @@ utils + + core + \ No newline at end of file