Skip to content

Commit

Permalink
A few 'constexpr' and 'noexcept' added to some obvious places.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlin-mike authored and Xottab-DUTY committed Jan 29, 2018
1 parent 6e250b2 commit 7a9e2c3
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 60 deletions.
35 changes: 18 additions & 17 deletions src/xrCommon/math_funcs_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "xrCommon/inlining_macros.h"
#include "xrCore/_bitwise.h" // iFloor

inline float _abs(float x) { return fabsf(x); }
inline float _sqrt(float x) { return sqrtf(x); }
inline float _sin(float x) { return sinf(x); }
inline float _cos(float x) { return cosf(x); }
inline double _abs(double x) { return fabs(x); }
inline double _sqrt(double x) { return sqrt(x); }
inline double _sin(double x) { return sin(x); }
inline double _cos(double x) { return cos(x); }
inline float _abs(float x) noexcept { return fabsf(x); }
inline float _sqrt(float x) noexcept { return sqrtf(x); }
inline float _sin(float x) noexcept { return sinf(x); }
inline float _cos(float x) noexcept { return cosf(x); }
inline double _abs(double x) noexcept { return fabs(x); }
inline double _sqrt(double x) noexcept { return sqrt(x); }
inline double _sin(double x) noexcept { return sin(x); }
inline double _cos(double x) noexcept { return cos(x); }

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

// degree to radians and vice-versa
ICF float deg2rad(float val) { return val*M_PI / 180; }
ICF double deg2rad(double val) { return val*M_PI / 180; }
ICF float rad2deg(float val) { return val*180 / M_PI; }
ICF double rad2deg(double val) { return val*180 / M_PI;}
constexpr float deg2rad(float val) noexcept { return val*M_PI / 180; }
constexpr double deg2rad(double val) noexcept { return val*M_PI / 180; }
constexpr float rad2deg(float val) noexcept { return val*180 / M_PI; }
constexpr double rad2deg(double val) noexcept { return val*180 / M_PI;}

// clamping/snapping
template <class T>
IC void clamp(T& val, const T& _low, const T& _high)
constexpr void clamp(T& val, const T& _low, const T& _high)
{
if (val<_low)
val = _low;
else if (val>_high)
val = _high;
}

// XXX: Check usages and provide overloads for native types where arguments are NOT references.
template <class T>
IC T clampr(const T& val, const T& _low, const T& _high)
constexpr T clampr(const T& val, const T& _low, const T& _high)
{
if (val<_low)
if (val < _low)
return _low;
if (val>_high)
if (val > _high)
return _high;
return val;
}

