Skip to content

Commit cffed16

Browse files
committed
tweaks
1 parent c283b73 commit cffed16

32 files changed

+267
-248
lines changed

include/AudioDevice.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AudioDevice {
1818
*
1919
* @throws raylib::RaylibException Throws if the AudioDevice failed to initialize.
2020
*/
21-
AudioDevice(bool lateInit = false) {
21+
explicit AudioDevice(bool lateInit = false) {
2222
if (!lateInit) {
2323
Init();
2424
}
@@ -34,7 +34,7 @@ class AudioDevice {
3434
*
3535
* @throws raylib::RaylibException Throws if the AudioDevice failed to initialize.
3636
*/
37-
void Init() {
37+
static void Init() {
3838
::InitAudioDevice();
3939
if (!IsReady()) {
4040
throw RaylibException("Failed to initialize AudioDevice");
@@ -44,12 +44,12 @@ class AudioDevice {
4444
/**
4545
* Close the audio device and context.
4646
*/
47-
void Close() { ::CloseAudioDevice(); }
47+
static void Close() { ::CloseAudioDevice(); }
4848

4949
/**
5050
* Check if audio device has been initialized successfully.
5151
*/
52-
bool IsReady() const { return ::IsAudioDeviceReady(); }
52+
static bool IsReady() { return ::IsAudioDeviceReady(); }
5353

5454
/**
5555
* Set master volume (listener).

include/AudioStream.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ namespace raylib {
1111
*/
1212
class AudioStream : public ::AudioStream {
1313
public:
14-
AudioStream(const ::AudioStream& music) { set(music); }
14+
AudioStream(const ::AudioStream& music)
15+
: ::AudioStream(music)
16+
{ }
1517

1618
AudioStream(
1719
rAudioBuffer* buffer = nullptr,
@@ -34,7 +36,7 @@ class AudioStream : public ::AudioStream {
3436

3537
AudioStream(const AudioStream&) = delete;
3638

37-
AudioStream(AudioStream&& other) {
39+
AudioStream(AudioStream&& other) noexcept {
3840
set(other);
3941

4042
other.buffer = nullptr;
@@ -96,7 +98,7 @@ class AudioStream : public ::AudioStream {
9698
/**
9799
* Check if any audio stream buffers requires refill
98100
*/
99-
bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }
101+
[[nodiscard]] bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }
100102

101103
/**
102104
* Play audio stream
@@ -125,7 +127,7 @@ class AudioStream : public ::AudioStream {
125127
/**
126128
* Check if audio stream is playing
127129
*/
128-
bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }
130+
[[nodiscard]] bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }
129131

130132
/**
131133
* Stop audio stream
@@ -182,7 +184,7 @@ class AudioStream : public ::AudioStream {
182184
/**
183185
* Retrieve whether or not the audio stream is ready.
184186
*/
185-
bool IsValid() const { return ::IsAudioStreamValid(*this); }
187+
[[nodiscard]] bool IsValid() const { return ::IsAudioStreamValid(*this); }
186188

187189
/**
188190
* Load audio stream (to stream raw audio pcm data)

include/AutomationEventList.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
#include "./RaylibException.hpp"
55
#include "./raylib-cpp-utils.hpp"
66
#include "./raylib.hpp"
7+
#include <raylib.h>
78

89
namespace raylib {
910
/**
1011
* AutomationEventList management functions
1112
*/
1213
class AutomationEventList : public ::AutomationEventList {
1314
public:
14-
AutomationEventList(const ::AutomationEventList& automationEventList) { set(automationEventList); }
15+
AutomationEventList(const ::AutomationEventList& automationEventList)
16+
: ::AutomationEventList(automationEventList) {
17+
// Nothing.
18+
}
1519

1620
/**
1721
* Load an empty automation events list.

include/BoundingBox.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ class BoundingBox : public ::BoundingBox {
4141
/**
4242
* Detect collision between two boxes
4343
*/
44-
bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }
44+
[[nodiscard]] bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }
4545

4646
/**
4747
* Detect collision between box and sphere
4848
*/
49-
bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }
49+
[[nodiscard]] bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }
5050

5151
/**
5252
* Detect collision between ray and bounding box
5353
*/
54-
bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }
54+
[[nodiscard]] bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }
5555

5656
/**
5757
* Get collision information between ray and bounding box

include/Camera2D.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ namespace raylib {
1111
*/
1212
class Camera2D : public ::Camera2D {
1313
public:
14-
Camera2D(const ::Camera2D& camera) { set(camera); }
14+
Camera2D(const ::Camera2D& camera)
15+
: ::Camera2D(camera) {
16+
// Nothing.
17+
}
1518

16-
Camera2D() {}
19+
Camera2D() : ::Camera2D() {}
1720
Camera2D(::Vector2 offset, ::Vector2 target, float rotation = 0.0f, float zoom = 1.0f)
1821
: ::Camera2D{offset, target, rotation, zoom} {}
1922

@@ -40,17 +43,17 @@ class Camera2D : public ::Camera2D {
4043
/**
4144
* Returns camera 2d transform matrix
4245
*/
43-
Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }
46+
[[nodiscard]] Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }
4447

4548
/**
4649
* Returns the world space position for a 2d camera screen space position
4750
*/
48-
Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }
51+
[[nodiscard]] Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }
4952

5053
/**
5154
* Returns the screen space position for a 2d world space position
5255
*/
53-
Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
56+
[[nodiscard]] Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
5457
protected:
5558
void set(const ::Camera2D& camera) {
5659
offset = camera.offset;

include/Camera3D.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace raylib {
1111
*/
1212
class Camera3D : public ::Camera3D {
1313
public:
14-
Camera3D(const ::Camera3D& camera) { set(camera); }
14+
Camera3D(const ::Camera3D& camera) : ::Camera3D(camera) { }
1515

1616
/**
1717
* Create a new Camera3D.

include/Color.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,43 +36,43 @@ class Color : public ::Color {
3636
/**
3737
* Get Color structure from hexadecimal value
3838
*/
39-
Color(unsigned int hexValue) { set(::GetColor(hexValue)); }
39+
explicit Color(unsigned int hexValue) : ::Color(::GetColor(hexValue)) { }
4040

41-
Color(void* srcPtr, int format) { set(::GetPixelColor(srcPtr, format)); }
41+
Color(void* srcPtr, int format) : ::Color(::GetPixelColor(srcPtr, format)) { }
4242

4343
/**
4444
* Returns hexadecimal value for a Color
4545
*/
46-
int ToInt() const { return ::ColorToInt(*this); }
46+
[[nodiscard]] int ToInt() const { return ::ColorToInt(*this); }
4747

4848
/**
4949
* Returns hexadecimal value for a Color
5050
*/
51-
operator int() const { return ::ColorToInt(*this); }
51+
explicit operator int() const { return ::ColorToInt(*this); }
5252

53-
std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }
53+
[[nodiscard]] std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }
5454

55-
operator std::string() const { return ToString(); }
55+
explicit operator std::string() const { return ToString(); }
5656

5757
/**
5858
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
5959
*/
60-
Color Fade(float alpha) const { return ::Fade(*this, alpha); }
60+
[[nodiscard]] Color Fade(float alpha) const { return ::Fade(*this, alpha); }
6161

6262
/**
6363
* Returns Color normalized as float [0..1]
6464
*/
65-
Vector4 Normalize() const { return ::ColorNormalize(*this); }
65+
[[nodiscard]] Vector4 Normalize() const { return ::ColorNormalize(*this); }
6666

6767
/**
6868
* Returns Color from normalized values [0..1]
6969
*/
70-
Color(::Vector4 normalized) { set(::ColorFromNormalized(normalized)); }
70+
explicit Color(::Vector4 normalized) : Color(::ColorFromNormalized(normalized)) { }
7171

7272
/**
7373
* Returns HSV values for a Color
7474
*/
75-
Vector3 ToHSV() const { return ::ColorToHSV(*this); }
75+
[[nodiscard]] Vector3 ToHSV() const { return ::ColorToHSV(*this); }
7676

7777
GETTERSETTER(unsigned char, R, r)
7878
GETTERSETTER(unsigned char, G, g)
@@ -206,7 +206,7 @@ class Color : public ::Color {
206206
/**
207207
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
208208
*/
209-
Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }
209+
[[nodiscard]] Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }
210210

211211
Color Lerp(::Color color2, float factor) {
212212
return ::ColorLerp(*this, color2, factor);
@@ -215,7 +215,7 @@ class Color : public ::Color {
215215
/**
216216
* Returns src alpha-blended into dst color with tint
217217
*/
218-
Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }
218+
[[nodiscard]] Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }
219219

220220
static Color LightGray() { return LIGHTGRAY; }
221221
static Color Gray() { return GRAY; }

include/Font.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class Font : public ::Font {
2828
/**
2929
* Retrieves the default Font.
3030
*/
31-
Font() { set(::GetFontDefault()); }
31+
Font() : ::Font(::GetFontDefault()) { }
3232

33-
Font(const ::Font& font) { set(font); }
33+
Font(const ::Font& font) : ::Font(font) { }
3434

3535
/**
3636
* Loads a Font from the given file.
@@ -203,7 +203,7 @@ class Font : public ::Font {
203203
/**
204204
* Returns if the font is ready to be used.
205205
*/
206-
bool IsValid() const { return ::IsFontValid(*this); }
206+
[[nodiscard]] bool IsValid() const { return ::IsFontValid(*this); }
207207

208208
/**
209209
* Draw text using font and additional parameters.
@@ -286,33 +286,33 @@ class Font : public ::Font {
286286
/**
287287
* Measure string size for Font
288288
*/
289-
Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
289+
[[nodiscard]] Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
290290
return ::MeasureTextEx(*this, text, fontSize, spacing);
291291
}
292292

293293
/**
294294
* Measure string size for Font
295295
*/
296-
Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
296+
[[nodiscard]] Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
297297
return ::MeasureTextEx(*this, text.c_str(), fontSize, spacing);
298298
}
299299

300300
/**
301301
* Get index position for a unicode character on font
302302
*/
303-
int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }
303+
[[nodiscard]] int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }
304304

