From 6d70cd3e743456530a2b645400a7d81b771bc9b6 Mon Sep 17 00:00:00 2001 From: Louvenarde Date: Thu, 11 Nov 2021 16:44:54 +0100 Subject: [PATCH] Get int now works on enum dvars --- src/Components/Modules/Dvar.cpp | 2 +- src/Components/Modules/Renderer.cpp | 22 ++++++++++++++-------- src/Utils/Utils.cpp | 6 +++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index d0892d2e..c8628e4d 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -38,7 +38,7 @@ namespace Components template <> int Dvar::Var::get() { - if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT) + if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT || this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM) { return this->dvar->current.integer; } diff --git a/src/Components/Modules/Renderer.cpp b/src/Components/Modules/Renderer.cpp index a1d01f90..2aa68b2d 100644 --- a/src/Components/Modules/Renderer.cpp +++ b/src/Components/Modules/Renderer.cpp @@ -292,6 +292,9 @@ namespace Components auto* scene = Game::scene; auto world = Game::DB_FindXAssetEntry(Game::XAssetType::ASSET_TYPE_GFXWORLD, Utils::String::VA("maps/mp/%s.d3dbsp", mapName))->asset.header.gfxWorld; + auto drawDistance = r_playerDrawDebugDistance.get(); + auto sqrDist = drawDistance * drawDistance; + switch (val) { case 1: for (auto i = 0; i < scene->sceneModelCount; i++) @@ -299,7 +302,7 @@ namespace Components if (!scene->sceneModel[i].model) continue; - if (Utils::Vec3SqrDistance(playerPosition, &scene->sceneModel[i].placement.base.origin) < r_playerDrawDebugDistance.get()) + if (Utils::Vec3SqrDistance(playerPosition, &scene->sceneModel[i].placement.base.origin) < sqrDist) { auto b = scene->sceneModel[i].model->bounds; b.midPoint[0] += scene->sceneModel[i].placement.base.origin[0]; @@ -317,7 +320,7 @@ namespace Components for (auto i = 0; i < scene->sceneDObjCount; i++) { - if (Utils::Vec3SqrDistance(playerPosition, &scene->sceneDObj[i].cull.bounds.midPoint) < r_playerDrawDebugDistance.get()) + if (Utils::Vec3SqrDistance(playerPosition, &scene->sceneDObj[i].cull.bounds.midPoint) < sqrDist) { scene->sceneDObj[i].cull.bounds.halfSize[0] = std::abs(scene->sceneDObj[i].cull.bounds.halfSize[0]); scene->sceneDObj[i].cull.bounds.halfSize[1] = std::abs(scene->sceneDObj[i].cull.bounds.halfSize[1]); @@ -342,7 +345,7 @@ namespace Components { auto staticModel = world->dpvs.smodelDrawInsts[i]; - if (Utils::Vec3SqrDistance(playerPosition, &staticModel.placement.origin) < r_playerDrawDebugDistance.get()) + if (Utils::Vec3SqrDistance(playerPosition, &staticModel.placement.origin) < sqrDist) { if (staticModel.model) { @@ -386,6 +389,9 @@ namespace Components auto* scene = Game::scene; auto world = Game::DB_FindXAssetEntry(Game::XAssetType::ASSET_TYPE_GFXWORLD, Utils::String::VA("maps/mp/%s.d3dbsp", mapName))->asset.header.gfxWorld; + auto drawDistance = r_playerDrawDebugDistance.get(); + auto sqrDist = drawDistance * drawDistance; + switch (val) { case 1: for (auto i = 0; i < scene->sceneModelCount; i++) @@ -393,7 +399,7 @@ namespace Components if (!scene->sceneModel[i].model) continue; - if (Utils::Vec3SqrDistance(playerPosition, &scene->sceneModel[i].placement.base.origin) < r_playerDrawDebugDistance.get()) + if (Utils::Vec3SqrDistance(playerPosition, &scene->sceneModel[i].placement.base.origin) < sqrDist) { Game::R_AddDebugString(sceneModelsColor, scene->sceneModel[i].placement.base.origin, 1.0, scene->sceneModel[i].model->name); } @@ -407,7 +413,7 @@ namespace Components { for (int j = 0; j < scene->sceneDObj[i].obj->numModels; j++) { - if (Utils::Vec3SqrDistance(playerPosition, &scene->sceneDObj[i].placement.origin) < r_playerDrawDebugDistance.get()) + if (Utils::Vec3SqrDistance(playerPosition, &scene->sceneDObj[i].placement.origin) < sqrDist) { Game::R_AddDebugString(dobjsColor, scene->sceneDObj[i].placement.origin, 1.0, scene->sceneDObj[i].obj->models[j]->name); } @@ -424,7 +430,7 @@ namespace Components if (staticModel.model) { auto dist = Utils::Vec3SqrDistance(playerPosition, &staticModel.placement.origin); - if (dist < r_playerDrawDebugDistance.get()) + if (dist < sqrDist) { Game::R_AddDebugString(staticModelsColor, staticModel.placement.origin, 1.0, staticModel.model->name); } @@ -531,7 +537,7 @@ namespace Components Dvar::OnInit([] { - char* values[5] = + static char* values[5] = { "Disabled", "Scene Models", @@ -545,7 +551,7 @@ namespace Components Renderer::r_drawTriggers = Game::Dvar_RegisterBool("r_drawTriggers", false, Game::DVAR_FLAG_CHEAT, "Draw triggers"); Renderer::r_drawModelNames = Game::Dvar_RegisterEnum("r_drawModelNames", values, 0, Game::DVAR_FLAG_CHEAT, "Draw all model names"); Renderer::r_drawAABBTrees = Game::Dvar_RegisterBool("r_drawAabbTrees", false, Game::DVAR_FLAG_CHEAT, "Draw aabb trees"); - Renderer::r_playerDrawDebugDistance = Game::Dvar_RegisterInt("r_drawDebugProximity", 100000, 0, 500000, Game::DVAR_FLAG_SAVED, "r_draw debug functions draw distance, relative to the player"); + Renderer::r_playerDrawDebugDistance = Game::Dvar_RegisterInt("r_drawDebugProximity", 1000, 0, 50000, Game::DVAR_FLAG_SAVED, "r_draw debug functions draw distance, relative to the player"); }); } diff --git a/src/Utils/Utils.cpp b/src/Utils/Utils.cpp index 8a7a7cb8..5feb2980 100644 --- a/src/Utils/Utils.cpp +++ b/src/Utils/Utils.cpp @@ -152,7 +152,11 @@ namespace Utils float Vec3SqrDistance(float(*v1)[3], float(*v2)[3]) { - return static_cast(std::pow((*v2)[0] - (*v1)[0], 2) + std::pow((*v2)[1] - (*v1)[1], 2) + std::pow((*v2)[2] - (*v1)[2], 2)); + auto x = (*v2)[0] - (*v1)[0]; + auto y = (*v2)[1] - (*v1)[1]; + auto z = (*v2)[2] - (*v1)[2]; + + return x * x + y * y + z * z; }