Skip to content

Commit 89124a7

Browse files
committed
disp: Add missed constexpr and static
1 parent 2d206ac commit 89124a7

File tree

4 files changed

+28
-38
lines changed

4 files changed

+28
-38
lines changed

public/disp_common.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ class CNodeVert
1616
{
1717
public:
1818
CNodeVert() = default;
19-
CNodeVert( int ix, int iy ) : x{ix}, y{iy} {}
19+
constexpr CNodeVert( int ix, int iy ) : x{ix}, y{iy} {}
2020

2121
inline int& operator[]( int i ) {return ((int*)this)[i];}
2222
inline int const& operator[]( int i ) const {return ((int*)this)[i];}
2323

2424
int x, y;
2525
};
2626

27-
static CNodeVert const g_NodeChildLookup[4][2] =
27+
static constexpr CNodeVert g_NodeChildLookup[4][2] =
2828
{
2929
{CNodeVert(0,0), CNodeVert(1,1)},
3030
{CNodeVert(1,0), CNodeVert(2,1)},
3131
{CNodeVert(0,1), CNodeVert(1,2)},
3232
{CNodeVert(1,1), CNodeVert(2,2)}
3333
};
3434

35-
static CNodeVert const g_NodeTriWinding[9] =
35+
static constexpr CNodeVert g_NodeTriWinding[9] =
3636
{
3737
CNodeVert(0, 1),
3838
CNodeVert(0, 0),
@@ -46,7 +46,7 @@ static CNodeVert const g_NodeTriWinding[9] =
4646
};
4747

