common: make VecStrf/VecStr threadsafe
This commit is contained in:
parent
e6411b2cee
commit
fa06716545
|
|
@ -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)
|
VecStr(const vec3_t vec)
|
||||||
{
|
{
|
||||||
static char buffers[8][20];
|
char buf[128];
|
||||||
static int current = 0;
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
buf = buffers[current++ & 7];
|
q_snprintf(buf, sizeof(buf), "%i %i %i",
|
||||||
q_snprintf(buf, sizeof(buffers[0]), "%i %i %i",
|
(int)vec[0], (int)vec[1], (int)vec[2]);
|
||||||
(int)vec[0], (int)vec[1], (int)vec[2]);
|
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * //mxd
|
std::string //mxd
|
||||||
VecStr(const qvec3f vec)
|
VecStr(const qvec3f vec)
|
||||||
{
|
{
|
||||||
vec3_t v;
|
vec3_t v;
|
||||||
|
|
@ -97,21 +94,18 @@ VecStr(const qvec3f vec)
|
||||||
return VecStr(v);
|
return VecStr(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
std::string
|
||||||
VecStrf(const vec3_t vec)
|
VecStrf(const vec3_t vec)
|
||||||
{
|
{
|
||||||
static char buffers[8][20];
|
char buf[128];
|
||||||
static int current = 0;
|
|
||||||
char *buf;
|
q_snprintf(buf, sizeof(buf), "%.2f %.2f %.2f",
|
||||||
|
|
||||||
buf = buffers[current++ & 7];
|
|
||||||
q_snprintf(buf, sizeof(buffers[0]), "%.2f %.2f %.2f",
|
|
||||||
vec[0], vec[1], vec[2]);
|
vec[0], vec[1], vec[2]);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * //mxd
|
std::string //mxd
|
||||||
VecStrf(const qvec3f vec)
|
VecStrf(const qvec3f vec)
|
||||||
{
|
{
|
||||||
vec3_t v;
|
vec3_t v;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <memory> // for unique_ptr
|
#include <memory> // for unique_ptr
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <common/qvec.hh>
|
#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);
|
bool SetPlanePts(const vec3_t planepts[3], vec3_t normal, vec_t *dist);
|
||||||
|
|
||||||
/* Shortcut for output of warnings/errors */
|
/* Shortcut for output of warnings/errors */
|
||||||
//FIXME: change from static buffers to returning std::string for thread safety
|
std::string VecStr(const vec3_t vec);
|
||||||
const char *VecStr(const vec3_t vec);
|
std::string VecStrf(const vec3_t vec);
|
||||||
const char *VecStrf(const vec3_t vec);
|
std::string VecStr(const qvec3f vec); //mxd
|
||||||
const char *VecStr(const qvec3f vec); //mxd
|
std::string VecStrf(const qvec3f vec); //mxd
|
||||||
const char *VecStrf(const qvec3f vec); //mxd
|
|
||||||
|
|
||||||
// Maps uniform random variables U and V in [0, 1] to uniformly distributed points on a sphere
|
// 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);
|
void UniformPointOnSphere(vec3_t dir, float u, float v);
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,7 @@ CheckEntityFields(const globalconfig_t &cfg, light_t *entity)
|
||||||
//mxd. Warn about unsupported _falloff / delay combos...
|
//mxd. Warn about unsupported _falloff / delay combos...
|
||||||
if(entity->falloff.floatValue() > 0.0f && entity->getFormula() != LF_LINEAR) {
|
if(entity->falloff.floatValue() > 0.0f && entity->getFormula() != LF_LINEAR) {
|
||||||
logprint("WARNING: _falloff is currently only supported on linear (delay 0) lights\n"
|
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);
|
entity->falloff.setFloatValue(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,7 +352,7 @@ CheckEntityFields(const globalconfig_t &cfg, light_t *entity)
|
||||||
" %s at (%s)\n"
|
" %s at (%s)\n"
|
||||||
" (further formula warnings will be supressed)\n",
|
" (further formula warnings will be supressed)\n",
|
||||||
entity->getFormula(), entity->classname(),
|
entity->getFormula(), entity->classname(),
|
||||||
VecStr(*entity->origin.vec3Value()));
|
VecStr(*entity->origin.vec3Value()).c_str());
|
||||||
}
|
}
|
||||||
entity->formula.setFloatValue(LF_LINEAR);
|
entity->formula.setFloatValue(LF_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ faceextents_t::faceextents_t(const bsp2_dface_t *face, const mbsp_t *bsp, float
|
||||||
" surface normal (%s)\n",
|
" surface normal (%s)\n",
|
||||||
Face_GetNum(bsp, face), i ? "t" : "s", m_texsize[i], m_lightmapscale,
|
Face_GetNum(bsp, face), i ? "t" : "s", m_texsize[i], m_lightmapscale,
|
||||||
texname, qv::to_string(point).c_str(),
|
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"
|
" texture %s at (%s)\n"
|
||||||
" surface normal (%s)\n",
|
" surface normal (%s)\n",
|
||||||
(int)(face - bsp->dfaces), i ? "t" : "s", surf->texsize[i], surf->lightmapscale,
|
(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) {
|
if (sorted.size() == MAXLIGHTMAPS) {
|
||||||
logprint("WARNING: Too many light styles on a face\n"
|
logprint("WARNING: Too many light styles on a face\n"
|
||||||
" lightmap point near (%s)\n",
|
" lightmap point near (%s)\n",
|
||||||
VecStr(lightsurf->points[0]));
|
VecStr(lightsurf->points[0]).c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ MakeSurfaceLightsThread(void *arg)
|
||||||
if (info->flags & Q2_SURF_LIGHT) {
|
if (info->flags & Q2_SURF_LIGHT) {
|
||||||
vec3_t wc;
|
vec3_t wc;
|
||||||
WindingCenter(WindingFromFace(bsp, face), 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -195,4 +195,4 @@ MakeSurfaceLights(const globalconfig_t &cfg, const mbsp_t *bsp)
|
||||||
|
|
||||||
make_surface_lights_args_t args { bsp, &cfg };
|
make_surface_lights_args_t args { bsp, &cfg };
|
||||||
RunThreadsOn(0, bsp->numfaces, MakeSurfaceLightsThread, static_cast<void *>(&args));
|
RunThreadsOn(0, bsp->numfaces, MakeSurfaceLightsThread, static_cast<void *>(&args));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue