Build navmesh files to game directory

And additional compiler improvements
This commit is contained in:
Amos 2022-03-13 22:20:02 +01:00
parent 3cf36b5d61
commit 7cd73893f4
10 changed files with 176 additions and 208 deletions

View File

@ -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

View File

@ -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<int> rank;
std::vector<int> 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<int> 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<int>& 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<int> rank;
std::vector<int> 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<int> 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<int>& 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<dtMeshTile*>(tile));
}
//still dont know what this thing is...
int header_sth=0;
for(int i=0;i<link_data.set_count;i++)
int header_sth = 0;
for (int i = 0; i < link_data.set_count; i++)
fwrite(&header_sth, sizeof(int), 1, fp);
std::vector<int> reachability(table_size,0);
std::vector<int> 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);
}
}

View File

@ -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.

View File

@ -1,47 +0,0 @@
#ifndef DTPCH_H
#define DTPCH_H
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <float.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef WIN32
# include <io.h>
#else // Linux, BSD, OSX
# include <dirent.h>
# include <cstring>
#endif
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <algorithm>
#include "thirdparty/sdl/include/SDL.h"
#include "thirdparty/sdl/include/SDL_syswm.h"
#include "thirdparty/sdl/include/SDL_opengl.h"
#ifdef __APPLE__
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#ifdef WIN32
# define snprintf _snprintf
#endif
#include "NavEditor/Include/imgui.h"
#include "NavEditor/Include/imguiRenderGL.h"
#endif // DTPCH_H

View File

@ -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;

View File

@ -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<string> 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 };

View File

@ -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

View File

@ -1,3 +1,5 @@
#ifndef DTPCH_H
#define DTPCH_H
#define _USE_MATH_DEFINES
#include <math.h>
@ -11,7 +13,7 @@
#ifdef WIN32
# include <io.h>
#else
#else // Linux, BSD, OSX
# include <dirent.h>
# include <cstring>
#endif
@ -24,6 +26,9 @@
#include <set>
#include <vector>
#include <algorithm>
#include <filesystem>
#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"
#include "NavEditor/Include/imguiRenderGL.h"
#endif // DTPCH_H

View File

@ -24,7 +24,6 @@
<ClInclude Include="..\naveditor\include\NavMeshPruneTool.h" />
<ClInclude Include="..\naveditor\include\NavMeshTesterTool.h" />
<ClInclude Include="..\naveditor\include\OffMeshConnectionTool.h" />
<ClInclude Include="..\naveditor\include\Pch.h" />
<ClInclude Include="..\naveditor\include\PerfTimer.h" />
<ClInclude Include="..\naveditor\include\Sample.h" />
<ClInclude Include="..\naveditor\include\SampleInterfaces.h" />
@ -35,6 +34,7 @@
<ClInclude Include="..\naveditor\include\TestCase.h" />
<ClInclude Include="..\naveditor\include\ValueHistory.h" />
<ClInclude Include="..\thirdparty\fastlz\fastlz.h" />
<ClInclude Include="..\thirdparty\recast\Pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\naveditor\ChunkyTriMesh.cpp" />
@ -51,10 +51,6 @@
<ClCompile Include="..\naveditor\NavMeshPruneTool.cpp" />
<ClCompile Include="..\naveditor\NavMeshTesterTool.cpp" />
<ClCompile Include="..\naveditor\OffMeshConnectionTool.cpp" />
<ClCompile Include="..\naveditor\Pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\naveditor\PerfTimer.cpp" />
<ClCompile Include="..\naveditor\Sample.cpp" />
<ClCompile Include="..\naveditor\SampleInterfaces.cpp" />
@ -68,6 +64,10 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\thirdparty\recast\Pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>

View File

@ -39,9 +39,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\naveditor\include\Pch.h">
<Filter>core\include</Filter>
</ClInclude>
<ClInclude Include="..\naveditor\include\Sample.h">
<Filter>core\include</Filter>
</ClInclude>
@ -111,6 +108,9 @@
<ClInclude Include="..\thirdparty\fastlz\fastlz.h">
<Filter>contrib\include</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\recast\Pch.h">
<Filter>core\include</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\thirdparty\fastlz\fastlz.c">
@ -119,9 +119,6 @@
<ClCompile Include="..\naveditor\main.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="..\naveditor\Pch.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="..\naveditor\Sample.cpp">
<Filter>core</Filter>
</ClCompile>
@ -188,5 +185,8 @@
<ClCompile Include="..\naveditor\TestCase.cpp">
<Filter>utils</Filter>
</ClCompile>
<ClCompile Include="..\thirdparty\recast\Pch.cpp">
<Filter>core</Filter>
</ClCompile>
</ItemGroup>
</Project>