4848
// Indexed by CORNER_. These store NEIGHBOREDGE_ defines and tell which edges butt up against the corner.
49-
static int g_CornerEdges[4][2] =
49+
static constexpr int g_CornerEdges[4][2] =
5050
{
5151
{ NEIGHBOREDGE_BOTTOM, NEIGHBOREDGE_LEFT }, // CORNER_LOWER_LEFT
5252
{ NEIGHBOREDGE_TOP, NEIGHBOREDGE_LEFT }, // CORNER_UPPER_LEFT

public/disp_powerinfo.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
// ------------------------------------------------------------------------ //
1818

1919
// These point at the vertices connecting to each of the [north,south,east,west] vertices.
20-
class CVertCorners
20+
// dimhotepus: class -> struct.
21+
struct CVertCorners
2122
{
22-
public:
2323
short m_Corner1[2];
2424
short m_Corner2[2];
2525
};
@@ -30,9 +30,9 @@ class CVertCorners
3030
// ------------------------------------------------------------------------ //
3131

3232
// This points at vertices to the side of a node (north, south, east, west).
33-
static short g_SideVertMul[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };
33+
static constexpr short g_SideVertMul[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };
3434

35-
static CVertCorners g_SideVertCorners[4] =
35+
static constexpr CVertCorners g_SideVertCorners[4] =
3636
{
3737
{ {1,-1}, {1,1} },
3838
{ {1,1}, {-1,1} },
@@ -45,7 +45,7 @@ static CVertCorners g_SideVertCorners[4] =
4545
// 1 = upper-left
4646
// 2 = lower-left
4747
// 3 = lower-right
48-
static CVertIndex g_ChildNodeIndexMul[4] =
48+
static constexpr CVertIndex g_ChildNodeIndexMul[4] =
4949
{
5050
CVertIndex(1,1),
5151
CVertIndex(-1,1),
@@ -54,7 +54,7 @@ static CVertIndex g_ChildNodeIndexMul[4] =
5454
};
5555

5656
// These are multipliers on vertMul (not nodeMul).
57-
static CVertIndex g_ChildNodeDependencies[4][2] =
57+
static constexpr CVertIndex g_ChildNodeDependencies[4][2] =
5858
{
5959
{ CVertIndex(1,0), CVertIndex(0,1) },
6060
{ CVertIndex(0,1), CVertIndex(-1,0) },
@@ -63,7 +63,7 @@ static CVertIndex g_ChildNodeDependencies[4][2] =
6363
};
6464

6565
// 2x2 rotation matrices for each orientation.
66-
static int g_OrientationRotations[4][2][2] =
66+
static constexpr int g_OrientationRotations[4][2][2] =
6767
{
6868
{{1, 0}, // CCW_0
6969
{0, 1}},
@@ -211,14 +211,6 @@ static void AddDependency(
211211
// --------------------------------------------------------------------------------- //
212212
// CTesselateWinding stuff.
213213
// --------------------------------------------------------------------------------- //
214-
215-
CTesselateVert::CTesselateVert( CVertIndex const &index, int iNode )
216-
: m_Index( index )
217-
{
218-
m_iNode = iNode;
219-
}
220-
221-
222214
CVertInfo::CVertInfo()
223215
{
224216
for( auto& d : m_Dependencies )
@@ -237,8 +229,8 @@ CVertInfo::CVertInfo()
237229
m_iNodeLevel = -1;
238230
}
239231

240-
241-
CTesselateVert g_TesselateVerts[] =
232+
// dimhotepus: constexpr.
233+
constexpr CTesselateVert g_TesselateVerts[] =
242234
{
243235
CTesselateVert( CVertIndex(1,-1), CHILDNODE_LOWER_RIGHT),
244236
CTesselateVert( CVertIndex(0,-1), -1),
@@ -254,7 +246,7 @@ CTesselateVert g_TesselateVerts[] =
254246
CTesselateWinding g_TWinding =
255247
{
256248
g_TesselateVerts,
257-
sizeof( g_TesselateVerts ) / sizeof( g_TesselateVerts[0] )
249+
std::size( g_TesselateVerts )
258250
};
259251

260252

@@ -289,10 +281,11 @@ DECLARE_TABLES( 17 );
289281

290282

291283
// Index by m_Power.
292-
CPowerInfo *g_PowerInfos[NUM_POWERINFOS] =
284+
// dimhotepus: static.
285+
static CPowerInfo *g_PowerInfos[NUM_POWERINFOS] =
293286
{
294-
NULL,
295-
NULL,
287+
nullptr,
288+
nullptr,
296289
POWERINFO_ENTRY(5),
297290
POWERINFO_ENTRY(9),
298291
POWERINFO_ENTRY(17)

public/disp_powerinfo.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,22 @@ struct DispNodeInfo_t
4545
class CTesselateVert
4646
{
4747
public:
48-
CTesselateVert( CVertIndex const &index, int iNode );
48+
// dimhotepus: constexpr. int -> short
49+
constexpr inline CTesselateVert(CVertIndex index, short iNode)
50+
: m_Index{ index }, m_iNode{ iNode }
51+
{
52+
}
4953

50-
CVertIndex m_Index;
54+
CVertIndex m_Index;
5155
short m_iNode; // Which node this vert is a part of (-1 on left, right, up, and down).
5256
};
5357

5458

5559
class CTesselateWinding
5660
{
5761
public:
58-
CTesselateVert *m_Verts;
62+
// dimhotepus: Add const.
63+
const CTesselateVert *m_Verts;
5964
short m_nVerts; // (includes the last vert)
6065
};
6166

public/disp_vertindex.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
class CVertIndex
2323
{
2424
public:
25-
CVertIndex() = default;
26-
CVertIndex( short ix, short iy );
25+
CVertIndex() = default;
26+
constexpr CVertIndex( short ix, short iy ) : x{ix}, y{iy} {}
2727

2828
void Init( short ix, short iy );
2929

@@ -67,14 +67,6 @@ inline CVertIndex BuildOffsetVertIndex(
6767
// ------------------------------------------------------------------ //
6868
// CVertIndex inlines.
6969
// ------------------------------------------------------------------ //
70-
71-
inline CVertIndex::CVertIndex( short ix, short iy )
72-
{
73-
x = ix;
74-
y = iy;
75-
}
76-
77-
7870
inline void CVertIndex::Init( short ix, short iy )
7971
{
8072
x = ix;

0 commit comments

Comments
 (0)