IC float snapto(float value, float snap)
inline float snapto(float value, float snap)
{
if (snap <= 0.f)
return value;
Expand Down
16 changes: 8 additions & 8 deletions src/xrCore/FTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class XRCORE_API CTimerBase
bool paused;

public:
CTimerBase() : startTime(), pauseDuration(), pauseAccum(), paused(false) {}
constexpr CTimerBase() noexcept : startTime(), pauseDuration(), pauseAccum(), paused(false) {}

void Start()
{
Expand Down Expand Up @@ -88,18 +88,18 @@ class XRCORE_API CTimer : public CTimerBase
}

public:
CTimer() : m_time_factor(1.f), realTime(), time() {}
constexpr CTimer() noexcept : m_time_factor(1.f), realTime(), time() {}

void Start()
void Start() noexcept
{
if (paused) return;

super::Start();
}

float time_factor() const { return m_time_factor; }
float time_factor() const noexcept { return m_time_factor; }

void time_factor(const float time_factor)
void time_factor(const float time_factor) noexcept
{
const auto current = super::getElapsedTime();
time = getElapsedTime(current);
Expand All @@ -118,11 +118,11 @@ class XRCORE_API CTimer_paused_ex : public CTimer
Time save_clock;

public:
CTimer_paused_ex() : save_clock() {}
CTimer_paused_ex() noexcept : save_clock() {}
virtual ~CTimer_paused_ex() {}
bool Paused() const { return paused; }
bool Paused() const noexcept { return paused; }

void Pause(const bool b)
void Pause(const bool b) noexcept
{
if (paused == b) return;

Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ XRCORE_API u32 qpc_counter = 0;

XRCORE_API processor_info ID;

XRCORE_API u64 QPC()
XRCORE_API u64 QPC() noexcept
{
u64 _dest;
QueryPerformanceCounter((PLARGE_INTEGER)&_dest);
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ XRCORE_API extern u64 qpc_freq;
XRCORE_API extern u32 qpc_counter;

XRCORE_API extern processor_info ID;
XRCORE_API extern u64 QPC();
XRCORE_API extern u64 QPC() noexcept;

#ifdef _MSC_VER
// XXX: Stale checks. All MS' x86&x64 compilers cabable of compiling XRay-16 have __rdtsc
Expand Down
43 changes: 22 additions & 21 deletions src/xrCore/_vector3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,167 +21,168 @@ struct _vector3
ICF T& operator[](int i) { return *((T*)this + i); }
ICF T& operator[](int i) const { return *((T*)this + i); }

ICF SelfRef set(T _x, T _y, T _z)
ICF SelfRef set(T _x, T _y, T _z) noexcept
{
x = _x;
y = _y;
z = _z;
return *this;
}

ICF SelfRef set(const _vector3<float>& v)
ICF SelfRef set(const _vector3<float>& v) noexcept
{
x = T(v.x);
y = T(v.y);
z = T(v.z);
return *this;
}

ICF SelfRef set(const _vector3<double>& v)
ICF SelfRef set(const _vector3<double>& v) noexcept
{
x = T(v.x);
y = T(v.y);
z = T(v.z);
return *this;
}

ICF SelfRef set(float* p)
ICF SelfRef set(float* p) noexcept
{
x = p[0];
y = p[1];
z = p[2];
return *this;
}

ICF SelfRef set(double* p)
ICF SelfRef set(double* p) noexcept
{
x = p[0];
y = p[1];
z = p[2];
return *this;
}

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

ICF SelfRef add(T s)
ICF SelfRef add(T s) noexcept
{
x += s;
y += s;
z += s;
return *this;
}

ICF SelfRef add(const Self& a, const Self& v)
ICF SelfRef add(const Self& a, const Self& v) noexcept
{
x = a.x + v.x;
y = a.y + v.y;
z = a.z + v.z;
return *this;
}

ICF SelfRef add(const Self& a, T s)
ICF SelfRef add(const Self& a, T s) noexcept
{
x = a.x + s;
y = a.y + s;
z = a.z + s;
return *this;
}

ICF SelfRef sub(const Self& v)
ICF SelfRef sub(const Self& v) noexcept
{
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}

ICF SelfRef sub(T s)
ICF SelfRef sub(T s) noexcept
{
x -= s;
y -= s;
z -= s;
return *this;
}

ICF SelfRef sub(const Self& a, const Self& v)
ICF SelfRef sub(const Self& a, const Self& v) noexcept
{
x = a.x - v.x;
y = a.y - v.y;
z = a.z - v.z;
return *this;
}

ICF SelfRef sub(const Self& a, T s)
ICF SelfRef sub(const Self& a, T s) noexcept
{
x = a.x - s;
y = a.y - s;
z = a.z - s;
return *this;
}

ICF SelfRef mul(const Self& v)
ICF SelfRef mul(const Self& v) noexcept
{
x *= v.x;
y *= v.y;
z *= v.z;
return *this;
}

ICF SelfRef mul(T s)
ICF SelfRef mul(T s) noexcept
{
x *= s;
y *= s;
z *= s;
return *this;
}

ICF SelfRef mul(const Self& a, const Self& v)
ICF SelfRef mul(const Self& a, const Self& v) noexcept
{
x = a.x * v.x;
y = a.y * v.y;
z = a.z * v.z;
return *this;
}

ICF SelfRef mul(const Self& a, T s)
ICF SelfRef mul(const Self& a, T s) noexcept
{
x = a.x * s;
y = a.y * s;
z = a.z * s;
return *this;
}

ICF SelfRef div(const Self& v)
ICF SelfRef div(const Self& v) noexcept
{
x /= v.x;
y /= v.y;
z /= v.z;
return *this;
}

ICF SelfRef div(T s)
ICF SelfRef div(T s) noexcept
{
x /= s;
y /= s;
z /= s;
return *this;
}

ICF SelfRef div(const Self& a, const Self& v)
ICF SelfRef div(const Self& a, const Self& v) noexcept
{
x = a.x / v.x;
y = a.y / v.y;
z = a.z / v.z;
return *this;
}

ICF SelfRef div(const Self& a, T s)
ICF SelfRef div(const Self& a, T s) noexcept
{
x = a.x / s;
y = a.y / s;
Expand Down
12 changes: 6 additions & 6 deletions src/xrGame/alife_switch_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
////////////////////////////////////////////////////////////////////////////

#pragma once

#include "alife_simulator_base.h"

// XXX: WTF is this? CALifeSwitchManager IS-A CRandom??? I think NOT! CRandom should be aggregated, NOT inherited from!
class CALifeSwitchManager : public virtual CALifeSimulatorBase, CRandom
{
protected:
Expand Down Expand Up @@ -40,11 +40,11 @@ class CALifeSwitchManager : public virtual CALifeSimulatorBase, CRandom
IC CALifeSwitchManager(IPureServer* server, LPCSTR section);
virtual ~CALifeSwitchManager();
void switch_object(CSE_ALifeDynamicObject* object);
IC float online_distance() const;
IC float offline_distance() const;
IC float switch_distance() const;
IC void set_switch_distance(float switch_distance);
IC void set_switch_factor(float switch_factor);
IC float online_distance() const noexcept;
IC float offline_distance() const noexcept;
IC float switch_distance() const noexcept;
IC void set_switch_distance(float switch_distance) noexcept;
IC void set_switch_factor(float switch_factor) noexcept;
};

#include "alife_switch_manager_inline.h"
10 changes: 5 additions & 5 deletions src/xrGame/alife_switch_manager_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ IC CALifeSwitchManager::CALifeSwitchManager(IPureServer* server, LPCSTR section)
seed(u32(CPU::QPC() & 0xffffffff));
}

IC float CALifeSwitchManager::online_distance() const { return (m_online_distance); }
IC float CALifeSwitchManager::offline_distance() const { return (m_offline_distance); }
IC float CALifeSwitchManager::switch_distance() const { return (m_switch_distance); }
IC void CALifeSwitchManager::set_switch_distance(float switch_distance)
IC float CALifeSwitchManager::online_distance() const noexcept { return (m_online_distance); }
IC float CALifeSwitchManager::offline_distance() const noexcept { return (m_offline_distance); }
IC float CALifeSwitchManager::switch_distance() const noexcept { return (m_switch_distance); }
IC void CALifeSwitchManager::set_switch_distance(float switch_distance) noexcept
{
m_switch_distance = switch_distance;
m_online_distance = m_switch_distance * (1.f - m_switch_factor);
m_offline_distance = m_switch_distance * (1.f + m_switch_factor);
}

IC void CALifeSwitchManager::set_switch_factor(float switch_factor)
IC void CALifeSwitchManager::set_switch_factor(float switch_factor) noexcept
{
m_switch_factor = switch_factor;
set_switch_distance(switch_distance());
Expand Down
2 changes: 1 addition & 1 deletion src/xrServerEntities/script_token_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CScriptTokenList
{
pcstr m_name;

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

Expand Down

0 comments on commit 7a9e2c3

Please sign in to comment.