Skip to content

Commit c92674d

Browse files
authored
Merge pull request #105 from RobLoach/by-reference
Pass objects by reference
2 parents 2dc2c3f + d9ec434 commit c92674d

34 files changed

+429
-238
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- `models_first_person_maze.cpp` example
1212
- String override functions to use `std::string` directly instead of `const char*`
1313
- `std::vector<std::string>` wrapper for `GetDirectoryFiles()` and `GetDroppedFiles()`
14+
- `raylib::Color::RayWhite()` static functions to build `Color` objects
15+
- `Rectangle.GetPosition()` and `Rectangle.SetPosition()`
16+
- `Rectangle.GetSize()` and `Rectangle.SetSize()`
1417

1518
### Fixed
1619
- `Mouse::SetX()` and `Mouse::SetY()`
20+
- Most objects are now passed by reference
1721
- Error correction when unloading images, materials, models and meshes
1822

23+
### Changed
24+
- `Mouse` functions are now `static`. Use `Mouse::SetX()` instead of using `Mouse mouse`.
25+
- `Camera*::BeginMode()` and `Camera*::EndMode()` no longer have 2D/3D in the name
26+
1927
## [v3.5.0-alpha1] - 2020-12-26
2028
### Changed
2129
- Update to raylib 3.5.0

