From fccd09dee272e74684093bc65779746b7dfe1be8 Mon Sep 17 00:00:00 2001 From: Unreal Karaulov Date: Fri, 15 Nov 2024 15:14:41 +0300 Subject: [PATCH] Fix some compilation error --- src/bsp/Bsp.cpp | 26 +++++++++++++------------- src/bsp/BspMerger.h | 6 +++--- src/bsp/Entity.cpp | 2 -- src/editor/Renderer.cpp | 9 ++------- src/nav/LeafNavMeshGenerator.cpp | 30 +++++++++++++++--------------- src/nav/NavMesh.cpp | 4 ++-- src/nav/NavMesh.h | 10 +++++----- src/nav/NavMeshGenerator.cpp | 22 +++++++++++----------- src/util/Polygon3D.cpp | 10 +++++----- 9 files changed, 56 insertions(+), 63 deletions(-) diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 66754992..ed8a69f7 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -2938,7 +2938,7 @@ void Bsp::delete_oob_data(int clipFlags) { print_log(" Deleted {} entities\n", deletedEnts); ents = newEnts; - uint8_t* oobFaces = new uint8_t[faceCount]; + unsigned char* oobFaces = new unsigned char[faceCount]; memset(oobFaces, 0, faceCount * sizeof(bool)); int oobFaceCount = 0; @@ -3039,7 +3039,7 @@ void Bsp::delete_oob_data(int clipFlags) { } else { for (int k = 0; k < leaf.nMarkSurfaces; k++) { - unsigned int faceIdx = marksurfs[leaf.iFirstMarkSurface + k]; + int faceIdx = marksurfs[leaf.iFirstMarkSurface + k]; int offset = 0; for (int j = 0; j < faceIdx; j++) { @@ -3264,7 +3264,7 @@ void Bsp::delete_box_data(vec3 clipMins, vec3 clipMaxs) { print_log(" Deleted {} entities\n", deletedEnts); ents = newEnts; - uint8_t* oobFaces = new uint8_t[faceCount]; + unsigned char* oobFaces = new unsigned char[faceCount]; memset(oobFaces, 0, faceCount * sizeof(bool)); int oobFaceCount = 0; @@ -3358,7 +3358,7 @@ void Bsp::delete_box_data(vec3 clipMins, vec3 clipMaxs) { } else { for (int k = 0; k < leaf.nMarkSurfaces; k++) { - unsigned int faceIdx = marksurfs[leaf.iFirstMarkSurface + k]; + int faceIdx = marksurfs[leaf.iFirstMarkSurface + k]; int offset = 0; for (int j = 0; j < faceIdx; j++) { @@ -3766,11 +3766,11 @@ bool Bsp::subdivide_face(int faceIdx) { std::vector& cutPoly = polys[k]; newFaces[faceIdx + k] = faces[faceIdx]; - newFaces[faceIdx + k].iFirstEdge = surfedgePtr - newSurfEdges; + newFaces[faceIdx + k].iFirstEdge = (int)(surfedgePtr - newSurfEdges); newFaces[faceIdx + k].nEdges = (int)cutPoly.size(); - int vertOffset = vertPtr - newVerts; - int edgeOffset = edgePtr - newEdges; + int vertOffset = (int)(vertPtr - newVerts); + int edgeOffset = (int)(edgePtr - newEdges); for (int i = 0; i < cutPoly.size(); i++) { edgePtr->iVertex[0] = vertOffset + i; @@ -4062,9 +4062,9 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) { adjust_downscaled_texture_coordinates(textureId, oldWidth, oldHeight); // shrink texture lump - int removedBytes = palette - newPalette; + int removedBytes = (int)(palette - newPalette); unsigned char* texEnd = newPalette + 256 * sizeof(COLOR3); - int shiftBytes = (texEnd - textures) + removedBytes; + int shiftBytes = (int)(texEnd - textures) + removedBytes; memcpy(texEnd, texEnd + removedBytes, bsp_header.lump[LUMP_TEXTURES].nLength - shiftBytes); for (int k = textureId + 1; k < textureCount; k++) { @@ -4193,7 +4193,7 @@ void Bsp::downscale_invalid_textures() { continue; } - if (tex.nWidth * tex.nHeight > MAX_TEXTURE_SIZE) { + if ((unsigned int)tex.nWidth * tex.nHeight > MAX_TEXTURE_SIZE) { int oldWidth = tex.nWidth; int oldHeight = tex.nHeight; @@ -4204,13 +4204,13 @@ void Bsp::downscale_invalid_textures() { while (newWidth > 16) { newWidth -= 16; - newHeight = newWidth * ratio; + newHeight = (int)(newWidth * ratio); if (newHeight % 16 != 0) { continue; } - if (newWidth * newHeight <= MAX_TEXTURE_SIZE) { + if ((unsigned int)newWidth * newHeight <= MAX_TEXTURE_SIZE) { break; } } @@ -6354,7 +6354,7 @@ bool Bsp::validate() print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0136), texlen, tex->szName[0] != '\0' ? tex->szName : "UNKNOWN_NAME", texOffset, dataOffset); } } - else if (tex->nWidth * tex->nHeight > MAX_TEXTURE_SIZE) { + else if ((unsigned int)tex->nWidth * tex->nHeight > MAX_TEXTURE_SIZE) { print_log("Texture '{}' too large ({}x{})\n", tex->szName, tex->nWidth, tex->nHeight); } } diff --git a/src/bsp/BspMerger.h b/src/bsp/BspMerger.h index 3a0b0532..a9659d76 100644 --- a/src/bsp/BspMerger.h +++ b/src/bsp/BspMerger.h @@ -28,9 +28,9 @@ struct MAPBLOCK float zdelta_neg = other.maxs.z - mins.z; float zdelta_pos = maxs.z - other.mins.z; - int xdelta = xdelta_neg < xdelta_pos ? ceilf(xdelta_neg + 1.5f) : -ceilf(xdelta_pos + 1.5f); - int ydelta = ydelta_neg < ydelta_pos ? ceilf(ydelta_neg + 1.5f) : -ceilf(ydelta_pos + 1.5f); - int zdelta = zdelta_neg < zdelta_pos ? ceilf(zdelta_neg + 1.5f) : -ceilf(zdelta_pos + 1.5f); + float xdelta = xdelta_neg < xdelta_pos ? ceilf(xdelta_neg + 1.5f) : -ceilf(xdelta_pos + 1.5f); + float ydelta = ydelta_neg < ydelta_pos ? ceilf(ydelta_neg + 1.5f) : -ceilf(ydelta_pos + 1.5f); + float zdelta = zdelta_neg < zdelta_pos ? ceilf(zdelta_neg + 1.5f) : -ceilf(zdelta_pos + 1.5f); result.moveFixes = vec3(xdelta, ydelta, zdelta); result.moveFixes2 = vec3(-xdelta, -ydelta, -zdelta); diff --git a/src/bsp/Entity.cpp b/src/bsp/Entity.cpp index f50d1388..bcadb394 100644 --- a/src/bsp/Entity.cpp +++ b/src/bsp/Entity.cpp @@ -629,8 +629,6 @@ vec3 Entity::getHullOrigin(Bsp* map) { int modelIdx = getBspModelIdx(); if (modelIdx != -1) { - BSPMODEL& model = map->models[modelIdx]; - vec3 mins, maxs; map->get_model_vertex_bounds(modelIdx, mins, maxs); ori += (maxs + mins) * 0.5f; diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index a06e7fba..68414344 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -868,7 +868,7 @@ void Renderer::renderLoop() Line2D otherEdge(linkPoly.topdownVerts[k], linkPoly.topdownVerts[knext]); float t0, t1, t2, t3; - float overlapDist = thisEdge.getOverlapRanges(otherEdge, t0, t1, t2, t3); + thisEdge.getOverlapRanges(otherEdge, t0, t1, t2, t3); vec3 delta1 = poly.verts[inext] - poly.verts[n]; vec3 delta2 = linkPoly.verts[knext] - linkPoly.verts[k]; @@ -889,7 +889,6 @@ void Renderer::renderLoop() float stepUnits = 1.0f; float step = stepUnits / flatLen; TraceResult tr; - bool isBlocked = true; for (float f = 0; f < 0.5f; f += step) { vec3 test1 = mid1 + (delta1 * f) + testOffset; vec3 test2 = mid2 + (delta2 * f) + testOffset; @@ -912,10 +911,6 @@ void Renderer::renderLoop() drawLine(test3, test4, COLOR4(255, 0, 0, 255)); } } - - //if (isBlocked) { - // continue; - //} } glEnable(GL_DEPTH_TEST); @@ -2852,7 +2847,7 @@ void Renderer::drawPolygon3D(Polygon3D& poly, COLOR4 color) { verts[i].c = color; } - VertexBuffer buffer(g_app->colorShader, verts, poly.verts.size(), GL_TRIANGLE_FAN); + VertexBuffer buffer(g_app->colorShader, verts, (int)poly.verts.size(), GL_TRIANGLE_FAN); buffer.drawFull(); } diff --git a/src/nav/LeafNavMeshGenerator.cpp b/src/nav/LeafNavMeshGenerator.cpp index 6512578a..fcdf11d7 100644 --- a/src/nav/LeafNavMeshGenerator.cpp +++ b/src/nav/LeafNavMeshGenerator.cpp @@ -15,11 +15,11 @@ LeafNavMesh* LeafNavMeshGenerator::generate(Bsp* map) { - float NavMeshGeneratorGenStart = glfwGetTime(); + double NavMeshGeneratorGenStart = glfwGetTime(); - float createLeavesStart = glfwGetTime(); + double createLeavesStart = NavMeshGeneratorGenStart; std::vector leaves = getHullLeaves(map, 0, CONTENTS_EMPTY); - print_log("Created {} leaf nodes in {}\n", leaves.size(), glfwGetTime() - createLeavesStart); + print_log("Created {} leaf nodes in {}\n", leaves.size(), (float)(glfwGetTime() - createLeavesStart)); LeafOctree* octree = createLeafOctree(map, leaves, octreeDepth); LeafNavMesh* navmesh = new LeafNavMesh(leaves, octree); @@ -124,7 +124,7 @@ std::vector LeafNavMeshGenerator::getHullLeaves(Bsp* map, int modelIdx expandBoundingBox(face.verts[k], leaf.mins, leaf.maxs); } } - leaf.center /= leaf.leafFaces.size(); + leaf.center /= (float)leaf.leafFaces.size(); leaf.id = (int)emptyLeaves.size(); leaf.origin = leaf.center; @@ -150,7 +150,7 @@ void LeafNavMeshGenerator::getOctreeBox(Bsp* map, vec3& min, vec3& max) { } LeafOctree* LeafNavMeshGenerator::createLeafOctree(Bsp* map, std::vector& nodes, int treeDepth) { - float treeStart = glfwGetTime(); + double treeStart = glfwGetTime(); vec3 treeMin, treeMax; getOctreeBox(map, treeMin, treeMax); @@ -162,13 +162,13 @@ LeafOctree* LeafNavMeshGenerator::createLeafOctree(Bsp* map, std::vector {} in {}\n", treeDepth, - treeMax.x, treeMax.x / pow(2, treeDepth), (float)glfwGetTime() - treeStart); + treeMax.x, treeMax.x / pow(2, treeDepth), (float)(glfwGetTime() - treeStart)); return octree; } void LeafNavMeshGenerator::setLeafOrigins(Bsp* map, LeafNavMesh* mesh) { - float timeStart = glfwGetTime(); + double timeStart = glfwGetTime(); for (int i = 0; i < mesh->nodes.size(); i++) { LeafNode& node = mesh->nodes[i]; @@ -196,7 +196,7 @@ void LeafNavMeshGenerator::setLeafOrigins(Bsp* map, LeafNavMesh* mesh) { } } - print_log("Set leaf origins in {}\n", (float)glfwGetTime() - timeStart); + print_log("Set leaf origins in {}\n", (float)(glfwGetTime() - timeStart)); } vec3 LeafNavMeshGenerator::getBestPolyOrigin(Bsp* map, Polygon3D& poly, vec3 bias) { @@ -215,8 +215,8 @@ vec3 LeafNavMeshGenerator::getBestPolyOrigin(Bsp* map, Polygon3D& poly, vec3 bia vec3 bestPos = bias; float pad = 1.0f + EPSILON; // don't choose a point right against a face of the volume - for (int y = poly.localMins.y + pad; y < poly.localMaxs.y - pad; y += step) { - for (int x = poly.localMins.x + pad; x < poly.localMaxs.x - pad; x += step) { + for (float y = poly.localMins.y + pad; y < poly.localMaxs.y - pad; y += step) { + for (float x = poly.localMins.x + pad; x < poly.localMaxs.x - pad; x += step) { vec3 testPos = poly.unproject(vec2(x, y)); testPos.z += NAV_BOTTOM_EPSILON; @@ -250,7 +250,7 @@ vec3 LeafNavMeshGenerator::getBestPolyOrigin(Bsp* map, Polygon3D& poly, vec3 bia void LeafNavMeshGenerator::linkNavLeaves(Bsp* map, LeafNavMesh* mesh) { int numLinks = 0; - float linkStart = glfwGetTime(); + double linkStart = glfwGetTime(); std::vector regionLeaves; regionLeaves.resize(mesh->nodes.size()); @@ -274,7 +274,7 @@ void LeafNavMeshGenerator::linkNavLeaves(Bsp* map, LeafNavMesh* mesh) { } } - print_log("Added {} nav leaf links in {}\n", numLinks, (float)glfwGetTime() - linkStart); + print_log("Added {} nav leaf links in {}\n", numLinks, (float)(glfwGetTime() - linkStart)); } void LeafNavMeshGenerator::linkEntityLeaves(Bsp* map, LeafNavMesh* mesh) { @@ -428,7 +428,7 @@ int LeafNavMeshGenerator::tryFaceLinkLeaves(Bsp* map, LeafNavMesh* mesh, int src } void LeafNavMeshGenerator::calcPathCosts(Bsp* bsp, LeafNavMesh* mesh) { - float markStart = glfwGetTime(); + double markStart = glfwGetTime(); for (int i = 0; i < mesh->nodes.size(); i++) { LeafNode& node = mesh->nodes[i]; @@ -459,13 +459,13 @@ void LeafNavMeshGenerator::calcPathCosts(Bsp* bsp, LeafNavMesh* mesh) { } } - print_log("Calculated path costs in {}\n", (float)glfwGetTime() - markStart); + print_log("Calculated path costs in {}\n", (float)(glfwGetTime() - markStart)); } void LeafNavMeshGenerator::addPathCost(LeafLink& link, Bsp* bsp, vec3 start, vec3 end, bool isDrop) { TraceResult tr; - int steps = (end - start).length() / 8.0f; + float steps = (end - start).length() / 8.0f; vec3 delta = end - start; vec3 dir = delta.normalize(); diff --git a/src/nav/NavMesh.cpp b/src/nav/NavMesh.cpp index e2b201f9..5b774b77 100644 --- a/src/nav/NavMesh.cpp +++ b/src/nav/NavMesh.cpp @@ -6,7 +6,7 @@ #include #include "GLFW/glfw3.h" -bool NavNode::addLink(int node, int srcEdge, int dstEdge, int zDist, uint8_t _flags) { +bool NavNode::addLink(int node, int srcEdge, int dstEdge, int zDist, unsigned char _flags) { if (srcEdge < 0 || srcEdge >= MAX_NAV_POLY_VERTS) { print_log("Error: add link to invalid src edge {}\n", srcEdge); return false; @@ -88,7 +88,7 @@ NavMesh::NavMesh(std::vector faces) { sizeof(NavNode), sizeof(NavLink)); } -bool NavMesh::addLink(int from, int to, int srcEdge, int dstEdge, int zDist, uint8_t flags) { +bool NavMesh::addLink(int from, int to, int srcEdge, int dstEdge, int zDist, unsigned char flags) { if (from < 0 || to < 0 || from >= MAX_NAV_POLYS || to >= MAX_NAV_POLYS) { print_log("Error: add link from/to invalid node {} {}\n", from, to); return false; diff --git a/src/nav/NavMesh.h b/src/nav/NavMesh.h index c61bcd92..fbb2a3fb 100644 --- a/src/nav/NavMesh.h +++ b/src/nav/NavMesh.h @@ -14,9 +14,9 @@ #define NAV_AUTOCLIMB_HEIGHT 117 struct NavLink { - uint8_t srcEdge : 4; // edge to move from in source poly - uint8_t dstEdge : 4; // edge to move to in target/destination poly - uint8_t flags; + unsigned char srcEdge : 4; // edge to move from in source poly + unsigned char dstEdge : 4; // edge to move to in target/destination poly + unsigned char flags; int node; // which poly is linked to. -1 = end of links int zDist; // minimum height difference between the connecting edges }; @@ -27,7 +27,7 @@ struct NavNode { unsigned int id; // adds a link to node "node" on edge "edge" with height difference "zDist" - bool addLink(int node, int srcEdge, int dstEdge, int zDist, uint8_t flags); + bool addLink(int node, int srcEdge, int dstEdge, int zDist, unsigned char flags); int numLinks(); }; @@ -43,7 +43,7 @@ class NavMesh { NavMesh(std::vector polys); - bool addLink(int from, int to, int srcEdge, int dstEdge, int zDist, uint8_t flags); + bool addLink(int from, int to, int srcEdge, int dstEdge, int zDist, unsigned char flags); void clear(); diff --git a/src/nav/NavMeshGenerator.cpp b/src/nav/NavMeshGenerator.cpp index decb7eee..8c56c0a6 100644 --- a/src/nav/NavMeshGenerator.cpp +++ b/src/nav/NavMeshGenerator.cpp @@ -12,7 +12,7 @@ #include "GLFW/glfw3.h" NavMesh* NavMeshGenerator::generate(Bsp* map, int hull) { - float NavMeshGeneratorGenStart = glfwGetTime(); + double NavMeshGeneratorGenStart = glfwGetTime(); std::vector solidFaces = getHullFaces(map, hull); std::vector faces = getInteriorFaces(map, hull, solidFaces); @@ -24,7 +24,7 @@ NavMesh* NavMeshGenerator::generate(Bsp* map, int hull) { delete solidFaces[i]; } - print_log("Generated nav mesh in {}\n", faces.size(), glfwGetTime() - NavMeshGeneratorGenStart); + print_log("Generated nav mesh in {}\n", faces.size(), (float)(glfwGetTime() - NavMeshGeneratorGenStart)); NavMesh* navmesh = new NavMesh(faces); linkNavPolys(map, navmesh); @@ -141,7 +141,7 @@ std::vector NavMeshGenerator::getInteriorFaces(Bsp* map, int hull, st size_t cuttingPolyCount = faces.size(); size_t presplit = faces.size(); int numSplits = 0; - float startTime = glfwGetTime(); + double startTime = glfwGetTime(); bool doSplit = true; bool doCull = true; bool walkableSurfacesOnly = true; @@ -234,7 +234,7 @@ std::vector NavMeshGenerator::getInteriorFaces(Bsp* map, int hull, st } void NavMeshGenerator::mergeFaces(Bsp* map, std::vector& faces) { - float mergeStart = glfwGetTime(); + double mergeStart = glfwGetTime(); vec3 treeMin, treeMax; getOctreeBox(map, treeMin, treeMax); @@ -340,7 +340,7 @@ void NavMeshGenerator::cullTinyFaces(std::vector& faces) { void NavMeshGenerator::linkNavPolys(Bsp* map, NavMesh* mesh) { int numLinks = 0; - float linkStart = glfwGetTime(); + double linkStart = glfwGetTime(); for (int i = 0; i < mesh->numPolys; i++) { for (int k = i + 1; k < mesh->numPolys; k++) { @@ -350,7 +350,7 @@ void NavMeshGenerator::linkNavPolys(Bsp* map, NavMesh* mesh) { } } - print_log("Added {} nav poly links in {}\n", numLinks, (float)glfwGetTime() - linkStart); + print_log("Added {} nav poly links in {}\n", numLinks, (float)(glfwGetTime() - linkStart)); } int NavMeshGenerator::tryEdgeLinkPolys(Bsp* map, NavMesh* mesh, int srcPolyIdx, int dstPolyIdx) { @@ -388,7 +388,7 @@ int NavMeshGenerator::tryEdgeLinkPolys(Bsp* map, NavMesh* mesh, int srcPolyIdx, float min2 = std::min(e3.z, e4.z); float max2 = std::max(e3.z, e4.z); - int zDist = 0; // 0 = edges are are the same height or cross at some point + float zDist = 0.0f; // 0 = edges are are the same height or cross at some point if (max1 < min2) { // dst is above src zDist = ceilf(min2 - max1); } @@ -441,17 +441,17 @@ int NavMeshGenerator::tryEdgeLinkPolys(Bsp* map, NavMesh* mesh, int srcPolyIdx, // hard to pull off and no map requires that if (srcPoly.verts[i].z < dstPoly.verts[k].z) { - mesh->addLink(dstPolyIdx, srcPolyIdx, k, i, -zDist, 0); + mesh->addLink(dstPolyIdx, srcPolyIdx, k, i, (int)-zDist, 0); } else { - mesh->addLink(srcPolyIdx, dstPolyIdx, i, k, zDist, 0); + mesh->addLink(srcPolyIdx, dstPolyIdx, i, k, (int)zDist, 0); } return 1; } - mesh->addLink(srcPolyIdx, dstPolyIdx, i, k, zDist, 0); - mesh->addLink(dstPolyIdx, srcPolyIdx, k, i, -zDist, 0); + mesh->addLink(srcPolyIdx, dstPolyIdx, i, k, (int)zDist, 0); + mesh->addLink(dstPolyIdx, srcPolyIdx, k, i, (int)-zDist, 0); // TODO: multiple edge links are possible for overlapping polys return 2; diff --git a/src/util/Polygon3D.cpp b/src/util/Polygon3D.cpp index 52e4d4a1..a8f27642 100644 --- a/src/util/Polygon3D.cpp +++ b/src/util/Polygon3D.cpp @@ -441,11 +441,11 @@ namespace GrahamScan { } int squaredDist(vec2 p1, vec2 p2) { - return ((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); + return (int)((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); } int direction(vec2 a, vec2 b, vec2 c) { - int val = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y); + int val = (int)((b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)); if (val == 0) return 0; //colinear else if (val < 0) @@ -464,13 +464,13 @@ namespace GrahamScan { std::vector findConvexHull(vec2 points[], int n) { std::vector convexHullPoints; - int minY = points[0].y, min = 0; + int minY = (int)points[0].y, min = 0; for (int i = 1; i < n; i++) { - int y = points[i].y; + int y = (int)points[i].y; //find bottom most or left most point if ((y < minY) || (minY == y) && points[i].x < points[min].x) { - minY = points[i].y; + minY = (int)points[i].y; min = i; } }