Remove 'bool* is_tf2' from class 'Sample'

This commit is contained in:
Kawe Mazidjatari 2022-07-20 16:44:28 +02:00
parent 5486923f47
commit 5b9b0164b1
5 changed files with 33 additions and 38 deletions

View File

@ -118,7 +118,7 @@ InputGeom::~InputGeom()
delete m_mesh;
}
bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath,bool is_tf2)
bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath)
{
if (m_mesh)
{
@ -131,8 +131,6 @@ bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath,bool is_tf2
m_volumeCount = 0;
m_mesh = new rcMeshLoaderObj;
//m_mesh->m_flip_tris = is_tf2;
m_mesh->m_flipAxis = is_tf2;
if (!m_mesh)
{
ctx->log(RC_LOG_ERROR, "loadMesh: Out of memory 'm_mesh'.");
@ -160,7 +158,7 @@ bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath,bool is_tf2
return true;
}
bool InputGeom::loadPlyMesh(rcContext* ctx, const std::string& filepath, bool is_tf2)
bool InputGeom::loadPlyMesh(rcContext* ctx, const std::string& filepath)
{
if (m_mesh)
{
@ -173,8 +171,6 @@ bool InputGeom::loadPlyMesh(rcContext* ctx, const std::string& filepath, bool is
m_volumeCount = 0;
m_mesh = new rcMeshLoaderPly;
//m_mesh->m_flip_tris = is_tf2;
m_mesh->m_flipAxis = is_tf2;
if (!m_mesh)
{
ctx->log(RC_LOG_ERROR, "loadMesh: Out of memory 'm_mesh'.");
@ -202,7 +198,7 @@ bool InputGeom::loadPlyMesh(rcContext* ctx, const std::string& filepath, bool is
return true;
}
bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath,bool is_tf2)
bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath)
{
//NB(warmist): tf2 not implemented here
char* buf = 0;
@ -264,7 +260,7 @@ bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath,bool is_
name++;
if (*name)
{
if (!loadMesh(ctx, name, is_tf2))
if (!loadMesh(ctx, name))
{
delete [] buf;
return false;
@ -337,7 +333,7 @@ bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath,bool is_
return true;
}
bool InputGeom::load(rcContext* ctx, const std::string& filepath,bool is_tf2)
bool InputGeom::load(rcContext* ctx, const std::string& filepath)
{
size_t extensionPos = filepath.find_last_of('.');
if (extensionPos == std::string::npos)
@ -347,11 +343,11 @@ bool InputGeom::load(rcContext* ctx, const std::string& filepath,bool is_tf2)
std::transform(extension.begin(), extension.end(), extension.begin(), tolower);
if (extension == ".gset")
return loadGeomSet(ctx, filepath, is_tf2);
return loadGeomSet(ctx, filepath);
if (extension == ".obj")
return loadMesh(ctx, filepath, is_tf2);
return loadMesh(ctx, filepath);
if (extension == ".ply")
return loadPlyMesh(ctx, filepath, is_tf2);
return loadPlyMesh(ctx, filepath);
return false;
}

View File

@ -372,7 +372,8 @@ dtNavMesh* Sample::loadAll(std::string path)
fclose(fp);
return 0;
}
if(*is_tf2) patchHeaderGame(header);
dtStatus status = mesh->init(&header.params);
if (dtStatusFailed(status))
{
@ -395,19 +396,22 @@ dtNavMesh* Sample::loadAll(std::string path)
break;
unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
if (!data) break;
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) patchTileGame(tile);
}
fclose(fp);
@ -441,7 +445,9 @@ void Sample::saveAll(std::string path, dtNavMesh* mesh)
for (int i = 0; i < mesh->getMaxTiles(); ++i)
{
dtMeshTile* tile = mesh->getTile(i);
if (!tile || !tile->header || !tile->dataSize) continue;
if (!tile || !tile->header || !tile->dataSize)
continue;
header.numTiles++;
}
memcpy(&header.params, mesh->getParams(), sizeof(dtNavMeshParams));
@ -476,23 +482,21 @@ void Sample::saveAll(std::string path, dtNavMesh* mesh)
header.params.reachabilityTableCount = m_reachabilityTableCount;
header.params.reachabilityTableSize = ((header.params.disjointPolyGroupCount + 31) / 32) * header.params.disjointPolyGroupCount * 32;
if (*is_tf2)unpatchHeaderGame(header);
fwrite(&header, sizeof(NavMeshSetHeader), 1, fp);
// Store tiles.
for (int i = 0; i < mesh->getMaxTiles(); ++i)
{
dtMeshTile* tile = mesh->getTile(i);
if (!tile || !tile->header || !tile->dataSize) continue;
if (!tile || !tile->header || !tile->dataSize)
continue;
NavMeshTileHeader tileHeader;
tileHeader.tileRef = mesh->getTileRef(tile);
tileHeader.dataSize = tile->dataSize;
fwrite(&tileHeader, sizeof(tileHeader), 1, fp);
if (*is_tf2)unpatchTileGame(const_cast<dtMeshTile*>(tile));
fwrite(&tileHeader, sizeof(tileHeader), 1, fp);
fwrite(tile->data, tile->dataSize, 1, fp);
if (*is_tf2)patchTileGame(const_cast<dtMeshTile*>(tile));
}
////still dont know what this thing is...

View File

@ -96,15 +96,15 @@ class InputGeom
int m_volumeCount;
///@}
bool loadMesh(class rcContext* ctx, const std::string& filepath,bool is_tf2);
bool loadPlyMesh(class rcContext* ctx, const std::string& filepath, bool is_tf2);
bool loadGeomSet(class rcContext* ctx, const std::string& filepath,bool is_tf2);
bool loadMesh(class rcContext* ctx, const std::string& filepath);
bool loadPlyMesh(class rcContext* ctx, const std::string& filepath);
bool loadGeomSet(class rcContext* ctx, const std::string& filepath);
public:
InputGeom();
~InputGeom();
bool load(class rcContext* ctx, const std::string& filepath, bool is_tf2);
bool load(class rcContext* ctx, const std::string& filepath);
bool saveGeomSet(const BuildSettings* settings);
/// Method to return static mesh data.

View File

@ -194,8 +194,6 @@ public:
void resetCommonSettings();
void handleCommonSettings();
//don't do this kids, this is bad cpp
bool* is_tf2 = nullptr;
private:
// Explicitly disabled copy constructor and copy assignment operator.
Sample(const Sample&);

View File

@ -128,12 +128,12 @@ void generate_points(float* pts, int count, float dx, float dy, float dz)
}
}
void auto_load(const char* path, BuildContext& ctx, Sample*& sample,InputGeom*& geom, string& meshName,bool& tf2_transforms)
void auto_load(const char* path, BuildContext& ctx, Sample*& sample,InputGeom*& geom, string& meshName)
{
string geom_path = std::string(path);
meshName = geom_path.substr(geom_path.rfind("\\") + 1);
geom = new InputGeom;
if (!geom->load(&ctx, geom_path, tf2_transforms))
if (!geom->load(&ctx, geom_path))
{
delete geom;
geom = 0;
@ -404,7 +404,6 @@ int not_main(int argc, char** argv)
float markerPosition[3] = {0, 0, 0};
bool markerPositionSet = false;
bool tf2_transforms = false;
InputGeom* geom = nullptr;
Sample* sample = nullptr;
TestCase* test = nullptr;
@ -414,7 +413,6 @@ int not_main(int argc, char** argv)
sample = g_samples[1].create();
sampleName = g_samples[1].name;
sample->is_tf2 = &tf2_transforms;
sample->setContext(&ctx);
if (geom)
{
@ -422,7 +420,7 @@ int not_main(int argc, char** argv)
}
if (autoLoad)
{
auto_load(autoLoad, ctx, sample, geom, meshName, tf2_transforms);
auto_load(autoLoad, ctx, sample, geom, meshName);
if (geom || sample)
{
const float* bmin = 0;
@ -847,9 +845,8 @@ int not_main(int argc, char** argv)
}
imguiSeparator();
//if (imguiCheck("Import/Export TF2", tf2_transforms, true))
// tf2_transforms = !tf2_transforms;
imguiLabel("Input Level");
if (imguiButton("Load Level..."))
{
char szFile[260];
@ -955,7 +952,7 @@ int not_main(int argc, char** argv)
if (newSample)
{
sampleName = g_samples[i].name;
newSample->is_tf2 = &tf2_transforms;
//newSample->is_tf2 = &tf2_transforms;
}
}
}
@ -1022,7 +1019,7 @@ int not_main(int argc, char** argv)
if (!geom_path.empty())
{
geom = new InputGeom;
if (!geom->load(&ctx, geom_path, tf2_transforms))
if (!geom->load(&ctx, geom_path))
{
delete geom;
geom = 0;
@ -1098,7 +1095,7 @@ int not_main(int argc, char** argv)
if (newSample)
{
sampleName = g_samples[i].name;
newSample->is_tf2 = &tf2_transforms;
//newSample->is_tf2 = &tf2_transforms;
}
}
}
@ -1120,7 +1117,7 @@ int not_main(int argc, char** argv)
delete geom;
geom = new InputGeom;
if (!geom || !geom->load(&ctx, path,tf2_transforms))
if (!geom || !geom->load(&ctx, path))
{
delete geom;
geom = 0;