305305
/**
306306
* Create an image from text (custom sprite font)
307307
*/
308-
::Image ImageText(const char* text, float fontSize, float spacing, ::Color tint) const {
308+
[[nodiscard]] ::Image ImageText(const char* text, float fontSize, float spacing, ::Color tint) const {
309309
return ::ImageTextEx(*this, text, fontSize, spacing, tint);
310310
}
311311

312312
/**
313313
* Create an image from text (custom sprite font)
314314
*/
315-
::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
315+
[[nodiscard]] ::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
316316
return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint);
317317
}
318318
protected:

include/Gamepad.hpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ class Gamepad {
1818
GETTERSETTER(int, Number, number)
1919

2020
Gamepad& operator=(const Gamepad& gamepad) {
21-
set(gamepad);
21+
if (this != &gamepad) {
22+
set(static_cast<int>(gamepad));
23+
}
2224
return *this;
2325
}
2426

2527
Gamepad& operator=(int gamepadNumber) {
26-
set(gamepadNumber);
28+
if (this->number != gamepadNumber) {
29+
set(gamepadNumber);
30+
}
2731
return *this;
2832
}
2933

30-
operator int() const { return number; }
34+
explicit operator int() const { return number; }
3135

3236
/**
3337
* Detect if a gamepad is available
3438
*/
35-
bool IsAvailable() const { return ::IsGamepadAvailable(number); }
39+
[[nodiscard]] bool IsAvailable() const { return ::IsGamepadAvailable(number); }
3640

3741
/**
3842
* Detect if a gamepad is available
@@ -42,54 +46,54 @@ class Gamepad {
4246
/**
4347
* Return gamepad internal name id
4448
*/
45-
std::string GetName() const { return ::GetGamepadName(number); }
49+
[[nodiscard]] std::string GetName() const { return ::GetGamepadName(number); }
4650

4751
/**
4852
* Return gamepad internal name id
4953
*/
50-
operator std::string() const { return GetName(); }
54+
explicit operator std::string() const { return GetName(); }
5155

5256
/**
5357
* Detect if a gamepad button has been pressed once
5458
*/
55-
bool IsButtonPressed(int button) const { return ::IsGamepadButtonPressed(number, button); }
59+
[[nodiscard]] bool IsButtonPressed(int button) const { return ::IsGamepadButtonPressed(number, button); }
5660

5761
/**
5862
* Detect if a gamepad button is being pressed
5963
*/
60-
bool IsButtonDown(int button) const { return ::IsGamepadButtonDown(number, button); }
64+
[[nodiscard]] bool IsButtonDown(int button) const { return ::IsGamepadButtonDown(number, button); }
6165

6266
/**
6367
* Detect if a gamepad button has been released once
6468
*/
65-
bool IsButtonReleased(int button) const { return ::IsGamepadButtonReleased(number, button); }
69+
[[nodiscard]] bool IsButtonReleased(int button) const { return ::IsGamepadButtonReleased(number, button); }
6670

6771
/**
6872
* Detect if a gamepad button is NOT being pressed
6973
*/
70-
bool IsButtonUp(int button) const { return ::IsGamepadButtonUp(number, button); }
74+
[[nodiscard]] bool IsButtonUp(int button) const { return ::IsGamepadButtonUp(number, button); }
7175

7276
/**
7377
* Get the last gamepad button pressed
7478
*/
75-
int GetButtonPressed() const { return ::GetGamepadButtonPressed(); }
79+
static int GetButtonPressed() { return ::GetGamepadButtonPressed(); }
7680

7781
/**
7882
* Return gamepad axis count for a gamepad
7983
*/
80-
int GetAxisCount() const { return ::GetGamepadAxisCount(number); }
84+
[[nodiscard]] int GetAxisCount() const { return ::GetGamepadAxisCount(number); }
8185

8286
/**
8387
* Return axis movement value for a gamepad axis
8488
*/
85-
float GetAxisMovement(int axis) const { return ::GetGamepadAxisMovement(number, axis); }
89+
[[nodiscard]] float GetAxisMovement(int axis) const { return ::GetGamepadAxisMovement(number, axis); }
8690

87-
int SetMappings(const std::string& mappings) { return SetGamepadMappings(mappings.c_str()); }
91+
static int SetMappings(const std::string& mappings) { return SetGamepadMappings(mappings.c_str()); }
8892

8993
/**
9094
* Set gamepad vibration for both motors (duration in seconds)
9195
*/
92-
void SetVibration(float leftMotor, float rightMotor, float duration) {
96+
void SetVibration(float leftMotor, float rightMotor, float duration) const {
9397
::SetGamepadVibration(number, leftMotor, rightMotor, duration);
9498
}
9599
protected:

0 commit comments

Comments
 (0)