examples/core/core_3d_camera_first_person.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main() {
6161

6262
background.ClearBackground();
6363

64-
camera.BeginMode3D();
64+
camera.BeginMode();
6565

6666
DrawPlane(Vector3{ 0.0f, 0.0f, 0.0f }, Vector2{ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground
6767
DrawCube(Vector3{ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall
@@ -75,7 +75,7 @@ int main() {
7575
positions[i].DrawCubeWires(2.0f, heights[i], 2.0f, MAROON);
7676
}
7777

78-
EndMode3D();
78+
camera.EndMode();
7979

8080
DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f));
8181
DrawRectangleLines( 10, 10, 220, 70, BLUE);

examples/models/models_billboard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ int main() {
5050

5151
ClearBackground(RAYWHITE);
5252

53-
camera.BeginMode3D();
53+
camera.BeginMode();
5454

5555
DrawGrid(10, 1.0f); // Draw a grid
5656

5757
camera.DrawBillboard(bill, billPosition, 2.0f, WHITE);
5858

59-
camera.EndMode3D();
59+
camera.EndMode();
6060

6161
DrawFPS(10, 10);
6262

examples/models/models_first_person_maze.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int main(void)
7575
for (int x = 0; x < cubicmap.width; x++)
7676
{
7777
if ((mapPixels[y*cubicmap.width + x].r == 255) && // Collision: white pixel, only check R channel
78-
(playerPos.CheckCollisionCircleRec(playerRadius,
78+
(playerPos.CheckCollisionCircle(playerRadius,
7979
(Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f })))
8080
{
8181
// Collision detected, reset camera position
@@ -91,12 +91,12 @@ int main(void)
9191

9292
ClearBackground(RAYWHITE);
9393

94-
camera.BeginMode3D();
94+
camera.BeginMode();
9595

9696
model.Draw(mapPosition); // Draw maze map
9797
// playerPosition.DrawCube((Vector3){ 0.2f, 0.4f, 0.2f }, RED); // Draw player
9898

99-
camera.EndMode3D();
99+
camera.EndMode();
100100

101101
cubicmap.Draw((Vector2){ static_cast<float>(GetScreenWidth() - cubicmap.width*4 - 20), 20 }, 0.0f, 4.0f, WHITE);
102102
DrawRectangleLines(GetScreenWidth() - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);

examples/textures/textures_image_drawing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ int main(void)
3535
// Draw one image over the other with a scaling of 1.5f
3636
parrots
3737
.Draw(cat,
38-
raylib::Rectangle(0, 0, cat.width, cat.height),
39-
raylib::Rectangle(30, 40, cat.width*1.5f, cat.height*1.5f))
40-
.Crop(raylib::Rectangle(0, 50, parrots.width, parrots.height - 100)); // Crop resulting image
38+
raylib::Rectangle(0, 0, cat.GetWidth(), cat.GetHeight()),
39+
raylib::Rectangle(30, 40, cat.GetWidth() * 1.5f, cat.GetHeight() * 1.5f))
40+
.Crop(raylib::Rectangle(0, 50, parrots.GetWidth(), parrots.GetHeight() - 100)); // Crop resulting image
4141

4242
// Load custom font for frawing on image
4343
raylib::Font font("resources/custom_jupiter_crash.png");

include/AudioStream.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace raylib {
3434
*/
3535
class AudioStream : public ::AudioStream {
3636
public:
37-
AudioStream(::AudioStream music) {
37+
AudioStream(const ::AudioStream& music) {
3838
set(music);
3939
}
4040

@@ -149,7 +149,7 @@ class AudioStream : public ::AudioStream {
149149
}
150150

151151
protected:
152-
inline void set(::AudioStream stream) {
152+
inline void set(const ::AudioStream& stream) {
153153
buffer = stream.buffer;
154154
sampleRate = stream.sampleRate;
155155
sampleSize = stream.sampleSize;

include/BoundingBox.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ namespace raylib {
3434
*/
3535
class BoundingBox : public ::BoundingBox {
3636
public:
37-
BoundingBox(::BoundingBox box) {
37+
BoundingBox(const ::BoundingBox& box) {
3838
set(box);
3939
}
4040

4141
/**
4242
* Compute mesh bounding box limits
4343
*/
44-
BoundingBox(::Mesh mesh) {
45-
set(MeshBoundingBox(mesh));
44+
BoundingBox(const ::Mesh& mesh) {
45+
set(::MeshBoundingBox(mesh));
4646
}
4747

4848
BoundingBox(::Vector3 Min, ::Vector3 Max) {
@@ -66,15 +66,15 @@ class BoundingBox : public ::BoundingBox {
6666
/**
6767
* Draw a bounding box with wires
6868
*/
69-
inline BoundingBox& Draw(::Color color = WHITE) {
69+
inline BoundingBox& Draw(::Color color = {255, 255, 255, 255}) {
7070
DrawBoundingBox(*this, color);
7171
return *this;
7272
}
7373

7474
/**
7575
* Detect collision between two boxes
7676
*/
77-
inline bool CheckCollision(::BoundingBox box2) const {
77+
inline bool CheckCollision(const ::BoundingBox& box2) const {
7878
return CheckCollisionBoxes(*this, box2);
7979
}
8080

@@ -88,12 +88,12 @@ class BoundingBox : public ::BoundingBox {
8888
/**
8989
* Detect collision between ray and bounding box
9090
*/
91-
inline bool CheckCollision(::Ray ray) const {
91+
inline bool CheckCollision(const ::Ray& ray) const {
9292
return CheckCollisionRayBox(ray, *this);
9393
}
9494

9595
protected:
96-
inline void set(::BoundingBox box) {
96+
inline void set(const ::BoundingBox& box) {
9797
min = box.min;
9898
max = box.max;
9999
}

include/Camera2D.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
namespace raylib {
3333
class Camera2D : public ::Camera2D {
3434
public:
35+
Camera2D() {}
36+
Camera2D(const ::Camera2D& camera) {
37+
set(camera);
38+
}
39+
3540
Camera2D(::Vector2 offsetValue, ::Vector2 targetValue, float rotationValue = 0,
3641
float zoomValue = 1) {
3742
offset = offsetValue;
@@ -40,12 +45,12 @@ class Camera2D : public ::Camera2D {
4045
zoom = zoomValue;
4146
}
4247

43-
inline Camera2D& BeginMode2D() {
48+
inline Camera2D& BeginMode() {
4449
::BeginMode2D(*this);
4550
return *this;
4651
}
4752

48-
inline Camera2D& EndMode2D() {
53+
inline Camera2D& EndMode() {
4954
::EndMode2D();
5055
return *this;
5156
}
@@ -75,14 +80,14 @@ class Camera2D : public ::Camera2D {
7580
/**
7681
* Returns the screen space position for a 3d world space position
7782
*/
78-
inline Vector2 GetWorldToScreen2D(Vector2 position) const {
83+
inline Vector2 GetWorldToScreen(::Vector2 position) const {
7984
return ::GetWorldToScreen2D(position, *this);
8085
}
8186

8287
/**
8388
* Returns the world space position for a 2d camera screen space position
8489
*/
85-
inline Vector2 GetScreenToWorld2D(Vector2 position) const {
90+
inline Vector2 GetScreenToWorld(::Vector2 position) const {
8691
return ::GetScreenToWorld2D(position, *this);
8792
}
8893

include/Camera3D.hpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
namespace raylib {
3333
class Camera3D : public ::Camera3D {
3434
public:
35+
Camera3D(const ::Camera3D& camera) {
36+
set(camera);
37+
}
38+
3539
Camera3D(::Vector3 positionValue, ::Vector3 targetValue, ::Vector3 upValue,
3640
float fovyValue = 0, int typeValue = 0) {
3741
position = positionValue;
@@ -59,11 +63,18 @@ class Camera3D : public ::Camera3D {
5963
return *this;
6064
}
6165

62-
Camera3D& BeginMode3D() {
66+
/**
67+
* Initializes 3D mode with custom camera (3D)
68+
*/
69+
Camera3D& BeginMode() {
6370
::BeginMode3D(*this);
6471
return *this;
6572
}
66-
Camera3D& EndMode3D() {
73+
74+
/**
75+
* Ends 3D mode and returns to default 2D orthographic mode
76+
*/
77+
Camera3D& EndMode() {
6778
::EndMode3D();
6879
return *this;
6980
}
@@ -102,7 +113,9 @@ class Camera3D : public ::Camera3D {
102113
/**
103114
* Set camera move controls (1st person and 3rd person cameras)
104115
*/
105-
inline Camera3D& SetMoveControls(int frontKey, int backKey, int rightKey, int leftKey,
116+
inline Camera3D& SetMoveControls(
117+
int frontKey, int backKey,
118+
int rightKey, int leftKey,
106119
int upKey, int downKey) {
107120
::SetCameraMoveControls(frontKey, backKey, rightKey, leftKey, upKey, downKey);
108121
return *this;
@@ -138,14 +151,21 @@ class Camera3D : public ::Camera3D {
138151
return ::GetWorldToScreen(position, *this);
139152
}
140153

141-
inline Camera3D& DrawBillboard(::Texture2D texture, ::Vector3 center, float size,
142-
::Color tint = WHITE) {
154+
inline Camera3D& DrawBillboard(
155+
const ::Texture2D& texture,
156+
::Vector3 center,
157+
float size,
158+
::Color tint = {255, 255, 255, 255}) {
143159
::DrawBillboard(*this, texture, center, size, tint);
144160
return *this;
145161
}
146162

147-
inline Camera3D& DrawBillboard(::Texture2D texture, ::Rectangle sourceRec, ::Vector3 center,
148-
float size, ::Color tint = WHITE) {
163+
inline Camera3D& DrawBillboard(
164+
const ::Texture2D& texture,
165+
::Rectangle sourceRec,
166+
::Vector3 center,
167+
float size,
168+
::Color tint = {255, 255, 255, 255}) {
149169
::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
150170
return *this;
151171
}

include/Color.hpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@
3434
namespace raylib {
3535
class Color : public ::Color {
3636
public:
37-
Color(::Color color) {
38-
r = color.r;
39-
g = color.g;
40-
b = color.b;
41-
a = color.a;
37+
Color(const ::Color& color) {
38+
set(color);
4239
}
4340

4441
Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) :
4542
::Color{red, green, blue, alpha} {};
43+
4644
Color(unsigned char red, unsigned char green, unsigned char blue) :
4745
::Color{red, green, blue, 255} {};
4846

@@ -61,7 +59,7 @@ class Color : public ::Color {
6159
/**
6260
* Returns a Color from HSV values
6361
*/
64-
static Color FromHSV(float hue, float saturation, float value) {
62+
static ::Color FromHSV(float hue, float saturation, float value) {
6563
return ::ColorFromHSV(hue, saturation, value);
6664
}
6765

@@ -183,14 +181,19 @@ class Color : public ::Color {
183181
return *this;
184182
}
185183

186-
inline Color& DrawText(::Font font, const std::string& text, ::Vector2 position,
184+
inline Color& DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
187185
float fontSize, float spacing) {
188186
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, *this);
189187
return *this;
190188
}
191189

192-
inline Color& DrawText(::Font font, const std::string& text, ::Rectangle rec, float fontSize,
193-
float spacing, bool wordWrap = false) {
190+
inline Color& DrawText(
191+
const ::Font& font,
192+
const std::string& text,
193+
::Rectangle rec,
194+
float fontSize,
195+
float spacing,
196+
bool wordWrap = false) {
194197
::DrawTextRec(font, text.c_str(), rec, fontSize, spacing, wordWrap, *this);
195198
return *this;
196199
}
@@ -239,6 +242,33 @@ class Color : public ::Color {
239242
return ::ColorAlphaBlend(dst, *this, tint);
240243
}
241244

245+
inline static Color LightGray() { return LIGHTGRAY; }
246+
inline static Color Gray() { return GRAY; }
247+
inline static Color DarkGray() { return DARKGRAY; }
248+
inline static Color Yellow() { return YELLOW; }
249+
inline static Color Gold() { return GOLD; }
250+
inline static Color Orange() { return ORANGE; }
251+
inline static Color Pink() { return PINK; }
252+
inline static Color Red() { return RED; }
253+
inline static Color Maroon() { return MAROON; }
254+
inline static Color Green() { return GREEN; }
255+
inline static Color Lime() { return LIME; }
256+
inline static Color DarkGreen() { return DARKGREEN; }
257+
inline static Color SkyBlue() { return SKYBLUE; }
258+
inline static Color Blue() { return BLUE; }
259+
inline static Color DarkBlue() { return DARKBLUE; }
260+
inline static Color Purple() { return PURPLE; }
261+
inline static Color Violet() { return VIOLET; }
262+
inline static Color DarkPurple() { return DARKPURPLE; }
263+
inline static Color Beige() { return BEIGE; }
264+
inline static Color Brown() { return BROWN; }
265+
inline static Color DarkBrown() { return DARKBROWN; }
266+
inline static Color White() { return WHITE; }
267+
inline static Color Black() { return BLACK; }
268+
inline static Color Blank() { return BLANK; }
269+
inline static Color Magenta() { return MAGENTA; }
270+
inline static Color RayWhite() { return RAYWHITE; }
271+
242272
protected:
243273
inline void set(const ::Color& color) {
244274
r = color.r;

0 commit comments

Comments
 (0)