Skip to content

Commit

Permalink
Cleanup|World: world::Line accessors, const correctness, pimpl confor…
Browse files Browse the repository at this point in the history
…mance
  • Loading branch information
danij-deng committed Jul 13, 2016
1 parent e48f4b3 commit 5155fc0
Show file tree
Hide file tree
Showing 20 changed files with 622 additions and 625 deletions.
424 changes: 167 additions & 257 deletions doomsday/apps/client/include/world/line.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doomsday/apps/client/include/world/vertex.h
Expand Up @@ -68,12 +68,12 @@ class Vertex : public world::MapElement, public de::MeshElement
/**
* Returns the X axis origin (i.e., position) of the vertex in the map coordinate space.
*/
inline coord_t x() const { return origin().x; }
inline de::ddouble x() const { return origin().x; }

/**
* Returns the Y axis origin (i.e., position) of the vertex in the map coordinate space.
*/
inline coord_t y() const { return origin().y; }
inline de::ddouble y() const { return origin().y; }

/**
* Change the origin (i.e., position) of the vertex in the map coordinate
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/render/blockmapvisual.cpp
Expand Up @@ -59,8 +59,8 @@ static void drawMobj(mobj_t const &mobj)

static void drawLine(Line const &line)
{
glVertex2f(line.fromOrigin().x, line.fromOrigin().y);
glVertex2f( line.toOrigin().x, line.toOrigin().y);
glVertex2f(line.from().x(), line.from().y());
glVertex2f(line.to ().x(), line.to ().y());
}

static void drawSubspace(ConvexSubspace const &subspace)
Expand Down
14 changes: 7 additions & 7 deletions doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -324,7 +324,7 @@ static void reportWallDrawn(Line &line)
if(line.isMappedByPlayer(playerNum)) return;

// Mark as drawn.
line.markMappedByPlayer(playerNum);
line.setMappedByPlayer(playerNum);

// Send a status report.
if(gx.HandleMapObjectStatusReport)
Expand Down Expand Up @@ -2023,17 +2023,17 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,

static Lumobj::LightmapSemantic lightmapForSurface(Surface const &surface)
{
if(surface.parent().type() == DMU_SIDE) return Lumobj::Side;
if (surface.parent().type() == DMU_SIDE) return Lumobj::Side;
// Must be a plane then.
auto const &plane = surface.parent().as<Plane>();
return plane.isSectorFloor()? Lumobj::Down : Lumobj::Up;
return plane.isSectorFloor() ? Lumobj::Down : Lumobj::Up;
}

static DGLuint prepareLightmap(ClientTexture *tex = nullptr)
{
if(tex)
if (tex)
{
if(TextureVariant *variant = tex->prepareVariant(Rend_MapSurfaceLightmapTextureSpec()))
if (TextureVariant *variant = tex->prepareVariant(Rend_MapSurfaceLightmapTextureSpec()))
{
return variant->glName();
}
Expand Down Expand Up @@ -2480,7 +2480,7 @@ static bool applyNearFadeOpacity(WallEdge const &leftEdge, WallEdge const &right
mobj_t const *mo = viewPlayer->publicData().mo;
Line const &line = leftEdge.lineSide().line();

coord_t linePoint[2] = { line.fromOrigin().x, line.fromOrigin().y };
coord_t linePoint[2] = { line.from().x(), line.from().y() };
coord_t lineDirection[2] = { line.direction().x, line.direction().y };
vec2d_t result;
ddouble pos = V2d_ProjectOnLine(result, mo->origin, linePoint, lineDirection);
Expand Down Expand Up @@ -5324,7 +5324,7 @@ static void drawFakeRadioShadowPoints(Map &map)
LineOwner const *own = base;
do
{
coord_t const z = own->line().frontSector().floor().heightSmoothed();
coord_t const z = own->line().front().sector().floor().heightSmoothed();

drawPoint(Vector3d(vtx.origin() + own->extendedShadowOffset(), z), yellow);
drawPoint(Vector3d(vtx.origin() + own->innerShadowOffset (), z), red);
Expand Down
88 changes: 45 additions & 43 deletions doomsday/apps/client/src/render/rend_particle.cpp
Expand Up @@ -498,20 +498,20 @@ static void drawParticles(dint rtype, bool withBlend)

// Should we use a texture?
DGLuint tex = 0;
if(rtype == PTC_POINT ||
(rtype >= PTC_TEXTURE && rtype < PTC_TEXTURE + MAX_PTC_TEXTURES))
if (rtype == PTC_POINT
|| (rtype >= PTC_TEXTURE && rtype < PTC_TEXTURE + MAX_PTC_TEXTURES))
{
if(renderTextures)
if (renderTextures)
{
if(rtype == PTC_POINT || 0 == ptctexname[rtype - PTC_TEXTURE])
if (rtype == PTC_POINT || 0 == ptctexname[rtype - PTC_TEXTURE])
tex = pointTex;
else
tex = ptctexname[rtype - PTC_TEXTURE];
}
}

ushort primType = GL_QUADS;
if(rtype == PTC_MODEL)
if (rtype == PTC_MODEL)
{
//glDepthMask(GL_TRUE);
//glEnable(GL_DEPTH_TEST);
Expand All @@ -520,7 +520,7 @@ static void drawParticles(dint rtype, bool withBlend)
.setDepthTest(true)
.apply();
}
else if(tex != 0)
else if (tex != 0)
{
//glDepthMask(GL_FALSE);
//glDisable(GL_CULL_FACE);
Expand All @@ -543,43 +543,43 @@ static void drawParticles(dint rtype, bool withBlend)

// How many particles will be drawn?
size_t i = 0;
if(maxParticles)
if (maxParticles)
{
i = numParts - (unsigned) maxParticles;
}

blendmode_t mode = BM_NORMAL, newMode;
for(; i < numParts; ++i)
for (; i < numParts; ++i)
{
OrderedParticle const *slot = &order[i];
Generator const *gen = slot->generator;
ParticleInfo const *pinfo = &gen->particleInfo()[slot->particleId];
ParticleInfo const &pinfo = gen->particleInfo()[slot->particleId];

GeneratorParticleStage const *st = &gen->stages[pinfo->stage];
ded_ptcstage_t const *stDef = &gen->def->stages[pinfo->stage];
GeneratorParticleStage const *st = &gen->stages[pinfo.stage];
ded_ptcstage_t const *stDef = &gen->def->stages[pinfo.stage];

dshort stageType = st->type;
if(stageType >= PTC_TEXTURE && stageType < PTC_TEXTURE + MAX_PTC_TEXTURES &&
0 == ptctexname[stageType - PTC_TEXTURE])
if (stageType >= PTC_TEXTURE && stageType < PTC_TEXTURE + MAX_PTC_TEXTURES &&
0 == ptctexname[stageType - PTC_TEXTURE])
{
stageType = PTC_POINT;
}

// Only render one type of particles.
if((rtype == PTC_MODEL && stDef->model < 0) ||
(rtype != PTC_MODEL && stageType != rtype))
if ((rtype == PTC_MODEL && stDef->model < 0) ||
(rtype != PTC_MODEL && stageType != rtype))
{
continue;
}

if(rtype >= PTC_TEXTURE && rtype < PTC_TEXTURE + MAX_PTC_TEXTURES &&
0 == ptctexname[rtype - PTC_TEXTURE])
if (rtype >= PTC_TEXTURE && rtype < PTC_TEXTURE + MAX_PTC_TEXTURES &&
0 == ptctexname[rtype - PTC_TEXTURE])
continue;

if((gen->blendmode() != BM_ADD) == withBlend)
if ((gen->blendmode() != BM_ADD) == withBlend)
continue;

if(rtype != PTC_MODEL && !withBlend)
if (rtype != PTC_MODEL && !withBlend)
{
// We may need to change the blending mode.
newMode = gen->blendmode();
Expand All @@ -594,19 +594,19 @@ static void drawParticles(dint rtype, bool withBlend)

// Is there a next stage for this particle?
ded_ptcstage_t const *nextStDef;
if(pinfo->stage >= gen->def->stages.size() - 1 ||
!gen->stages[pinfo->stage + 1].type)
if (pinfo.stage >= gen->def->stages.size() - 1 ||
!gen->stages[pinfo.stage + 1].type)
{
// There is no "next stage". Use the current one.
nextStDef = &gen->def->stages[pinfo->stage];
nextStDef = &gen->def->stages[pinfo.stage];
}
else
{
nextStDef = &gen->def->stages[pinfo->stage + 1];
nextStDef = &gen->def->stages[pinfo.stage + 1];
}

// Where is intermark?
dfloat const inter = 1 - dfloat( pinfo->tics ) / stDef->tics;
dfloat const inter = 1 - dfloat( pinfo.tics ) / stDef->tics;

// Calculate size and color.
dfloat size = de::lerp( stDef->particleRadius(slot->particleId),
Expand All @@ -621,7 +621,7 @@ static void drawParticles(dint rtype, bool withBlend)
{
// This is a simplified version of sectorlight (no distance
// attenuation or range compression).
if(world::ConvexSubspace *subspace = pinfo->bspLeaf->subspacePtr())
if(world::ConvexSubspace *subspace = pinfo.bspLeaf->subspacePtr())
{
dfloat const intensity = subspace->cluster().lightSourceIntensity();
color *= Vector4f(intensity, intensity, intensity, 1);
Expand Down Expand Up @@ -654,14 +654,14 @@ static void drawParticles(dint rtype, bool withBlend)

glColor4f(color.x, color.y, color.z, color.w);

bool const nearWall = (pinfo->contact && !pinfo->mov[0] && !pinfo->mov[1]);
bool const nearWall = (pinfo.contact && !pinfo.mov[0] && !pinfo.mov[1]);

bool nearPlane = false;
if(world::ConvexSubspace *subspace = pinfo->bspLeaf->subspacePtr())
if(world::ConvexSubspace *subspace = pinfo.bspLeaf->subspacePtr())
{
world::SectorCluster &cluster = subspace->cluster();
if(FLT2FIX(cluster. visFloor().heightSmoothed()) + 2 * FRACUNIT >= pinfo->origin[2] ||
FLT2FIX(cluster.visCeiling().heightSmoothed()) - 2 * FRACUNIT <= pinfo->origin[2])
if(FLT2FIX(cluster. visFloor().heightSmoothed()) + 2 * FRACUNIT >= pinfo.origin[2] ||
FLT2FIX(cluster.visCeiling().heightSmoothed()) - 2 * FRACUNIT <= pinfo.origin[2])
{
nearPlane = true;
}
Expand All @@ -677,19 +677,19 @@ static void drawParticles(dint rtype, bool withBlend)
flatOnWall = true;
}

Vector3f center = gen->particleOrigin(*pinfo).xzy();
Vector3f center = gen->particleOrigin(pinfo).xzy();

if(!flatOnPlane && !flatOnWall)
{
Vector3f offset(frameTimePos, nearPlane? 0 : frameTimePos, frameTimePos);
center += offset * gen->particleMomentum(*pinfo).xzy();
Vector3f offset(frameTimePos, nearPlane ? 0 : frameTimePos, frameTimePos);
center += offset * gen->particleMomentum(pinfo).xzy();
}

// Model particles are rendered using the normal model rendering routine.
if(rtype == PTC_MODEL && stDef->model >= 0)
{
vissprite_t temp; de::zap(temp);
setupModelParamsForParticle(temp, pinfo, st, stDef, center, dist, size, inter, color.w);
setupModelParamsForParticle(temp, &pinfo, st, stDef, center, dist, size, inter, color.w);
Rend_DrawModel(temp);
continue;
}
Expand All @@ -715,18 +715,21 @@ static void drawParticles(dint rtype, bool withBlend)
// Flat against a wall, then?
else if(flatOnWall)
{
vec2d_t origin, projected;
DENG2_ASSERT(pinfo.contact);
Line const &contact = *pinfo.contact;

// There will be a slight approximation on the XY plane since
// the particles aren't that accurate when it comes to wall
// collisions.

// Calculate a new center point (project onto the wall).
V2d_Set(origin, FIX2FLT(pinfo->origin[0]), FIX2FLT(pinfo->origin[1]));
vec2d_t origin;
V2d_Set(origin, FIX2FLT(pinfo.origin[0]), FIX2FLT(pinfo.origin[1]));

coord_t linePoint[2] = { pinfo->contact->fromOrigin().x, pinfo->contact->fromOrigin().y };
coord_t lineDirection[2] = { pinfo->contact->direction().x, pinfo->contact->direction().y };
V2d_ProjectOnLine(projected, origin, linePoint, lineDirection);
vec2d_t projected;
V2d_ProjectOnLine(projected, origin,
contact.from().origin().data().baseAs<ddouble>(),
contact.direction().data().baseAs<ddouble>());

// Move away from the wall to avoid the worst Z-fighting.
ddouble const gap = -1; // 1 map unit.
Expand All @@ -738,8 +741,7 @@ static void drawParticles(dint rtype, bool withBlend)
projected[1] += diff[1] / dist * gap;
}

DENG2_ASSERT(pinfo->contact);
Vector2f unitVec = lineUnitVector(*pinfo->contact);
Vector2f unitVec = lineUnitVector(*pinfo.contact);

glTexCoord2f(0, 0);
glVertex3d(projected[0] - size * unitVec.x, center.y - size,
Expand Down Expand Up @@ -783,9 +785,9 @@ static void drawParticles(dint rtype, bool withBlend)
else // It's a line.
{
glVertex3f(center.x, center.y, center.z);
glVertex3f(center.x - FIX2FLT(pinfo->mov[0]),
center.y - FIX2FLT(pinfo->mov[2]),
center.z - FIX2FLT(pinfo->mov[1]));
glVertex3f(center.x - FIX2FLT(pinfo.mov[0]),
center.y - FIX2FLT(pinfo.mov[2]),
center.z - FIX2FLT(pinfo.mov[1]));
}
}

Expand Down

0 comments on commit 5155fc0

Please sign in to comment.