Skip to content

Commit 7a9e2c3

Browse files
tamlin-mikeXottab-DUTY
authored andcommitted
A few 'constexpr' and 'noexcept' added to some obvious places.
1 parent 6e250b2 commit 7a9e2c3

File tree

8 files changed

+62
-60
lines changed

8 files changed

+62
-60
lines changed

src/xrCommon/math_funcs_inline.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#include "xrCommon/inlining_macros.h"
55
#include "xrCore/_bitwise.h" // iFloor
66

7-
inline float _abs(float x) { return fabsf(x); }
8-
inline float _sqrt(float x) { return sqrtf(x); }
9-
inline float _sin(float x) { return sinf(x); }
10-
inline float _cos(float x) { return cosf(x); }
11-
inline double _abs(double x) { return fabs(x); }
12-
inline double _sqrt(double x) { return sqrt(x); }
13-
inline double _sin(double x) { return sin(x); }
14-
inline double _cos(double x) { return cos(x); }
7+
inline float _abs(float x) noexcept { return fabsf(x); }
8+
inline float _sqrt(float x) noexcept { return sqrtf(x); }
9+
inline float _sin(float x) noexcept { return sinf(x); }
10+
inline float _cos(float x) noexcept { return cosf(x); }
11+
inline double _abs(double x) noexcept { return fabs(x); }
12+
inline double _sqrt(double x) noexcept { return sqrt(x); }
13+
inline double _sin(double x) noexcept { return sin(x); }
14+
inline double _cos(double x) noexcept { return cos(x); }
1515

