common: make VecStrf/VecStr threadsafe

This commit is contained in:
Eric Wasylishen 2018-07-24 00:18:43 -06:00
parent e6411b2cee
commit fa06716545
5 changed files with 23 additions and 29 deletions

View File

@ -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;

View File

@ -28,6 +28,7 @@
#include <array>
#include <utility>
#include <memory> // for unique_ptr
#include <string>
#include <common/qvec.hh>
@ -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);

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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<void *>(&args));
}
}