Skip to content

Commit

Permalink
Cleanup: POD correctness; default initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 4, 2018
1 parent 4df1874 commit 5b4d052
Show file tree
Hide file tree
Showing 37 changed files with 160 additions and 140 deletions.
8 changes: 4 additions & 4 deletions doomsday/apps/client/include/clientplayer.h
Expand Up @@ -50,11 +50,11 @@ typedef struct clplayerstate_s {
struct DemoTimer
{
bool first;
de::dint begintime;
int begintime;
bool canwrite; ///< @c false until Handshake packet.
de::dint cameratimer;
de::dint pausetime;
de::dfloat fov;
int cameratimer;
int pausetime;
float fov;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/render/projectedtexturedata.h
Expand Up @@ -29,7 +29,7 @@
*/
struct ProjectedTextureData
{
DGLuint texture;
DGLuint texture = 0;
de::Vector2f topLeft;
de::Vector2f bottomRight;
de::Vector4f color;
Expand Down
16 changes: 8 additions & 8 deletions doomsday/apps/client/include/render/vectorlightdata.h
Expand Up @@ -28,14 +28,14 @@
*/
struct VectorLightData
{
de::dfloat approxDist; ///< Only an approximation.
de::Vector3f direction; ///< Normalized vector from light origin to illumination point.
de::Vector3f color; ///< How intense the light is (0..1, RGB).
de::dfloat offset;
de::dfloat lightSide;
de::dfloat darkSide; ///< Factors for world light.
bool affectedByAmbient;
struct mobj_s const *sourceMobj; ///< Originating mobj, or nullptr.
float approxDist = 0.f; ///< Only an approximation.
de::Vector3f direction; ///< Normalized vector from light origin to illumination point.
de::Vector3f color; ///< How intense the light is (0..1, RGB).
float offset = 0.f;
float lightSide = 0.f;
float darkSide = 0.f; ///< Factors for world light.
bool affectedByAmbient = false;
struct mobj_s const *sourceMobj = nullptr; ///< Originating mobj, or nullptr.
};

#endif // CLIENT_RENDER_VECTORLIGHTDATA_H
5 changes: 3 additions & 2 deletions doomsday/apps/client/include/render/viewports.h
Expand Up @@ -85,10 +85,11 @@ struct viewdata_t
*/
de::Vector3f frontVec, upVec, sideVec; /* to the left */

float viewCos, viewSin;
float viewCos = 0.f;
float viewSin = 0.f;

de::Rectanglei window, windowTarget, windowOld;
float windowInter;
float windowInter = 0.f;
};

enum ViewPortLayer {
Expand Down
34 changes: 17 additions & 17 deletions doomsday/apps/client/include/render/vissprite.h
Expand Up @@ -51,20 +51,20 @@ enum visspritetype_t
struct VisEntityPose
{
de::Vector3d origin;
de::dfloat topZ; ///< Global top Z coordinate (origin Z is the bottom).
de::Vector3d srvo; ///< Short-range visual offset.
coord_t distance; ///< Distance from viewer.
de::dfloat yaw;
de::dfloat extraYawAngle;
de::dfloat yawAngleOffset; ///< @todo We do not need three sets of angles...
de::dfloat pitch;
de::dfloat extraPitchAngle;
de::dfloat pitchAngleOffset;
de::dfloat extraScale;
bool viewAligned;
bool mirrored; ///< If true the model will be mirrored about its Z axis (in model space).

VisEntityPose() { de::zap(*this); }
float topZ = 0.f; ///< Global top Z coordinate (origin Z is the bottom).
de::Vector3d srvo; ///< Short-range visual offset.
coord_t distance = 0.0; ///< Distance from viewer.
float yaw = 0.f;
float extraYawAngle = 0.f;
float yawAngleOffset = 0.f; ///< @todo We do not need three sets of angles...
float pitch = 0.f;
float extraPitchAngle = 0.f;
float pitchAngleOffset = 0.f;
float extraScale = 0.f;
bool viewAligned = false;
bool mirrored = false; ///< If true the model will be mirrored about its Z axis (in model space).

VisEntityPose() = default;

VisEntityPose(de::Vector3d const &origin_, de::Vector3d const &visOffset,
bool viewAlign_ = false,
Expand Down Expand Up @@ -99,7 +99,7 @@ struct VisEntityLighting
de::Vector4f ambientColor;
de::duint vLightListIdx = 0;

VisEntityLighting() {}
VisEntityLighting() = default;

VisEntityLighting(de::Vector4f const &ambientColor, de::duint lightListIndex)
: ambientColor(ambientColor)
Expand All @@ -115,8 +115,8 @@ struct VisEntityLighting
*/
struct vissprite_t
{
vissprite_t *prev;
vissprite_t *next;
vissprite_t *prev = nullptr;
vissprite_t *next = nullptr;
visspritetype_t type;

VisEntityPose pose;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/audio/base/audiosystem.cpp
Expand Up @@ -1826,7 +1826,7 @@ dint AudioSystem::playMusic(Record const &definition, bool looped)
// Next, try non-MUS lumps.
canPlayMUS = false;

// Note: Intentionally falls through to MUSP_MUS.
// Note: Intentionally falls through to MUSP_MUS.

case MUSP_MUS:
if (d->playMusicLump(App_FileSystem().lumpNumForName(definition.gets("lumpName")),
Expand Down
1 change: 0 additions & 1 deletion doomsday/apps/client/src/clientplayer.cpp
Expand Up @@ -43,7 +43,6 @@ DENG2_PIMPL(ClientPlayer)
: Base(i)
, playerWeaponAnimator(i)
{
zap(viewport);
zap(clPlayerState);
zap(demoTimer);
}
Expand Down
101 changes: 67 additions & 34 deletions doomsday/apps/client/src/gl/dgl_draw.cpp
Expand Up @@ -50,24 +50,19 @@ struct DGLDrawState
{
struct Vertex
{
Vector3f vertex;
Vector4ub color { 255, 255, 255, 255 };
Vector2f texCoord[MAX_TEX_COORDS];
float fragOffset[2] { 0, 0 }; // Multiplied by uFragmentOffset
float batchIndex;

Vertex() {}

Vertex(const Vertex &other)
{
std::memcpy(this, &other, sizeof(Vertex));
}
float vertex[3];
uint8_t color[4]; // { 255, 255, 255, 255 };
struct { float s, t; } texCoord[MAX_TEX_COORDS];
float fragOffset[2]; // { 0, 0 }; // Multiplied by uFragmentOffset
float batchIndex;
};

Vertex &operator=(const Vertex &other)
{
std::memcpy(this, &other, sizeof(Vertex));
return *this;
}
static constexpr Vertex DEFAULT_VERTEX = {
{0.f, 0.f, 0.f},
{255, 255, 255, 255},
{{0.f, 0.f}, {0.f, 0.f}},
{0.f, 0.f},
0.f
};

// Indices for vertex attribute arrays.
Expand All @@ -87,7 +82,7 @@ struct DGLDrawState
duint batchMaxSize;
duint currentBatchIndex;
bool resetPrimitive = false;
Vertex currentVertex;
Vertex currentVertex = DEFAULT_VERTEX;
Vertex primVertices[4];
QVector<Vertex> vertices;

Expand Down Expand Up @@ -173,7 +168,7 @@ struct DGLDrawState

void commitLine(Vertex start, Vertex end)
{
const Vector2f lineDir = (end.vertex - start.vertex).normalize();
const Vector2f lineDir = (Vector2f(end.vertex) - Vector2f(start.vertex)).normalize();
const Vector2f lineNormal{-lineDir.y, lineDir.x};

const bool disjoint = !vertices.empty();
Expand Down Expand Up @@ -719,7 +714,7 @@ void DGL_Flush()

void DGL_CurrentColor(DGLubyte *rgba)
{
std::memcpy(rgba, dglDraw.currentVertex.color.constPtr(), 4);
std::memcpy(rgba, dglDraw.currentVertex.color, 4);
}

void DGL_CurrentColor(float *rgba)
Expand All @@ -733,63 +728,91 @@ DENG_EXTERN_C void DGL_Color3ub(DGLubyte r, DGLubyte g, DGLubyte b)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.color = Vector4ub(r, g, b, 255);
dglDraw.currentVertex.color[0] = r;
dglDraw.currentVertex.color[1] = g;
dglDraw.currentVertex.color[2] = b;
dglDraw.currentVertex.color[3] = 255;
}

#undef DGL_Color3ubv
DENG_EXTERN_C void DGL_Color3ubv(DGLubyte const *vec)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.color = Vector4ub(Vector3ub(vec), 255);
dglDraw.currentVertex.color[0] = vec[0];
dglDraw.currentVertex.color[1] = vec[1];
dglDraw.currentVertex.color[2] = vec[2];
dglDraw.currentVertex.color[3] = 255;
}

#undef DGL_Color4ub
DENG_EXTERN_C void DGL_Color4ub(DGLubyte r, DGLubyte g, DGLubyte b, DGLubyte a)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.color = Vector4ub(r, g, b, a);
dglDraw.currentVertex.color[0] = r;
dglDraw.currentVertex.color[1] = g;
dglDraw.currentVertex.color[2] = b;
dglDraw.currentVertex.color[3] = a;
}

#undef DGL_Color4ubv
DENG_EXTERN_C void DGL_Color4ubv(DGLubyte const *vec)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.color = Vector4ub(vec);
dglDraw.currentVertex.color[0] = vec[0];
dglDraw.currentVertex.color[1] = vec[1];
dglDraw.currentVertex.color[2] = vec[2];
dglDraw.currentVertex.color[3] = vec[3];
}

#undef DGL_Color3f
DENG_EXTERN_C void DGL_Color3f(float r, float g, float b)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.color = DGLDrawState::colorFromFloat(Vector4f(r, g, b, 1.f));
const auto color = DGLDrawState::colorFromFloat({r, g, b, 1.f});
dglDraw.currentVertex.color[0] = color.x;
dglDraw.currentVertex.color[1] = color.y;
dglDraw.currentVertex.color[2] = color.z;
dglDraw.currentVertex.color[3] = color.w;
}

#undef DGL_Color3fv
DENG_EXTERN_C void DGL_Color3fv(float const *vec)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.color = DGLDrawState::colorFromFloat(Vector4f(Vector3f(vec), 1.f));
const auto color = DGLDrawState::colorFromFloat({Vector3f(vec), 1.f});
dglDraw.currentVertex.color[0] = color.x;
dglDraw.currentVertex.color[1] = color.y;
dglDraw.currentVertex.color[2] = color.z;
dglDraw.currentVertex.color[3] = color.w;
}

#undef DGL_Color4f
DENG_EXTERN_C void DGL_Color4f(float r, float g, float b, float a)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.color = DGLDrawState::colorFromFloat(Vector4f(r, g, b, a));
const auto color = DGLDrawState::colorFromFloat({r, g, b, a});
dglDraw.currentVertex.color[0] = color.x;
dglDraw.currentVertex.color[1] = color.y;
dglDraw.currentVertex.color[2] = color.z;
dglDraw.currentVertex.color[3] = color.w;
}

#undef DGL_Color4fv
DENG_EXTERN_C void DGL_Color4fv(float const *vec)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.color = DGLDrawState::colorFromFloat(Vector4f(vec));
const auto color = DGLDrawState::colorFromFloat(vec);
dglDraw.currentVertex.color[0] = color.x;
dglDraw.currentVertex.color[1] = color.y;
dglDraw.currentVertex.color[2] = color.z;
dglDraw.currentVertex.color[3] = color.w;
}

#undef DGL_TexCoord2f
Expand All @@ -800,7 +823,8 @@ DENG_EXTERN_C void DGL_TexCoord2f(byte target, float s, float t)

if (target < MAX_TEX_COORDS)
{
dglDraw.currentVertex.texCoord[target] = Vector2f(s, t);
dglDraw.currentVertex.texCoord[target].s = s;
dglDraw.currentVertex.texCoord[target].t = t;
}
}

Expand All @@ -812,7 +836,8 @@ DENG_EXTERN_C void DGL_TexCoord2fv(byte target, float const *vec)

if (target < MAX_TEX_COORDS)
{
dglDraw.currentVertex.texCoord[target] = Vector2f(vec);
dglDraw.currentVertex.texCoord[target].s = vec[0];
dglDraw.currentVertex.texCoord[target].t = vec[1];
}
}

