diff --git a/include/light/bounce.hh b/include/light/bounce.hh index dfcfcadb..23fe7b85 100644 --- a/include/light/bounce.hh +++ b/include/light/bounce.hh @@ -33,7 +33,7 @@ struct bouncelight_t std::vector poly; std::vector poly_edgeplanes; qvec3f pos; - std::map colorByStyle; + std::unordered_map colorByStyle; qvec3d componentwiseMaxColor; // cached maximum color in the colorByStyle, used for culling so we don't need to loop // through colorByStyle qvec3f surfnormal; diff --git a/include/light/ltface.hh b/include/light/ltface.hh index c4c5cf51..834487c1 100644 --- a/include/light/ltface.hh +++ b/include/light/ltface.hh @@ -47,7 +47,7 @@ extern std::atomic fully_transparent_lightmaps; void PrintFaceInfo(const mface_t *face, const mbsp_t *bsp); // FIXME: remove light param. add normal param and dir params. vec_t GetLightValue(const settings::worldspawn_keys &cfg, const light_t *entity, vec_t dist); -std::map GetDirectLighting( +std::unordered_map GetDirectLighting( const mbsp_t *bsp, const settings::worldspawn_keys &cfg, const qvec3d &origin, const qvec3d &normal); void SetupDirt(settings::worldspawn_keys &cfg); float DirtAtPoint(const settings::worldspawn_keys &cfg, raystream_intersection_t *rs, const qvec3d &point, diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 92a04942..ede49321 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -133,6 +133,22 @@ struct hashvert_t size_t num; }; +struct VertexHash +{ + size_t operator()(const qvec3i &v) const noexcept { + return (v[0] / 3) << 10 | + (static_cast(v[1] / 3)) << 20 | + (v[2] / 3); + } +}; + +struct EdgeHash +{ + size_t operator()(const std::pair &pair) const noexcept { + return (pair.first << (sizeof(size_t) * 4)) | pair.second; + } +}; + struct mapdata_t { /* Arrays of actual items */ @@ -150,7 +166,7 @@ struct mapdata_t std::unordered_map> planehash; // hashed vertices; generated by EmitVertices - std::map> hashverts; + std::unordered_map, VertexHash> hashverts; // find vector of points in hash closest to vec inline auto find_hash_vector(const qvec3d &vec) @@ -189,7 +205,7 @@ struct mapdata_t } // hashed edges; generated by EmitEdges - std::map, int64_t> hashedges; + std::unordered_map, int64_t, EdgeHash> hashedges; inline void add_hash_edge(size_t v1, size_t v2, int64_t i) { diff --git a/light/bounce.cc b/light/bounce.cc index b297bc4d..a8e95c6e 100644 --- a/light/bounce.cc +++ b/light/bounce.cc @@ -48,7 +48,7 @@ using namespace polylib; mutex bouncelights_lock; static std::vector bouncelights; -std::map> bouncelightsByFacenum; +std::unordered_map> bouncelightsByFacenum; static bool Face_ShouldBounce(const mbsp_t *bsp, const mface_t *face) { @@ -91,7 +91,7 @@ qvec3b Face_LookupTextureColor(const mbsp_t *bsp, const mface_t *face) return {127}; } -static void AddBounceLight(const qvec3d &pos, const std::map &colorByStyle, const qvec3d &surfnormal, +static void AddBounceLight(const qvec3d &pos, const std::unordered_map &colorByStyle, const qvec3d &surfnormal, vec_t area, const mface_t *face, const mbsp_t *bsp) { for (const auto &styleColor : colorByStyle) { @@ -180,7 +180,7 @@ static void MakeBounceLightsThread(const settings::worldspawn_keys &cfg, const m facemidpoint += faceplane.normal; // lift 1 unit // average them, area weighted - map sum; + std::unordered_map sum; for (const auto &lightmap : surf.lightmapsByStyle) { for (const auto &sample : lightmap.samples) { @@ -206,7 +206,7 @@ static void MakeBounceLightsThread(const settings::worldspawn_keys &cfg, const m qvec3d blendedcolor = mix(qvec3d{127. / 255.}, texturecolor, cfg.bouncecolorscale.value()); // final colors to emit - map emitcolors; + std::unordered_map emitcolors; for (const auto &styleColor : sum) { emitcolors[styleColor.first] = styleColor.second * blendedcolor; diff --git a/light/phong.cc b/light/phong.cc index e2b697fa..f6e6a6d7 100644 --- a/light/phong.cc +++ b/light/phong.cc @@ -171,7 +171,7 @@ static float AngleBetweenPoints(const qvec3f &p1, const qvec3f &p2, const qvec3f } static bool s_builtPhongCaches; -static std::map> vertex_normals; +static std::unordered_map> vertex_normals; static map> smoothFaces; static map> vertsToFaces; static map> planesToFaces; @@ -554,7 +554,7 @@ void CalculateVertexNormals(const mbsp_t *bsp) std::copy(neighboursToSmooth.begin(), neighboursToSmooth.end(), std::back_inserter(fPlusNeighbours)); // global vertex index -> smoothed normal - std::map smoothedNormals; + std::unordered_map smoothedNormals; // walk fPlusNeighbours for (auto f2 : fPlusNeighbours) { diff --git a/qbsp/brush.cc b/qbsp/brush.cc index e56bcadb..1a8fad72 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -35,9 +35,7 @@ const maptexinfo_t& side_t::get_texinfo() const std::unique_ptr bspbrush_t::copy_unique() const { - bspbrush_t *copy = new bspbrush_t{*this}; - - return std::unique_ptr(copy); + return std::make_unique(*this); } /* diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index 455cc12f..0bfb2acb 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -101,7 +101,7 @@ Creates a new axial brush */ std::unique_ptr BrushFromBounds(const aabb3d &bounds) { - auto b = std::unique_ptr(new bspbrush_t{}); + auto b = std::make_unique(); b->sides.resize(6); for (int i = 0; i < 3; i++) @@ -858,9 +858,8 @@ static void BuildTree_r(node_t *node, std::vector> b // allocate children before recursing for (int i = 0; i < 2; i++) { - auto* newnode = new node_t{}; + auto &newnode = node->children[i] = std::make_unique(); newnode->parent = node; - node->children[i] = std::unique_ptr(newnode); } auto children_volumes = SplitBrush(node->volume->copy_unique(), node->planenum); @@ -881,7 +880,7 @@ BrushBSP */ static std::unique_ptr BrushBSP(mapentity_t *entity, std::vector> brushlist) { - auto tree = std::unique_ptr(new tree_t{}); + auto tree = std::make_unique(); logging::print(logging::flag::PROGRESS, "---- {} ----\n", __func__); @@ -895,7 +894,7 @@ static std::unique_ptr BrushBSP(mapentity_t *entity, std::vectororiginal->entitynum, b->original->brushnum); @@ -925,13 +924,13 @@ static std::unique_ptr BrushBSP(mapentity_t *entity, std::vector(new node_t{}); + auto headnode = std::make_unique(); headnode->bounds = entity->bounds; - headnode->children[0] = std::unique_ptr(new node_t{}); + headnode->children[0] = std::make_unique(); headnode->children[0]->planenum = PLANENUM_LEAF; headnode->children[0]->contents = qbsp_options.target_game->create_empty_contents(); headnode->children[0]->parent = headnode.get(); - headnode->children[1] = std::unique_ptr(new node_t{}); + headnode->children[1] = std::make_unique(); headnode->children[1]->planenum = PLANENUM_LEAF; headnode->children[1]->contents = qbsp_options.target_game->create_empty_contents(); headnode->children[1]->parent = headnode.get(); @@ -946,8 +945,7 @@ static std::unique_ptr BrushBSP(mapentity_t *entity, std::vector(new node_t{}); + auto node = std::make_unique(); node->volume = BrushFromBounds(tree->bounds.grow(SIDESPACE)); diff --git a/qbsp/csg.cc b/qbsp/csg.cc index 286132c4..7d616458 100644 --- a/qbsp/csg.cc +++ b/qbsp/csg.cc @@ -49,7 +49,7 @@ MergeFace. */ std::unique_ptr NewFaceFromFace(const face_t *in) { - auto newf = std::unique_ptr(new face_t{}); + auto newf = std::make_unique(); newf->planenum = in->planenum; newf->texinfo = in->texinfo; diff --git a/qbsp/faces.cc b/qbsp/faces.cc index d97ba9fb..6b9cd407 100644 --- a/qbsp/faces.cc +++ b/qbsp/faces.cc @@ -482,7 +482,7 @@ static std::unique_ptr FaceFromPortal(portal_t *p, int pside) if (!side) return nullptr; // portal does not bridge different visible contents - auto f = std::unique_ptr(new face_t{}); + auto f = std::make_unique(); f->texinfo = side->texinfo; f->planenum = side->planenum; diff --git a/qbsp/tree.cc b/qbsp/tree.cc index 00cec80b..a2b92863 100644 --- a/qbsp/tree.cc +++ b/qbsp/tree.cc @@ -30,11 +30,7 @@ portal_t *tree_t::create_portal() { - auto *result = new portal_t{}; - - portals.push_back(std::unique_ptr(result)); - - return result; + return portals.emplace_back(std::make_unique()).get(); } /*