diff --git a/common/mathlib.cc b/common/mathlib.cc index d592c8d5..6f8860ea 100644 --- a/common/mathlib.cc +++ b/common/mathlib.cc @@ -73,23 +73,20 @@ SetPlanePts(const vec3_t planepts[3], vec3_t normal, vec_t *dist) } /* - * VecStr - handy shortcut for printf, not thread safe, obviously + * VecStr - handy shortcut for printf */ -const char * +std::string VecStr(const vec3_t vec) { - static char buffers[8][20]; - static int current = 0; - char *buf; + char buf[128]; - buf = buffers[current++ & 7]; - q_snprintf(buf, sizeof(buffers[0]), "%i %i %i", - (int)vec[0], (int)vec[1], (int)vec[2]); + q_snprintf(buf, sizeof(buf), "%i %i %i", + (int)vec[0], (int)vec[1], (int)vec[2]); return buf; } -const char * //mxd +std::string //mxd VecStr(const qvec3f vec) { vec3_t v; @@ -97,21 +94,18 @@ VecStr(const qvec3f vec) return VecStr(v); } -const char * +std::string VecStrf(const vec3_t vec) { - static char buffers[8][20]; - static int current = 0; - char *buf; - - buf = buffers[current++ & 7]; - q_snprintf(buf, sizeof(buffers[0]), "%.2f %.2f %.2f", + char buf[128]; + + q_snprintf(buf, sizeof(buf), "%.2f %.2f %.2f", vec[0], vec[1], vec[2]); return buf; } -const char * //mxd +std::string //mxd VecStrf(const qvec3f vec) { vec3_t v; diff --git a/include/common/mathlib.hh b/include/common/mathlib.hh index ca575ac8..769ecdac 100644 --- a/include/common/mathlib.hh +++ b/include/common/mathlib.hh @@ -28,6 +28,7 @@ #include #include #include // for unique_ptr +#include #include @@ -245,11 +246,10 @@ ProjectPointOntoPlane(const vec3_t normal, const vec_t dist, vec3_t point) bool SetPlanePts(const vec3_t planepts[3], vec3_t normal, vec_t *dist); /* Shortcut for output of warnings/errors */ -//FIXME: change from static buffers to returning std::string for thread safety -const char *VecStr(const vec3_t vec); -const char *VecStrf(const vec3_t vec); -const char *VecStr(const qvec3f vec); //mxd -const char *VecStrf(const qvec3f vec); //mxd +std::string VecStr(const vec3_t vec); +std::string VecStrf(const vec3_t vec); +std::string VecStr(const qvec3f vec); //mxd +std::string VecStrf(const qvec3f vec); //mxd // Maps uniform random variables U and V in [0, 1] to uniformly distributed points on a sphere void UniformPointOnSphere(vec3_t dir, float u, float v); diff --git a/light/entities.cc b/light/entities.cc index c211e8d3..3572d85e 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -340,7 +340,7 @@ CheckEntityFields(const globalconfig_t &cfg, light_t *entity) //mxd. Warn about unsupported _falloff / delay combos... if(entity->falloff.floatValue() > 0.0f && entity->getFormula() != LF_LINEAR) { logprint("WARNING: _falloff is currently only supported on linear (delay 0) lights\n" - " %s at (%s)\n", entity->classname(), VecStr(*entity->origin.vec3Value())); + " %s at (%s)\n", entity->classname(), VecStr(*entity->origin.vec3Value()).c_str()); entity->falloff.setFloatValue(0.0f); } @@ -352,7 +352,7 @@ CheckEntityFields(const globalconfig_t &cfg, light_t *entity) " %s at (%s)\n" " (further formula warnings will be supressed)\n", entity->getFormula(), entity->classname(), - VecStr(*entity->origin.vec3Value())); + VecStr(*entity->origin.vec3Value()).c_str()); } entity->formula.setFloatValue(LF_LINEAR); } diff --git a/light/ltface.cc b/light/ltface.cc index 23bdf8b6..982bffa7 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -118,7 +118,7 @@ faceextents_t::faceextents_t(const bsp2_dface_t *face, const mbsp_t *bsp, float " surface normal (%s)\n", Face_GetNum(bsp, face), i ? "t" : "s", m_texsize[i], m_lightmapscale, texname, qv::to_string(point).c_str(), - VecStrf(plane.normal)); + VecStrf(plane.normal).c_str()); } } } @@ -345,7 +345,7 @@ CalcFaceExtents(const bsp2_dface_t *face, " texture %s at (%s)\n" " surface normal (%s)\n", (int)(face - bsp->dfaces), i ? "t" : "s", surf->texsize[i], surf->lightmapscale, - texname, VecStr(worldpoint), VecStrf(plane->normal)); + texname, VecStr(worldpoint).c_str(), VecStrf(plane->normal).c_str()); } } } @@ -2985,7 +2985,7 @@ WriteLightmaps(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const if (sorted.size() == MAXLIGHTMAPS) { logprint("WARNING: Too many light styles on a face\n" " lightmap point near (%s)\n", - VecStr(lightsurf->points[0])); + VecStr(lightsurf->points[0]).c_str()); break; } diff --git a/light/surflight.cc b/light/surflight.cc index 3b5c598e..f222d199 100644 --- a/light/surflight.cc +++ b/light/surflight.cc @@ -83,7 +83,7 @@ MakeSurfaceLightsThread(void *arg) if (info->flags & Q2_SURF_LIGHT) { vec3_t wc; WindingCenter(WindingFromFace(bsp, face), wc); - logprint("WARNING: surface light '%s' at [%s] has 0 intensity.\n", Face_TextureName(bsp, face), VecStr(wc)); + logprint("WARNING: surface light '%s' at [%s] has 0 intensity.\n", Face_TextureName(bsp, face), VecStr(wc).c_str()); } continue; } @@ -195,4 +195,4 @@ MakeSurfaceLights(const globalconfig_t &cfg, const mbsp_t *bsp) make_surface_lights_args_t args { bsp, &cfg }; RunThreadsOn(0, bsp->numfaces, MakeSurfaceLightsThread, static_cast(&args)); -} \ No newline at end of file +}