Expand All @@ -821,7 +846,9 @@ DENG_EXTERN_C void DGL_Vertex2f(float x, float y)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.vertex = Vector3f(x, y, 0.f);
dglDraw.currentVertex.vertex[0] = x;
dglDraw.currentVertex.vertex[1] = y;
dglDraw.currentVertex.vertex[2] = 0.f;
dglDraw.commitVertex();
}

Expand All @@ -832,7 +859,9 @@ DENG_EXTERN_C void DGL_Vertex2fv(const float* vec)

if (vec)
{
dglDraw.currentVertex.vertex = Vector3f(vec[0], vec[1], 0.f);
dglDraw.currentVertex.vertex[0] = vec[0];
dglDraw.currentVertex.vertex[1] = vec[1];
dglDraw.currentVertex.vertex[2] = 0.f;
}
dglDraw.commitVertex();
}
Expand All @@ -842,7 +871,9 @@ DENG_EXTERN_C void DGL_Vertex3f(float x, float y, float z)
{
DENG2_ASSERT_IN_RENDER_THREAD();

dglDraw.currentVertex.vertex = Vector3f(x, y, z);
dglDraw.currentVertex.vertex[0] = x;
dglDraw.currentVertex.vertex[1] = y;
dglDraw.currentVertex.vertex[2] = z;

dglDraw.commitVertex();
}
Expand All @@ -854,7 +885,9 @@ DENG_EXTERN_C void DGL_Vertex3fv(const float* vec)

