diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 500db376..8976241e 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -7002,7 +7002,7 @@ bool Bsp::recursiveHullCheck(int hull, int num, float p1f, float p2f, vec3 p1, v { trace->flFraction = midf; trace->vecEndPos = mid; - print_log("backup past 0\n"); + //print_log("backup past 0\n"); return false; } diff --git a/src/editor/BspRenderer.cpp b/src/editor/BspRenderer.cpp index 76bc3b06..912833ea 100644 --- a/src/editor/BspRenderer.cpp +++ b/src/editor/BspRenderer.cpp @@ -1498,7 +1498,9 @@ void BspRenderer::generateNavMeshBuffer() { renderClip->faceMaths[hull] = std::move(navFaceMaths); - std::ofstream file(map->bsp_name + "_hull" + std::to_string(hull) + ".obj", std::ios::out | std::ios::trunc); + std::string navmesh_hull3_path = g_working_dir + map->bsp_name + "_hull" + std::to_string(hull) + ".obj"; + + std::ofstream file(navmesh_hull3_path, std::ios::out | std::ios::trunc); for (int i = 0; i < allVerts.size(); i++) { vec3 v = vec3(allVerts[i].pos.x, allVerts[i].pos.y, allVerts[i].pos.z); file << "v " << std::fixed << std::setprecision(2) << v.x << " " << v.y << " " << v.z << std::endl; @@ -1506,7 +1508,7 @@ void BspRenderer::generateNavMeshBuffer() { for (int i = 0; i < allVerts.size(); i += 3) { file << "f " << (i + 1) << " " << (i + 2) << " " << (i + 3) << std::endl; } - print_log("Wrote {} verts\n", allVerts.size()); + print_log("Wrote {} verts to {}\n", allVerts.size(), navmesh_hull3_path); file.close(); } @@ -1923,12 +1925,6 @@ void BspRenderer::generateClipnodeBuffer(int modelIdx) { generateClipnodeBufferForHull(modelIdx, i); } - - if (modelIdx == 0) - { - /*generateNavMeshBuffer(); - generateLeafNavMeshBuffer();*/ - } } void BspRenderer::updateClipnodeOpacity(unsigned char newValue) @@ -2047,6 +2043,7 @@ void BspRenderer::refreshEnt(int entIdx) int skin = -1; int sequence = -1; int body = -1; + float scale = 1.0f; auto& rendEntity = renderEnts[entIdx]; @@ -2119,6 +2116,22 @@ void BspRenderer::refreshEnt(int entIdx) } } + if (ent->hasKey("scale") || g_app->fgd) + { + if (ent->hasKey("scale") && isFloating(ent->keyvalues["scale"])) + { + scale = str_to_float(ent->keyvalues["scale"]); + } + if (scale <= 0 && g_app->fgd) + { + FgdClass* fgdClass = g_app->fgd->getFgdClass(ent->classname); + if (fgdClass) + { + scale = fgdClass->scale; + } + } + } + if (ent->hasKey("sequence") || g_app->fgd) { if (ent->hasKey("sequence") && isNumeric(ent->keyvalues["sequence"])) @@ -2214,13 +2227,13 @@ void BspRenderer::refreshEnt(int entIdx) { if (FindPathInAssets(map, modelpath, newModelPath)) { - if (rendEntity.pointEntCube) + if (rendEntity.pointEntCube && std::fabs(scale - 1.0f) < EPSILON) { rendEntity.spr = AddNewSpriteToRender(newModelPath, rendEntity.pointEntCube->mins, rendEntity.pointEntCube->maxs, 1.0f); } else { - rendEntity.spr = AddNewSpriteToRender(newModelPath); + rendEntity.spr = AddNewSpriteToRender(newModelPath, scale); } } else @@ -2265,13 +2278,13 @@ void BspRenderer::refreshEnt(int entIdx) { if (FindPathInAssets(map, fgdClass->sprite, newModelPath)) { - if (rendEntity.pointEntCube) + if (rendEntity.pointEntCube && std::fabs(scale - 1.0f) < EPSILON) { rendEntity.spr = AddNewSpriteToRender(newModelPath, rendEntity.pointEntCube->mins, rendEntity.pointEntCube->maxs, 1.0f); } else { - rendEntity.spr = AddNewSpriteToRender(newModelPath); + rendEntity.spr = AddNewSpriteToRender(newModelPath, scale); } } else @@ -2313,13 +2326,13 @@ void BspRenderer::refreshEnt(int entIdx) { if (FindPathInAssets(map, fgdClass->model, newModelPath)) { - if (rendEntity.pointEntCube) + if (rendEntity.pointEntCube && std::fabs(scale - 1.0f) < EPSILON) { rendEntity.spr = AddNewSpriteToRender(newModelPath, rendEntity.pointEntCube->mins, rendEntity.pointEntCube->maxs, 1.0f); } else { - rendEntity.spr = AddNewSpriteToRender(newModelPath); + rendEntity.spr = AddNewSpriteToRender(newModelPath, scale); } } else diff --git a/src/editor/Fgd.cpp b/src/editor/Fgd.cpp index d633c3d2..9f4047fd 100644 --- a/src/editor/Fgd.cpp +++ b/src/editor/Fgd.cpp @@ -729,7 +729,7 @@ void Fgd::processClassInheritance() { if (classes[i]->modelSequence <= 0) { - if (isNumeric(classes[i]->keyvalues[c].defaultValue)) + if (classes[i]->keyvalues[c].iType == FGD_KEY_TYPES::FGD_KEY_INTEGER) { classes[i]->modelSequence = str_to_int(classes[i]->keyvalues[c].defaultValue); } @@ -739,7 +739,7 @@ void Fgd::processClassInheritance() { if (classes[i]->modelBody <= 0) { - if (isNumeric(classes[i]->keyvalues[c].defaultValue)) + if (classes[i]->keyvalues[c].iType == FGD_KEY_TYPES::FGD_KEY_INTEGER) { classes[i]->modelBody = str_to_int(classes[i]->keyvalues[c].defaultValue); } @@ -749,12 +749,24 @@ void Fgd::processClassInheritance() { if (classes[i]->modelSkin <= 0) { - if (isNumeric(classes[i]->keyvalues[c].defaultValue)) + if (classes[i]->keyvalues[c].iType == FGD_KEY_TYPES::FGD_KEY_INTEGER) { classes[i]->modelSkin = str_to_int(classes[i]->keyvalues[c].defaultValue); } } } + else if (classes[i]->keyvalues[c].name == "scale" || + classes[i]->keyvalues[c].name == "sprite_scale") + { + if (classes[i]->keyvalues[c].iType == FGD_KEY_TYPES::FGD_KEY_INTEGER) + { + classes[i]->scale = str_to_int(classes[i]->keyvalues[c].defaultValue); + } + else if (classes[i]->keyvalues[c].iType == FGD_KEY_TYPES::FGD_KEY_STRING) + { + classes[i]->scale = str_to_float(classes[i]->keyvalues[c].defaultValue); + } + } } } } diff --git a/src/editor/Fgd.h b/src/editor/Fgd.h index ffb9244c..41767363 100644 --- a/src/editor/Fgd.h +++ b/src/editor/Fgd.h @@ -71,6 +71,7 @@ struct FgdClass COLOR3 color; vec3 offset; hashmap otherTypes; // unrecognized types + float scale; // if false, then need to get props from the base class bool colorSet; @@ -93,6 +94,7 @@ struct FgdClass color = { 220, 0, 220 }; offset = vec3(); modelSkin = modelBody = modelSequence = 0; + scale = 1.0f; } // get parent classes from youngest to oldest, in right-to-left order diff --git a/src/editor/Gui.cpp b/src/editor/Gui.cpp index 6afd294b..6cb5d3f9 100644 --- a/src/editor/Gui.cpp +++ b/src/editor/Gui.cpp @@ -4524,8 +4524,17 @@ void Gui::drawMenuBar() rend->pushUndoCommand(createCommand); } IMGUI_TOOLTIP(g, "Create a point entity for use with the culling tool. 2 of these define the bounding box for structure culling operations.\n"); + ImGui::EndMenu(); } + + if (ImGui::MenuItem("Generate nav mesh", NULL, false, (!rend->debugNavMesh || !g_app->debugLeafNavMesh))) + { + rend->generateNavMeshBuffer(); + rend->generateLeafNavMeshBuffer(); + } + IMGUI_TOOLTIP(g, "I don't know for what it needs :) From original bspguy repository + crash fixes. \n"); + if (ImGui::BeginMenu("MAP TRANSFORMATION [WIP]", map)) { if (ImGui::MenuItem("Mirror map x/y", NULL, false, map)) diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index ab28a814..db762a3e 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -922,8 +922,12 @@ void Renderer::renderLoop() } } + if (debugTraceStart != vec3()) + { + glLineWidth(currentLineWidth); + } + if (debugLeafNavMesh) { - glLineWidth(1); glDisable(GL_DEPTH_TEST); Bsp* map = mapRenderers[0]->map; @@ -937,7 +941,6 @@ void Renderer::renderLoop() if (leafNavIdx >= 0 && leafNavIdx < debugLeafNavMesh->nodes.size()) { if (pickInfo.selectedEnts.size()) { - glDisable(GL_DEPTH_TEST); int endNode = debugLeafNavMesh->getNodeIdx(map, map->ents[pickInfo.selectedEnts[0]]); //vector route = debugLeafNavMesh->AStarRoute(leafNavIdx, endNode); @@ -1069,12 +1072,8 @@ void Renderer::renderLoop() colorShader->popMatrix(MAT_PROJECTION); colorShader->popMatrix(MAT_VIEW); */ + glEnable(GL_DEPTH_TEST); } - if (debugTraceStart != vec3()) - { - glLineWidth(currentLineWidth); - } - glEnable(GL_CULL_FACE); } diff --git a/src/main.cpp b/src/main.cpp index 20dc6421..e8ab50a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ // Solve: // Create empty hull 0 box ? -std::string g_version_string = "NewBSPGuy v4.29"; +std::string g_version_string = "NewBSPGuy v4.30"; bool g_verbose = false; diff --git a/src/res/Sprite.cpp b/src/res/Sprite.cpp index 2b61373e..a19c9c4b 100644 --- a/src/res/Sprite.cpp +++ b/src/res/Sprite.cpp @@ -217,13 +217,19 @@ Sprite::Sprite(const std::string& filename, const vec3& mins , const vec3& maxs tmpSpriteImage.spriteCube = new EntCube(); - if (!useOwnSettigns) + if (!useOwnSettigns || (mins == maxs && mins == vec3())) { tmpSpriteImage.spriteCube->mins = { -5.0f, 0.0f, 0.0f }; tmpSpriteImage.spriteCube->maxs = { 5.0f, tmpSpriteImage.frameinfo.width * 1.0f, tmpSpriteImage.frameinfo.height * 1.0f }; tmpSpriteImage.spriteCube->mins += vec3(0.0f, tmpSpriteImage.frameinfo.origin[0] * 1.0f, tmpSpriteImage.frameinfo.origin[1] * -1.0f); tmpSpriteImage.spriteCube->maxs += vec3(0.0f, tmpSpriteImage.frameinfo.origin[0] * 1.0f, tmpSpriteImage.frameinfo.origin[1] * -1.0f); + + if (useOwnSettigns) + { + tmpSpriteImage.spriteCube->mins *= scale; + tmpSpriteImage.spriteCube->maxs *= scale; + } } else { @@ -269,6 +275,21 @@ Sprite* AddNewSpriteToRender(const std::string& path, unsigned int sum) } } +Sprite* AddNewSpriteToRender(const std::string& path, float scale) +{ + unsigned int crc32 = GetCrc32InMemory((unsigned char*)path.data(), (unsigned int)path.size(), *(int*)&scale); + + if (spr_models.find(crc32) != spr_models.end()) + { + return spr_models[crc32]; + } + else + { + Sprite* newModel = new Sprite(path, vec3(),vec3(), scale, true); + spr_models[crc32] = newModel; + return newModel; + } +} Sprite* AddNewSpriteToRender(const std::string& path, vec3 mins, vec3 maxs, float scale) { diff --git a/src/res/Sprite.h b/src/res/Sprite.h index 9c883d3c..db25293b 100644 --- a/src/res/Sprite.h +++ b/src/res/Sprite.h @@ -90,4 +90,5 @@ void TestSprite(); extern std::map spr_models; Sprite* AddNewSpriteToRender(const std::string & path, unsigned int sum = 0); +Sprite* AddNewSpriteToRender(const std::string& path, float scale); Sprite* AddNewSpriteToRender(const std::string& path, vec3 mins, vec3 maxs, float scale); \ No newline at end of file diff --git a/src/util/util.cpp b/src/util/util.cpp index 95055667..7e101395 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -225,6 +225,23 @@ bool isNumeric(const std::string& s) return it == s.end(); } +bool isFloating(const std::string& s) +{ + if (s.empty()) + return false; + std::string::const_iterator it = s.begin(); + int points = 0; + + while (it != s.end() && (isdigit(*it) || *it == '.')) + { + ++it; + if (*it == '.') + points++; + } + + return it == s.end() && points <= 1; +} + std::string toLowerCase(const std::string& s) { std::string ret = s; diff --git a/src/util/util.h b/src/util/util.h index a2e856b1..15b82545 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -65,6 +65,8 @@ std::string stripExt(const std::string& filename); std::string stripFileName(const std::string& path); std::wstring stripFileName(const std::wstring& path); +bool isFloating(const std::string& s); + bool isNumeric(const std::string& s); bool dirExists(const std::string& dirName);