diff --git a/common/bsputils.cc b/common/bsputils.cc index c80c6012..02118fca 100644 --- a/common/bsputils.cc +++ b/common/bsputils.cc @@ -198,9 +198,11 @@ bool Light_PointInSolid(const bsp2_t *bsp, const vec3_t point ) return Light_PointInSolid_r(bsp, bsp->dmodels[0].headnode[0], point); } -void -Face_MakeInwardFacingEdgePlanes(const bsp2_t *bsp, const bsp2_dface_t *face, plane_t *out) +plane_t * +Face_AllocInwardFacingEdgePlanes(const bsp2_t *bsp, const bsp2_dface_t *face) { + plane_t *out = (plane_t *)calloc(face->numedges, sizeof(plane_t)); + const plane_t faceplane = Face_Plane(bsp, face); for (int i=0; inumedges; i++) { @@ -216,6 +218,8 @@ Face_MakeInwardFacingEdgePlanes(const bsp2_t *bsp, const bsp2_dface_t *face, pla CrossProduct(edgevec, faceplane.normal, dest->normal); dest->dist = DotProduct(dest->normal, v0); } + + return out; } bool diff --git a/include/common/bsputils.hh b/include/common/bsputils.hh index db9fd5fb..66f31860 100644 --- a/include/common/bsputils.hh +++ b/include/common/bsputils.hh @@ -36,7 +36,7 @@ int Face_Contents(const bsp2_t *bsp, const bsp2_dface_t *face); const dmodel_t *BSP_DModelForModelString(const bsp2_t *bsp, const std::string &submodel_str); vec_t Plane_Dist(const vec3_t point, const dplane_t *plane); bool Light_PointInSolid(const bsp2_t *bsp, const vec3_t point ); -void Face_MakeInwardFacingEdgePlanes(const bsp2_t *bsp, const bsp2_dface_t *face, plane_t *out); +plane_t *Face_AllocInwardFacingEdgePlanes(const bsp2_t *bsp, const bsp2_dface_t *face); bool EdgePlanes_PointInside(const bsp2_dface_t *face, const plane_t *edgeplanes, const vec3_t point); #endif /* __COMMON_BSPUTILS_HH__ */ diff --git a/light/ltface.cc b/light/ltface.cc index 38285709..50955ff7 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -494,8 +494,7 @@ static void CalcPointNormal(const bsp2_t *bsp, const bsp2_dface_t *face, vec_t * // not in any triangle. among the edges this point is _behind_, // search for the one that the point is least past the endpoints of the edge { - plane_t *edgeplanes = (plane_t *)calloc(face->numedges, sizeof(plane_t)); - Face_MakeInwardFacingEdgePlanes(bsp, face, edgeplanes); + plane_t *edgeplanes = Face_AllocInwardFacingEdgePlanes(bsp, face); int bestplane = -1; vec_t bestdist = VECT_MAX; diff --git a/light/trace.cc b/light/trace.cc index 00ffa5fb..427e63f8 100644 --- a/light/trace.cc +++ b/light/trace.cc @@ -190,13 +190,10 @@ MakeFaceInfo(const bsp2_t *bsp, const bsp2_dface_t *face, faceinfo_t *info) { info->face = face; info->numedges = face->numedges; - info->edgeplanes = (plane_t *) calloc(face->numedges, sizeof(plane_t)); + info->edgeplanes = Face_AllocInwardFacingEdgePlanes(bsp, face); info->plane = Face_Plane(bsp, face); - // make edge planes - Face_MakeInwardFacingEdgePlanes(bsp, face, info->edgeplanes); - // make sphere that bounds the face vec3_t centroid = {0,0,0}; for (int i=0; inumedges; i++)