if (vec)
{
dglDraw.currentVertex.vertex = Vector3f(vec);
dglDraw.currentVertex.vertex[0] = vec[0];
dglDraw.currentVertex.vertex[1] = vec[1];
dglDraw.currentVertex.vertex[2] = vec[2];
}
dglDraw.commitVertex();
}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/client/src/render/blockmapvisual.cpp
Expand Up @@ -247,10 +247,10 @@ static void drawCellInfo(Vector2d const &origin_, char const *info)
FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET);
FR_SetShadowStrength(UI_SHADOW_STRENGTH);

Size2Raw size(16 + FR_TextWidth(info),
16 + FR_SingleLineHeight(info));
Size2Raw size = {{{16 + FR_TextWidth(info),
16 + FR_SingleLineHeight(info)}}};

Point2Raw origin(origin_.x, origin_.y);
Point2Raw origin = {{{int(origin_.x), int(origin_.y)}}};
origin.x -= size.width / 2;
//UI_GradientEx(&origin, &size, 6, UI_Color(UIC_BG_MEDIUM), UI_Color(UIC_BG_LIGHT), .5f, .5f);
//UI_DrawRectEx(&origin, &size, 6, false, UI_Color(UIC_BRD_HI), NULL, .5f, -1);
Expand All @@ -267,7 +267,7 @@ static void drawBlockmapInfo(Vector2d const &origin_, Blockmap const &blockmap)
{
DGL_Enable(DGL_TEXTURE_2D);

Point2Raw origin(origin_.x, origin_.y);
Point2Raw origin = {{{int(origin_.x), int(origin_.y)}}};

FR_SetFont(fontFixed);
FR_LoadDefaultAttrib();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/r_main.cpp
Expand Up @@ -308,7 +308,7 @@ void Rend_Draw3DPlayerSprites()

if (spr.type == VPSPR_MODEL)
{
vissprite_t vs; de::zap(vs);
vissprite_t vs;
setupModelParamsForVisPSprite(vs, spr);
Rend_DrawModel(vs);
}
Expand Down

0 comments on commit 5b4d052

Please sign in to comment.