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() void Sample::resetCommonSettings()
{ {
m_cellSize = 15.0f; m_cellSize = 15.0f;
m_cellHeight = 5.8f; m_cellHeight = 5.85f;
m_agentHeight = 2.0f; m_agentHeight = 2.0f;
m_agentRadius = 0.6f; m_agentRadius = 0.6f;
m_agentMaxClimb = 0.9f; m_agentMaxClimb = 0.9f;
@ -429,82 +429,6 @@ void unpatch_tiletf2(dtMeshTile* t)
coord_tf_unfix(t->offMeshCons[i].unk); coord_tf_unfix(t->offMeshCons[i].unk);
} }
} }
dtNavMesh* Sample::loadAll(const char* path)
{
char buffer[256];
sprintf(buffer, "%s_%s.nm", path, m_navmesh_name);
FILE* fp = fopen(buffer, "rb");
if (!fp) return 0;
// Read header.
NavMeshSetHeader header;
size_t readLen = fread(&header, sizeof(NavMeshSetHeader), 1, fp);
if (readLen != 1)
{
fclose(fp);
return 0;
}
if (header.magic != NAVMESHSET_MAGIC)
{
fclose(fp);
return 0;
}
if (header.version != NAVMESHSET_VERSION)
{
fclose(fp);
return 0;
}
dtNavMesh* mesh = dtAllocNavMesh();
if (!mesh)
{
fclose(fp);
return 0;
}
if(*is_tf2) patch_headertf2(header);
dtStatus status = mesh->init(&header.params);
if (dtStatusFailed(status))
{
fclose(fp);
return 0;
}
// Read tiles.
for (int i = 0; i < header.numTiles; ++i)
{
NavMeshTileHeader tileHeader;
readLen = fread(&tileHeader, sizeof(tileHeader), 1, fp);
if (readLen != 1)
{
fclose(fp);
return 0;
}
if (!tileHeader.tileRef || !tileHeader.dataSize)
break;
unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
if (!data) break;
memset(data, 0, tileHeader.dataSize);
readLen = fread(data, tileHeader.dataSize, 1, fp);
if (readLen != 1)
{
dtFree(data);
fclose(fp);
return 0;
}
dtTileRef result;
mesh->addTile(data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, &result);
auto tile = const_cast<dtMeshTile*>(mesh->getTileByRef(result));
if (*is_tf2) patch_tiletf2(tile);
}
fclose(fp);
return mesh;
}
struct link_table_data struct link_table_data
{ {
//disjoint set algo from some crappy site because i'm too lazy to think //disjoint set algo from some crappy site because i'm too lazy to think
@ -623,15 +547,97 @@ void set_reachable(std::vector<int>& data,int count, int id1, int id2, bool valu
else else
cell = (cell & value_mask) | (1 << (id2 & 0x1f)); cell = (cell & value_mask) | (1 << (id2 & 0x1f));
} }
void Sample::saveAll(const char* path,dtNavMesh* mesh)
dtNavMesh* Sample::loadAll(const char* path)
{ {
printf("%s\n", path);
if (!mesh) return;
char buffer[256]; char buffer[256];
sprintf(buffer, "%s_%s.nm", path, m_navmesh_name); sprintf(buffer, "%s_%s.nm", path, m_navmesh_name);
printf("%s\n", buffer); FILE* fp = fopen(buffer, "rb");
if (!fp) return 0;
// Read header.
NavMeshSetHeader header;
size_t readLen = fread(&header, sizeof(NavMeshSetHeader), 1, fp);
if (readLen != 1)
{
fclose(fp);
return 0;
}
if (header.magic != NAVMESHSET_MAGIC)
{
fclose(fp);
return 0;
}
if (header.version != NAVMESHSET_VERSION)
{
fclose(fp);
return 0;
}
dtNavMesh* mesh = dtAllocNavMesh();
if (!mesh)
{
fclose(fp);
return 0;
}
if(*is_tf2) patch_headertf2(header);
dtStatus status = mesh->init(&header.params);
if (dtStatusFailed(status))
{
fclose(fp);
return 0;
}
// Read tiles.
for (int i = 0; i < header.numTiles; ++i)
{
NavMeshTileHeader tileHeader;
readLen = fread(&tileHeader, sizeof(tileHeader), 1, fp);
if (readLen != 1)
{
fclose(fp);
return 0;
}
if (!tileHeader.tileRef || !tileHeader.dataSize)
break;
unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
if (!data) break;
memset(data, 0, tileHeader.dataSize);
readLen = fread(data, tileHeader.dataSize, 1, fp);
if (readLen != 1)
{
dtFree(data);
fclose(fp);
return 0;
}
dtTileRef result;
mesh->addTile(data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, &result);
auto tile = const_cast<dtMeshTile*>(mesh->getTileByRef(result));
if (*is_tf2) patch_tiletf2(tile);
}
fclose(fp);
return mesh;
}
void Sample::saveAll(std::string path, dtNavMesh* mesh)
{
if (!mesh) return;
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"); FILE* fp = fopen(buffer, "wb");
if (!fp) if (!fp)

View File

@ -34,7 +34,6 @@
#include "NavEditor/Include/InputGeom.h" #include "NavEditor/Include/InputGeom.h"
#include "NavEditor/Include/Sample.h" #include "NavEditor/Include/Sample.h"
#include "NavEditor/Include/Sample_TempObstacles.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. // 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; SampleDebugDraw m_dd;
dtNavMesh* loadAll(const char* path); dtNavMesh* loadAll(const char* path);
void saveAll(const char* path,dtNavMesh* mesh); void saveAll(std::string path,dtNavMesh* mesh);
public: public:
std::string m_model_name; std::string m_model_name;

View File

@ -376,6 +376,10 @@ int not_main(int argc, char** argv)
auto_load = argv[1]; auto_load = argv[1];
} }
} }
else
{
FreeConsole();
}
float t = 0.0f; float t = 0.0f;
float timeAcc = 0.0f; float timeAcc = 0.0f;
@ -412,8 +416,8 @@ int not_main(int argc, char** argv)
string sampleName = "Choose Sample..."; string sampleName = "Choose Sample...";
vector<string> files; vector<string> files;
const string meshesFolder = "Meshes"; const string meshesFolder = "Levels";
string meshName = "Choose Mesh..."; string meshName = "Choose Level...";
float markerPosition[3] = {0, 0, 0}; float markerPosition[3] = {0, 0, 0};
bool markerPositionSet = false; bool markerPositionSet = false;
@ -835,8 +839,8 @@ int not_main(int argc, char** argv)
imguiSeparator(); imguiSeparator();
//if (imguiCheck("Import/Export TF2", tf2_transforms, true)) //if (imguiCheck("Import/Export TF2", tf2_transforms, true))
// tf2_transforms = !tf2_transforms; // tf2_transforms = !tf2_transforms;
imguiLabel("Input Mesh"); imguiLabel("Input Level");
if (imguiButton("Load mesh...")) if (imguiButton("Load Level..."))
{ {
char szFile[260]; char szFile[260];
OPENFILENAMEA diag = { 0 }; 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 #define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
@ -11,7 +13,7 @@
#ifdef WIN32 #ifdef WIN32
# include <io.h> # include <io.h>
#else #else // Linux, BSD, OSX
# include <dirent.h> # include <dirent.h>
# include <cstring> # include <cstring>
#endif #endif
@ -24,6 +26,9 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <filesystem>
#include "thirdparty/fastlz/fastlz.h"
#include "thirdparty/sdl/include/SDL.h" #include "thirdparty/sdl/include/SDL.h"
#include "thirdparty/sdl/include/SDL_syswm.h" #include "thirdparty/sdl/include/SDL_syswm.h"
@ -41,3 +46,5 @@
#include "NavEditor/Include/imgui.h" #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\NavMeshPruneTool.h" />
<ClInclude Include="..\naveditor\include\NavMeshTesterTool.h" /> <ClInclude Include="..\naveditor\include\NavMeshTesterTool.h" />
<ClInclude Include="..\naveditor\include\OffMeshConnectionTool.h" /> <ClInclude Include="..\naveditor\include\OffMeshConnectionTool.h" />
<ClInclude Include="..\naveditor\include\Pch.h" />
<ClInclude Include="..\naveditor\include\PerfTimer.h" /> <ClInclude Include="..\naveditor\include\PerfTimer.h" />
<ClInclude Include="..\naveditor\include\Sample.h" /> <ClInclude Include="..\naveditor\include\Sample.h" />
<ClInclude Include="..\naveditor\include\SampleInterfaces.h" /> <ClInclude Include="..\naveditor\include\SampleInterfaces.h" />
@ -35,6 +34,7 @@
<ClInclude Include="..\naveditor\include\TestCase.h" /> <ClInclude Include="..\naveditor\include\TestCase.h" />
<ClInclude Include="..\naveditor\include\ValueHistory.h" /> <ClInclude Include="..\naveditor\include\ValueHistory.h" />
<ClInclude Include="..\thirdparty\fastlz\fastlz.h" /> <ClInclude Include="..\thirdparty\fastlz\fastlz.h" />
<ClInclude Include="..\thirdparty\recast\Pch.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\naveditor\ChunkyTriMesh.cpp" /> <ClCompile Include="..\naveditor\ChunkyTriMesh.cpp" />
@ -51,10 +51,6 @@
<ClCompile Include="..\naveditor\NavMeshPruneTool.cpp" /> <ClCompile Include="..\naveditor\NavMeshPruneTool.cpp" />
<ClCompile Include="..\naveditor\NavMeshTesterTool.cpp" /> <ClCompile Include="..\naveditor\NavMeshTesterTool.cpp" />
<ClCompile Include="..\naveditor\OffMeshConnectionTool.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\PerfTimer.cpp" />
<ClCompile Include="..\naveditor\Sample.cpp" /> <ClCompile Include="..\naveditor\Sample.cpp" />
<ClCompile Include="..\naveditor\SampleInterfaces.cpp" /> <ClCompile Include="..\naveditor\SampleInterfaces.cpp" />
@ -68,6 +64,10 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile> </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> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion> <VCProjectVersion>16.0</VCProjectVersion>

View File

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