Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/MeshObstacle.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ class MeshObstacle final : public Obstacle
void print(std::ostream& out, const std::string& indent) const override;
void printOBJ(std::ostream& out, const std::string& indent) const override;

struct RadarFaceCache
{
bool noRadar;
float posZ;
float sizeZ;
int phydrv;
int vertexCount;
float vx[4];
float vy[4];
};
std::vector<RadarFaceCache> radarCache;

private:
void makeFacePointers(const std::vector<int>& _vertices,
const std::vector<int>& _normals,
Expand Down
28 changes: 16 additions & 12 deletions src/bzflag/RadarRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1065,21 +1065,19 @@ void RadarRenderer::renderBoxPyrMesh()
for (i = 0; i < count; i++)
{
const MeshObstacle* mesh = (const MeshObstacle*) meshes[i];
const auto* cachePtr = mesh->radarCache.data();
int faces = mesh->getFaceCount();

for (int f = 0; f < faces; f++)
{
const MeshFace* face = mesh->getFace(f);
const auto& cache = cachePtr[f];
if (enhanced)
{
if (face->getPlane()[2] <= 0.0f)
continue;
const BzMaterial* bzmat = face->getMaterial();
if ((bzmat != NULL) && bzmat->getNoRadar())
if (cache.noRadar)
continue;
}
float z = face->getPosition()[2];
float bh = face->getSize()[2];
float z = cache.posZ;
float bh = cache.sizeZ;

if (BZDBCache::useMeshForRadar)
{
Expand All @@ -1089,18 +1087,24 @@ void RadarRenderer::renderBoxPyrMesh()

const float cs = colorScale(z, bh);
// draw death faces with a soupcon of red
const PhysicsDriver* phydrv = PHYDRVMGR.getDriver(face->getPhysicsDriver());
const PhysicsDriver* phydrv = PHYDRVMGR.getDriver(cache.phydrv);
if ((phydrv != NULL) && phydrv->getIsDeath())
glColor4f(0.75f * cs, 0.25f * cs, 0.25f * cs, transScale(z, bh));
else
glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(z, bh));
// draw the face as a triangle fan
int vertexCount = face->getVertexCount();
int vertexCount = cache.vertexCount;
glBegin(GL_TRIANGLE_FAN);
for (int v = 0; v < vertexCount; v++)
for (int v = 0; v < std::min(vertexCount, 4); v++)
glVertex2f(cache.vx[v], cache.vy[v]);
if (vertexCount > 4)
{
const float* pos = face->getVertex(v);
glVertex2f(pos[0], pos[1]);
const MeshFace* face = mesh->getFace(f);
for (int v = 4; v < vertexCount; v++)
{
const float* pos = face->getVertex(v);
glVertex2f(pos[0], pos[1]);
}
}
glEnd();
}
Expand Down
34 changes: 33 additions & 1 deletion src/obstacle/MeshObstacle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,42 @@ void MeshObstacle::finalize()
for (f = 0; f < faceCount; f++)
faces[f]->edges = NULL;

// Clear and prepare the cache
radarCache.clear();
radarCache.reserve(faceCount);

// set the extents
for (f = 0; f < faceCount; f++)
{
const Extents& exts = faces[f]->getExtents();
const auto& face = *faces[f];
const Extents& exts = face.getExtents();

RadarFaceCache cache;

if (face.getPlane()[2] <= 0.0f)
cache.noRadar = true;

else
{
const BzMaterial* bzmat = face.getMaterial();
if ((bzmat != NULL) && bzmat->getNoRadar())
cache.noRadar = true;
else
cache.noRadar = false;
}
cache.posZ = face.getPosition()[2];
cache.sizeZ = face.getSize()[2];
cache.phydrv = face.getPhysicsDriver();
cache.vertexCount = face.getVertexCount();
for (int v = 0; v < std::min(cache.vertexCount, 4); ++v)
{
const float* vpos = face.getVertex(v);
cache.vx[v] = vpos[0];
cache.vy[v] = vpos[1];
}

radarCache.push_back(cache);

extents.expandToBox(exts);
}

Expand Down
Loading