Skip to content

Commit 309e158

Browse files
numberZeronerzhul
authored andcommittedDec 22, 2018
mapnode: add const/noexcept (#8009)
1 parent 0990ddb commit 309e158

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed
 

‎src/mapnode.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void MapNode::getColor(const ContentFeatures &f, video::SColor *color) const
6565
*color = f.color;
6666
}
6767

68-
void MapNode::setLight(enum LightBank bank, u8 a_light, const ContentFeatures &f)
68+
void MapNode::setLight(LightBank bank, u8 a_light, const ContentFeatures &f) noexcept
6969
{
7070
// If node doesn't contain light data, ignore this
7171
if(f.param_type != CPT_LIGHT)
@@ -84,8 +84,7 @@ void MapNode::setLight(enum LightBank bank, u8 a_light, const ContentFeatures &f
8484
assert("Invalid light bank" == NULL);
8585
}
8686

87-
void MapNode::setLight(enum LightBank bank, u8 a_light,
88-
const NodeDefManager *nodemgr)
87+
void MapNode::setLight(LightBank bank, u8 a_light, const NodeDefManager *nodemgr)
8988
{
9089
setLight(bank, a_light, nodemgr->get(*this));
9190
}
@@ -106,7 +105,7 @@ bool MapNode::isLightDayNightEq(const NodeDefManager *nodemgr) const
106105
return isEqual;
107106
}
108107

109-
u8 MapNode::getLight(enum LightBank bank, const NodeDefManager *nodemgr) const
108+
u8 MapNode::getLight(LightBank bank, const NodeDefManager *nodemgr) const
110109
{
111110
// Select the brightest of [light source, propagated light]
112111
const ContentFeatures &f = nodemgr->get(*this);
@@ -120,14 +119,14 @@ u8 MapNode::getLight(enum LightBank bank, const NodeDefManager *nodemgr) const
120119
return MYMAX(f.light_source, light);
121120
}
122121

123-
u8 MapNode::getLightRaw(enum LightBank bank, const ContentFeatures &f) const
122+
u8 MapNode::getLightRaw(LightBank bank, const ContentFeatures &f) const noexcept
124123
{
125124
if(f.param_type == CPT_LIGHT)
126125
return bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f;
127126
return 0;
128127
}
129128

130-
u8 MapNode::getLightNoChecks(enum LightBank bank, const ContentFeatures *f) const
129+
u8 MapNode::getLightNoChecks(LightBank bank, const ContentFeatures *f) const noexcept
131130
{
132131
return MYMAX(f->light_source,
133132
bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f);
@@ -530,7 +529,7 @@ static inline void getNeighborConnectingFace(
530529
*neighbors |= bitmask;
531530
}
532531

533-
u8 MapNode::getNeighbors(v3s16 p, Map *map)
532+
u8 MapNode::getNeighbors(v3s16 p, Map *map) const
534533
{
535534
const NodeDefManager *nodedef = map->getNodeDefManager();
536535
u8 neighbors = 0;
@@ -567,14 +566,14 @@ u8 MapNode::getNeighbors(v3s16 p, Map *map)
567566
}
568567

569568
void MapNode::getNodeBoxes(const NodeDefManager *nodemgr,
570-
std::vector<aabb3f> *boxes, u8 neighbors)
569+
std::vector<aabb3f> *boxes, u8 neighbors) const
571570
{
572571
const ContentFeatures &f = nodemgr->get(*this);
573572
transformNodeBox(*this, f.node_box, nodemgr, boxes, neighbors);
574573
}
575574