1616
// comparisions
1717
inline bool fsimilar(float a, float b, float cmp = EPS) { return _abs(a-b)<cmp; }
@@ -21,32 +21,33 @@ inline bool fis_zero(float val, float cmp = EPS_S) noexcept { return _abs(val) <
2121
inline bool dis_zero(double val, double cmp = EPS_S) noexcept { return _abs(val) < cmp; }
2222

2323
// degree to radians and vice-versa
24-
ICF float deg2rad(float val) { return val*M_PI / 180; }
25-
ICF double deg2rad(double val) { return val*M_PI / 180; }
26-
ICF float rad2deg(float val) { return val*180 / M_PI; }
27-
ICF double rad2deg(double val) { return val*180 / M_PI;}
24+
constexpr float deg2rad(float val) noexcept { return val*M_PI / 180; }
25+
constexpr double deg2rad(double val) noexcept { return val*M_PI / 180; }
26+
constexpr float rad2deg(float val) noexcept { return val*180 / M_PI; }
27+
constexpr double rad2deg(double val) noexcept { return val*180 / M_PI;}
2828

2929
// clamping/snapping
3030
template <class T>
31-
IC void clamp(T& val, const T& _low, const T& _high)
31+
constexpr void clamp(T& val, const T& _low, const T& _high)
3232
{
3333
if (val<_low)
3434
val = _low;
3535
else if (val>_high)
3636
val = _high;
3737
}
3838

39+
// XXX: Check usages and provide overloads for native types where arguments are NOT references.
3940
template <class T>
40-
IC T clampr(const T& val, const T& _low, const T& _high)
41+
constexpr T clampr(const T& val, const T& _low, const T& _high)
4142
{
42-
if (val<_low)
43+
if (val < _low)
4344
return _low;
44-
if (val>_high)
45+
if (val > _high)
4546
return _high;
4647
return val;
4748
}
4849

49-
IC float snapto(float value, float snap)
50+
inline float snapto(float value, float snap)
5051
{
5152
if (snap <= 0.f)
5253
return value;

src/xrCore/FTimer.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class XRCORE_API CTimerBase
3939
bool paused;
4040

4141
public:
42-
CTimerBase() : startTime(), pauseDuration(), pauseAccum(), paused(false) {}
42+
constexpr CTimerBase() noexcept : startTime(), pauseDuration(), pauseAccum(), paused(false) {}
4343

4444
void Start()
4545
{
@@ -88,18 +88,18 @@ class XRCORE_API CTimer : public CTimerBase
8888
}
8989

9090
public:
91-
CTimer() : m_time_factor(1.f), realTime(), time() {}
91+
constexpr CTimer() noexcept : m_time_factor(1.f), realTime(), time() {}
9292

93-
void Start()
93+
void Start() noexcept
9494
{
9595
if (paused) return;
9696

9797
super::Start();
9898
}
9999

100-
float time_factor() const { return m_time_factor; }
100+
float time_factor() const noexcept { return m_time_factor; }
101101

102-
void time_factor(const float time_factor)
102+
void time_factor(const float time_factor) noexcept
103103
{
104104
const auto current = super::getElapsedTime();
105105
time = getElapsedTime(current);
@@ -118,11 +118,11 @@ class XRCORE_API CTimer_paused_ex : public CTimer
118118
Time save_clock;
119119

120120
public:
121-
CTimer_paused_ex() : save_clock() {}
121+
CTimer_paused_ex() noexcept : save_clock() {}
122122
virtual ~CTimer_paused_ex() {}
123-
bool Paused() const { return paused; }
123+
bool Paused() const noexcept { return paused; }
124124

125-
void Pause(const bool b)
125+
void Pause(const bool b) noexcept
126126
{
127127
if (paused == b) return;
128128

src/xrCore/_math.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ XRCORE_API u32 qpc_counter = 0;
159159

160160
XRCORE_API processor_info ID;
161161

162-
XRCORE_API u64 QPC()
162+
XRCORE_API u64 QPC() noexcept
163163
{
164164
u64 _dest;
165165
QueryPerformanceCounter((PLARGE_INTEGER)&_dest);

src/xrCore/_math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ XRCORE_API extern u64 qpc_freq;
2424
XRCORE_API extern u32 qpc_counter;
2525

2626
XRCORE_API extern processor_info ID;
27-
XRCORE_API extern u64 QPC();
27+
XRCORE_API extern u64 QPC() noexcept;
2828

2929
#ifdef _MSC_VER
3030
// XXX: Stale checks. All MS' x86&x64 compilers cabable of compiling XRay-16 have __rdtsc

src/xrCore/_vector3d.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,167 +21,168 @@ struct _vector3
2121
ICF T& operator[](int i) { return *((T*)this + i); }
2222
ICF T& operator[](int i) const { return *((T*)this + i); }
2323

24-
ICF SelfRef set(T _x, T _y, T _z)
24+
ICF SelfRef set(T _x, T _y, T _z) noexcept
2525
{
2626
x = _x;
2727
y = _y;
2828
z = _z;
2929
return *this;
3030
}
3131

32-
ICF SelfRef set(const _vector3<float>& v)
32+
ICF SelfRef set(const _vector3<float>& v) noexcept
3333
{
3434
x = T(v.x);
3535
y = T(v.y);
3636
z = T(v.z);
3737
return *this;
3838
}
3939

40-
ICF SelfRef set(const _vector3<double>& v)
40+
ICF SelfRef set(const _vector3<double>& v) noexcept
4141
{
4242
x = T(v.x);
4343
y = T(v.y);
4444
z = T(v.z);
4545
return *this;
4646
}
4747

48-
ICF SelfRef set(float* p)
48+
ICF SelfRef set(float* p) noexcept
4949
{
5050
x = p[0];
5151
y = p[1];
5252
z = p[2];
5353
return *this;
5454
}
5555

56-
ICF SelfRef set(double* p)
56+
ICF SelfRef set(double* p) noexcept
5757
{
5858
x = p[0];
5959
y = p[1];
6060
z = p[2];
6161
return *this;
6262
}
6363

64-
ICF SelfRef add(const Self& v)
64+
// XXX: The vast majority of these basic math operations can be expressed as non-class functions.
65+
ICF SelfRef add(const Self& v) noexcept
6566
{
6667
x += v.x;
6768
y += v.y;
6869
z += v.z;
6970
return *this;
7071
}
7172

72-
ICF SelfRef add(T s)
73+
ICF SelfRef add(T s) noexcept
7374
{
7475
x += s;
7576
y += s;
7677
z += s;
7778
return *this;
7879
}
7980

80-
ICF SelfRef add(const Self& a, const Self& v)
81+
ICF SelfRef add(const Self& a, const Self& v) noexcept
8182
{
8283
x = a.x + v.x;
8384
y = a.y + v.y;
8485
z = a.z + v.z;
8586
return *this;
8687
}
8788

88-
ICF SelfRef add(const Self& a, T s)
89+
ICF SelfRef add(const Self& a, T s) noexcept
8990
{
9091
x = a.x + s;
9192
y = a.y + s;
9293
z = a.z + s;
9394
return *this;
9495
}
9596

96-
ICF SelfRef sub(const Self& v)
97+
ICF SelfRef sub(const Self& v) noexcept
9798
{
9899
x -= v.x;
99100
y -= v.y;
100101
z -= v.z;
101102
return *this;
102103
}
103104

104-
ICF SelfRef sub(T s)
105+
ICF SelfRef sub(T s) noexcept
105106
{
106107
x -= s;
107108
y -= s;
108109
z -= s;
109110
return *this;
110111
}
111112

112-
ICF SelfRef sub(const Self& a, const Self& v)
113+
ICF SelfRef sub(const Self& a, const Self& v) noexcept
113114
{
114115
x = a.x - v.x;
115116
y = a.y - v.y;
116117
z = a.z - v.z;
117118
return *this;
118119
}
119120

120-
ICF SelfRef sub(const Self& a, T s)
121+
ICF SelfRef sub(const Self& a, T s) noexcept
121122
{
122123
x = a.x - s;
123124
y = a.y - s;
124125
z = a.z - s;
125126
return *this;
126127
}
127128

128-
ICF SelfRef mul(const Self& v)
129+
ICF SelfRef mul(const Self& v) noexcept
129130
{
130131
x *= v.x;
131132
y *= v.y;
132133
z *= v.z;
133134
return *this;
134135
}
135136

136-
ICF SelfRef mul(T s)
137+
ICF SelfRef mul(T s) noexcept
137138
{
138139
x *= s;
139140
y *= s;
140141
z *= s;
141142
return *this;
142143
}
143144

144-
ICF SelfRef mul(const Self& a, const Self& v)
145+
ICF SelfRef mul(const Self& a, const Self& v) noexcept
145146
{
146147
x = a.x * v.x;
147148
y = a.y * v.y;
148149
z = a.z * v.z;
149150
return *this;
150151
}
151152

152-
ICF SelfRef mul(const Self& a, T s)
153+
ICF SelfRef mul(const Self& a, T s) noexcept
153154
{
154155
x = a.x * s;
155156
y = a.y * s;
156157
z = a.z * s;
157158
return *this;
158159
}
159160

160-
ICF SelfRef div(const Self& v)
161+
ICF SelfRef div(const Self& v) noexcept
161162
{
162163
x /= v.x;
163164
y /= v.y;
164165
z /= v.z;
165166
return *this;
166167
}
167168

168-
ICF SelfRef div(T s)
169+
ICF SelfRef div(T s) noexcept
169170
{
170171
x /= s;
171172
y /= s;
172173
z /= s;
173174
return *this;
174175
}
175176

176-
ICF SelfRef div(const Self& a, const Self& v)
177+
ICF SelfRef div(const Self& a, const Self& v) noexcept
177178
{
178179
x = a.x / v.x;
179180
y = a.y / v.y;
180181
z = a.z / v.z;
181182
return *this;
182183
}
183184

184-
ICF SelfRef div(const Self& a, T s)
185+
ICF SelfRef div(const Self& a, T s) noexcept
185186
{
186187
x = a.x / s;
187188
y = a.y / s;

src/xrGame/alife_switch_manager.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
////////////////////////////////////////////////////////////////////////////
88

99
#pragma once
10-
1110
#include "alife_simulator_base.h"
1211

12+
// XXX: WTF is this? CALifeSwitchManager IS-A CRandom??? I think NOT! CRandom should be aggregated, NOT inherited from!
1313
class CALifeSwitchManager : public virtual CALifeSimulatorBase, CRandom
1414
{
1515
protected:
@@ -40,11 +40,11 @@ class CALifeSwitchManager : public virtual CALifeSimulatorBase, CRandom
4040
IC CALifeSwitchManager(IPureServer* server, LPCSTR section);
4141
virtual ~CALifeSwitchManager();
4242
void switch_object(CSE_ALifeDynamicObject* object);
43-
IC float online_distance() const;
44-
IC float offline_distance() const;
45-
IC float switch_distance() const;
46-
IC void set_switch_distance(float switch_distance);
47-
IC void set_switch_factor(float switch_factor);
43+
IC float online_distance() const noexcept;
44+
IC float offline_distance() const noexcept;
45+
IC float switch_distance() const noexcept;
46+
IC void set_switch_distance(float switch_distance) noexcept;
47+
IC void set_switch_factor(float switch_factor) noexcept;
4848
};
4949

5050
#include "alife_switch_manager_inline.h"

src/xrGame/alife_switch_manager_inline.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ IC CALifeSwitchManager::CALifeSwitchManager(IPureServer* server, LPCSTR section)
1616
seed(u32(CPU::QPC() & 0xffffffff));
1717
}
1818

19-
IC float CALifeSwitchManager::online_distance() const { return (m_online_distance); }
20-
IC float CALifeSwitchManager::offline_distance() const { return (m_offline_distance); }
21-
IC float CALifeSwitchManager::switch_distance() const { return (m_switch_distance); }
22-
IC void CALifeSwitchManager::set_switch_distance(float switch_distance)
19+
IC float CALifeSwitchManager::online_distance() const noexcept { return (m_online_distance); }
20+
IC float CALifeSwitchManager::offline_distance() const noexcept { return (m_offline_distance); }
21+
IC float CALifeSwitchManager::switch_distance() const noexcept { return (m_switch_distance); }
22+
IC void CALifeSwitchManager::set_switch_distance(float switch_distance) noexcept
2323
{
2424
m_switch_distance = switch_distance;
2525
m_online_distance = m_switch_distance * (1.f - m_switch_factor);
2626
m_offline_distance = m_switch_distance * (1.f + m_switch_factor);
2727
}
2828

29-
IC void CALifeSwitchManager::set_switch_factor(float switch_factor)
29+
IC void CALifeSwitchManager::set_switch_factor(float switch_factor) noexcept
3030
{
3131
m_switch_factor = switch_factor;
3232
set_switch_distance(switch_distance());

src/xrServerEntities/script_token_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CScriptTokenList
2323
{
2424
pcstr m_name;
2525

26-
CTokenPredicateName(pcstr name) noexcept : m_name(name) {}
26+
constexpr CTokenPredicateName(pcstr name) noexcept : m_name(name) {}
2727
IC bool operator()(const xr_token& token) const noexcept { return token.name && !xr_strcmp(token.name, m_name); }
2828
};
2929

0 commit comments

Comments
 (0)