576575
void MapNode::getCollisionBoxes(const NodeDefManager *nodemgr,
577-
std::vector<aabb3f> *boxes, u8 neighbors)
576+
std::vector<aabb3f> *boxes, u8 neighbors) const
578577
{
579578
const ContentFeatures &f = nodemgr->get(*this);
580579
if (f.collision_box.fixed.empty())
@@ -584,7 +583,7 @@ void MapNode::getCollisionBoxes(const NodeDefManager *nodemgr,
584583
}
585584

586585
void MapNode::getSelectionBoxes(const NodeDefManager *nodemgr,
587-
std::vector<aabb3f> *boxes, u8 neighbors)
586+
std::vector<aabb3f> *boxes, u8 neighbors) const
588587
{
589588
const ContentFeatures &f = nodemgr->get(*this);
590589
transformNodeBox(*this, f.selection_box, nodemgr, boxes, neighbors);
@@ -676,7 +675,7 @@ u32 MapNode::serializedLength(u8 version)
676675

677676
return 4;
678677
}
679-
void MapNode::serialize(u8 *dest, u8 version)
678+
void MapNode::serialize(u8 *dest, u8 version) const
680679
{
681680
if(!ser_ver_supported(version))
682681
throw VersionMismatchException("ERROR: MapNode format not supported");

‎src/mapnode.h

+20-22
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct MapNode
139139

140140
MapNode() = default;
141141

142-
MapNode(content_t content, u8 a_param1=0, u8 a_param2=0)
142+
MapNode(content_t content, u8 a_param1=0, u8 a_param2=0) noexcept
143143
: param0(content),
144144
param1(a_param1),
145145
param2(a_param2)
@@ -150,35 +150,35 @@ struct MapNode
150150
MapNode(const NodeDefManager *ndef, const std::string &name,
151151
u8 a_param1=0, u8 a_param2=0);
152152

153-
bool operator==(const MapNode &other)
153+
bool operator==(const MapNode &other) const noexcept
154154
{
155155
return (param0 == other.param0
156156
&& param1 == other.param1
157157
&& param2 == other.param2);
158158
}
159159

160160
// To be used everywhere
161-
content_t getContent() const
161+
content_t getContent() const noexcept
162162
{
163163
return param0;
164164
}
165-
void setContent(content_t c)
165+
void setContent(content_t c) noexcept
166166
{
167167
param0 = c;
168168
}
169-
u8 getParam1() const
169+
u8 getParam1() const noexcept
170170
{
171171
return param1;
172172
}
173-
void setParam1(u8 p)
173+
void setParam1(u8 p) noexcept
174174
{
175175
param1 = p;
176176
}
177-
u8 getParam2() const
177+
u8 getParam2() const noexcept
178178
{
179179
return param2;
180180
}
181-
void setParam2(u8 p)
181+
void setParam2(u8 p) noexcept
182182
{
183183
param2 = p;
184184
}
@@ -191,10 +191,9 @@ struct MapNode
191191
*/
192192
void getColor(const ContentFeatures &f, video::SColor *color) const;
193193

194-
void setLight(enum LightBank bank, u8 a_light, const ContentFeatures &f);
194+
void setLight(LightBank bank, u8 a_light, const ContentFeatures &f) noexcept;
195195

196-
void setLight(enum LightBank bank, u8 a_light,
197-
const NodeDefManager *nodemgr);
196+
void setLight(LightBank bank, u8 a_light, const NodeDefManager *nodemgr);
198197

199198
/**
200199
* Check if the light value for night differs from the light value for day.
@@ -203,17 +202,17 @@ struct MapNode
203202
*/
204203
bool isLightDayNightEq(const NodeDefManager *nodemgr) const;
205204

206-
u8 getLight(enum LightBank bank, const NodeDefManager *nodemgr) const;
205+
u8 getLight(LightBank bank, const NodeDefManager *nodemgr) const;
207206

208207
/*!
209208
* Returns the node's light level from param1.
210209
* If the node emits light, it is ignored.
211210
* \param f the ContentFeatures of this node.
212211
*/
213-
u8 getLightRaw(enum LightBank bank, const ContentFeatures &f) const;
212+
u8 getLightRaw(LightBank bank, const ContentFeatures &f) const noexcept;
214213

215214
/**
216-
* This function differs from getLight(enum LightBank bank, NodeDefManager *nodemgr)
215+
* This function differs from getLight(LightBank bank, NodeDefManager *nodemgr)
217216
* in that the ContentFeatures of the node in question are not retrieved by
218217
* the function itself. Thus, if you have already called nodemgr->get() to
219218
* get the ContentFeatures you pass it to this function instead of the
@@ -227,7 +226,7 @@ struct MapNode
227226
* @pre f != NULL
228227
* @pre f->param_type == CPT_LIGHT
229228
*/
230-
u8 getLightNoChecks(LightBank bank, const ContentFeatures *f) const;
229+
u8 getLightNoChecks(LightBank bank, const ContentFeatures *f) const noexcept;
231230

232231
bool getLightBanks(u8 &lightday, u8 &lightnight,
233232
const NodeDefManager *nodemgr) const;
@@ -242,8 +241,7 @@ struct MapNode
242241
return blend_light(daylight_factor, lightday, lightnight);
243242
}
244243

245-
u8 getFaceDir(const NodeDefManager *nodemgr,
246-
bool allow_wallmounted = false) const;
244+
u8 getFaceDir(const NodeDefManager *nodemgr, bool allow_wallmounted = false) const;
247245
u8 getWallMounted(const NodeDefManager *nodemgr) const;
248246
v3s16 getWallMountedDir(const NodeDefManager *nodemgr) const;
249247

@@ -254,25 +252,25 @@ struct MapNode
254252
*
255253
* \param p coordinates of the node
256254
*/
257-
u8 getNeighbors(v3s16 p, Map *map);
255+
u8 getNeighbors(v3s16 p, Map *map) const;
258256

259257
/*
260258
Gets list of node boxes (used for rendering (NDT_NODEBOX))
261259
*/
262260
void getNodeBoxes(const NodeDefManager *nodemgr, std::vector<aabb3f> *boxes,
263-
u8 neighbors = 0);
261+
u8 neighbors = 0) const;
264262

265263
/*
266264
Gets list of selection boxes
267265
*/
268266
void getSelectionBoxes(const NodeDefManager *nodemg,
269-
std::vector<aabb3f> *boxes, u8 neighbors = 0);
267+
std::vector<aabb3f> *boxes, u8 neighbors = 0) const;
270268

271269
/*
272270
Gets list of collision boxes
273271
*/
274272
void getCollisionBoxes(const NodeDefManager *nodemgr,
275-
std::vector<aabb3f> *boxes, u8 neighbors = 0);
273+
std::vector<aabb3f> *boxes, u8 neighbors = 0) const;
276274

277275
/*
278276
Liquid helpers
@@ -287,7 +285,7 @@ struct MapNode
287285
*/
288286

289287
static u32 serializedLength(u8 version);
290-
void serialize(u8 *dest, u8 version);
288+
void serialize(u8 *dest, u8 version) const;
291289
void deSerialize(u8 *source, u8 version);
292290

293291
// Serializes or deserializes a list of nodes in bulk format (first the

0 commit comments

Comments
 (0)
Please sign in to comment.