From 2cc804cacd1dd5943e4600934b0b900a1eb4f2f4 Mon Sep 17 00:00:00 2001 From: Sophie Kirschner Date: Sun, 17 Oct 2021 20:17:40 +0300 Subject: [PATCH 1/6] Updated to work with raylib master Working with commit https://github.com/raysan5/raylib/commit/a1db0220a1582a568ce05257d1e5b602132602a1 --- include/AudioStream.hpp | 12 +++---- include/BoundingBox.hpp | 11 +++++-- include/CMakeLists.txt | 2 +- include/Camera3D.hpp | 2 +- include/Color.hpp | 11 ++++--- include/Font.hpp | 47 ++++++++++++-------------- include/Functions.hpp | 2 +- include/Image.hpp | 14 ++------ include/Mesh.hpp | 6 ++-- include/Model.hpp | 4 +-- include/ModelAnimation.hpp | 2 +- include/Music.hpp | 10 +++--- include/Ray.hpp | 37 ++++++++++----------- include/RayCollision.hpp | 60 ++++++++++++++++++++++++++++++++++ include/RayHitInfo.hpp | 67 -------------------------------------- include/Sound.hpp | 10 +++--- include/Texture.hpp | 2 +- include/Wave.hpp | 12 +++---- include/raylib-cpp.hpp | 2 +- 19 files changed, 150 insertions(+), 163 deletions(-) create mode 100644 include/RayCollision.hpp delete mode 100644 include/RayHitInfo.hpp diff --git a/include/AudioStream.hpp b/include/AudioStream.hpp index f80613d..dc0b77b 100644 --- a/include/AudioStream.hpp +++ b/include/AudioStream.hpp @@ -18,7 +18,7 @@ class AudioStream : public ::AudioStream { * Init audio stream (to stream raw audio pcm data) */ AudioStream(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) { - set(InitAudioStream(SampleRate, SampleSize, Channels)); + set(LoadAudioStream(SampleRate, SampleSize, Channels)); } AudioStream(const AudioStream&) = delete; @@ -33,7 +33,7 @@ class AudioStream : public ::AudioStream { } ~AudioStream() { - Close(); + Unload(); } GETTERSETTER(rAudioBuffer *, Buffer, buffer) @@ -53,7 +53,7 @@ class AudioStream : public ::AudioStream { return *this; } - Close(); + Unload(); set(other); other.buffer = nullptr; @@ -73,10 +73,10 @@ class AudioStream : public ::AudioStream { } /** - * Close audio stream and free memory + * Unload audio stream and free memory */ - inline void Close() { - ::CloseAudioStream(*this); + inline void Unload() { + ::UnloadAudioStream(*this); } /** diff --git a/include/BoundingBox.hpp b/include/BoundingBox.hpp index 1c59cb7..2452649 100644 --- a/include/BoundingBox.hpp +++ b/include/BoundingBox.hpp @@ -18,7 +18,7 @@ class BoundingBox : public ::BoundingBox { * Compute mesh bounding box limits */ BoundingBox(const ::Mesh& mesh) { - set(::MeshBoundingBox(mesh)); + set(::GetMeshBoundingBox(mesh)); } BoundingBox(::Vector3 minMax) : ::BoundingBox{minMax, minMax} {} @@ -58,7 +58,14 @@ class BoundingBox : public ::BoundingBox { * Detect collision between ray and bounding box */ inline bool CheckCollision(const ::Ray& ray) const { - return CheckCollisionRayBox(ray, *this); + return GetRayCollisionBox(ray, *this).hit; + } + + /** + * Get collision information between ray and bounding box + */ + inline RayCollision GetCollision(const ::Ray& ray) const { + return GetRayCollisionBox(ray, *this); } private: diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index bde1964..25be549 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -25,7 +25,7 @@ install(FILES physac.hpp Physics.hpp Ray.hpp - RayHitInfo.hpp + RayCollision.hpp raylib-cpp-utils.hpp raylib-cpp.hpp raylib.hpp diff --git a/include/Camera3D.hpp b/include/Camera3D.hpp index 2970588..c88182b 100644 --- a/include/Camera3D.hpp +++ b/include/Camera3D.hpp @@ -143,7 +143,7 @@ class Camera3D : public ::Camera3D { const ::Texture2D& texture, ::Rectangle sourceRec, ::Vector3 center, - float size, + ::Vector2 size, ::Color tint = {255, 255, 255, 255}) { ::DrawBillboardRec(*this, texture, sourceRec, center, size, tint); return *this; diff --git a/include/Color.hpp b/include/Color.hpp index 29becae..79ca649 100644 --- a/include/Color.hpp +++ b/include/Color.hpp @@ -163,13 +163,14 @@ class Color : public ::Color { } inline Color& DrawText( - const ::Font& font, + const ::Font font, const std::string& text, - ::Rectangle rec, + ::Vector2 position, + ::Vector2 origin, + float rotation, float fontSize, - float spacing, - bool wordWrap = false) { - ::DrawTextRec(font, text.c_str(), rec, fontSize, spacing, wordWrap, *this); + float spacing) { + ::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, *this); return *this; } diff --git a/include/Font.hpp b/include/Font.hpp index 81d2a2d..711bec4 100644 --- a/include/Font.hpp +++ b/include/Font.hpp @@ -44,11 +44,11 @@ class Font : public ::Font { set(other); other.baseSize = 0; - other.charsCount = 0; - other.charsPadding = 0; + other.glyphCount = 0; + other.glyphPadding = 0; other.texture = { 0 }; other.recs = nullptr; - other.chars = nullptr; + other.glyphs = nullptr; } ~Font() { @@ -60,11 +60,11 @@ class Font : public ::Font { } GETTERSETTER(int, BaseSize, baseSize) - GETTERSETTER(int, CharsCount, charsCount) - GETTERSETTER(int, CharsPadding, charsPadding) + GETTERSETTER(int, GlyphCount, glyphCount) + GETTERSETTER(int, GlyphPadding, glyphPadding) GETTERSETTER(::Texture2D, Texture, texture) GETTERSETTER(::Rectangle*, Recs, recs) - GETTERSETTER(::CharInfo*, Chars, chars) + GETTERSETTER(::GlyphInfo*, Glyphs, glyphs) Font& operator=(const ::Font& font) { set(font); @@ -82,11 +82,11 @@ class Font : public ::Font { set(other); other.baseSize = 0; - other.charsCount = 0; - other.charsPadding = 0; + other.glyphCount = 0; + other.glyphPadding = 0; other.texture = { 0 }; other.recs = nullptr; - other.chars = nullptr; + other.glyphs = nullptr; return *this; } @@ -100,20 +100,15 @@ class Font : public ::Font { return *this; } - inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, - bool wordWrap = false, ::Color tint = WHITE) { - ::DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint); - return *this; - } - - /** - * Draw text using font inside rectangle limits with support for text selection. - */ - inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, - bool wordWrap, ::Color tint, int selectStart, int selectLength, ::Color selectText, - ::Color selectBack) { - ::DrawTextRecEx(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint, - selectStart, selectLength, selectText, selectBack); + inline Font& DrawText( + const std::string& text, + ::Vector2 position, + ::Vector2 origin, + float rotation, + float fontSize, + float spacing, + ::Color tint = WHITE) { + ::DrawTextPro(*this, text.c_str(), position, origin, rotation, fontSize, spacing, tint); return *this; } @@ -153,11 +148,11 @@ class Font : public ::Font { private: void set(const ::Font& font) { baseSize = font.baseSize; - charsCount = font.charsCount; - charsPadding = font.charsPadding; + glyphCount = font.glyphCount; + glyphPadding = font.glyphPadding; texture = font.texture; recs = font.recs; - chars = font.chars; + glyphs = font.glyphs; } }; } // namespace raylib diff --git a/include/Functions.hpp b/include/Functions.hpp index 956867f..b1efac3 100644 --- a/include/Functions.hpp +++ b/include/Functions.hpp @@ -67,7 +67,7 @@ RLCPPAPI inline void TakeScreenshot(const std::string& fileName) { RLCPPAPI std::string LoadFileText(const std::string& fileName) { char* text = ::LoadFileText(fileName.c_str()); std::string output(text); - ::UnloadFileText((unsigned char*)text); + ::UnloadFileText(text); return output; } diff --git a/include/Image.hpp b/include/Image.hpp index e582895..8efe2d7 100644 --- a/include/Image.hpp +++ b/include/Image.hpp @@ -35,7 +35,7 @@ class Image : public ::Image { } Image(const ::Texture2D& texture) { - set(::GetTextureData(texture)); + set(::LoadImageFromTexture(texture)); } Image(int width, int height, ::Color color = {255, 255, 255, 255}) { @@ -74,8 +74,8 @@ class Image : public ::Image { /** * Get pixel data from screen buffer and return an Image (screenshot) */ - static ::Image GetScreenData() { - return ::GetScreenData(); + static ::Image LoadFromScreen() { + return ::LoadImageFromScreen(); } /** @@ -122,14 +122,6 @@ class Image : public ::Image { return ::GenImageWhiteNoise(width, height, factor); } - /** - * Generate image: perlin noise - */ - static ::Image PerlinNoise(int width, int height, int offsetX, int offsetY, - float scale = 1.0f) { - return ::GenImagePerlinNoise(width, height, offsetX, offsetY, scale); - } - /** * Generate image: cellular algorithm. Bigger tileSize means bigger cells */ diff --git a/include/Mesh.hpp b/include/Mesh.hpp index 4c1dc22..97aa46b 100644 --- a/include/Mesh.hpp +++ b/include/Mesh.hpp @@ -220,7 +220,7 @@ class Mesh : public ::Mesh { * Compute mesh bounding box limits */ inline raylib::BoundingBox BoundingBox() const { - return ::MeshBoundingBox(*this); + return ::GetMeshBoundingBox(*this); } /** @@ -234,7 +234,7 @@ class Mesh : public ::Mesh { * Compute mesh tangents */ inline Mesh& Tangents() { - ::MeshTangents(this); + ::GenMeshTangents(this); return *this; } @@ -242,7 +242,7 @@ class Mesh : public ::Mesh { * Compute mesh binormals (aka bitangent) */ inline Mesh& Binormals() { - ::MeshBinormals(this); + ::GenMeshBinormals(this); return *this; } diff --git a/include/Model.hpp b/include/Model.hpp index 185295e..6a9f2b8 100644 --- a/include/Model.hpp +++ b/include/Model.hpp @@ -109,8 +109,8 @@ class Model : public ::Model { /** * Get collision info between ray and model */ - inline RayHitInfo GetCollision(const ::Ray& ray) const { - return ::GetCollisionRayModel(ray, *this); + inline RayCollision GetCollision(const ::Ray& ray) const { + return ::GetRayCollisionModel(ray, *this); } /** diff --git a/include/ModelAnimation.hpp b/include/ModelAnimation.hpp index 4895a53..cdbafe3 100644 --- a/include/ModelAnimation.hpp +++ b/include/ModelAnimation.hpp @@ -37,7 +37,7 @@ class ModelAnimation : public ::ModelAnimation { * Load model animations from file */ static std::vector Load(const std::string& fileName) { - int count = 0; + unsigned int count = 0; ::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.c_str(), &count); std::vector mats(modelAnimations, modelAnimations + count); diff --git a/include/Music.hpp b/include/Music.hpp index 896159d..6e5c756 100644 --- a/include/Music.hpp +++ b/include/Music.hpp @@ -38,7 +38,7 @@ class Music : public ::Music { other.ctxType = 0; other.ctxData = nullptr; other.looping = false; - other.sampleCount = 0; + other.frameCount = 0; other.stream = { 0 }; } @@ -50,7 +50,7 @@ class Music : public ::Music { } GETTERSETTER(::AudioStream, Stream, stream) - GETTERSETTER(unsigned int, SampleCount, sampleCount) + GETTERSETTER(unsigned int, FrameCount, frameCount) GETTERSETTER(bool, Looping, looping) GETTERSETTER(int, CtxType, ctxType) GETTERSETTER(void*, CtxData, ctxData) @@ -73,7 +73,7 @@ class Music : public ::Music { other.ctxType = 0; other.ctxData = nullptr; other.looping = false; - other.sampleCount = 0; + other.frameCount = 0; other.stream = { 0 }; return *this; @@ -130,7 +130,7 @@ class Music : public ::Music { * Check if music is playing */ inline bool IsPlaying() const { - return ::IsMusicPlaying(*this); + return ::IsMusicStreamPlaying(*this); } /** @@ -168,7 +168,7 @@ class Music : public ::Music { ctxType = music.ctxType; ctxData = music.ctxData; looping = music.looping; - sampleCount = music.sampleCount; + frameCount = music.frameCount; stream = music.stream; } }; diff --git a/include/Ray.hpp b/include/Ray.hpp index e34b660..576aea1 100644 --- a/include/Ray.hpp +++ b/include/Ray.hpp @@ -3,7 +3,7 @@ #include "./raylib.hpp" #include "./raylib-cpp-utils.hpp" -#include "./RayHitInfo.hpp" +#include "./RayCollision.hpp" namespace raylib { /** @@ -41,43 +41,42 @@ class Ray : public ::Ray { * Detect collision between ray and sphere */ inline bool CheckCollisionSphere(::Vector3 center, float radius) const { - return CheckCollisionRaySphere(*this, center, radius); + return GetRayCollisionSphere(*this, center, radius).hit; } - + /** - * Detect collision between ray and sphere, returns collision point + * Get collision information between ray and sphere */ - inline bool CheckCollisionSphere(::Vector3 center, float radius, - ::Vector3 *collisionPoint) const { - return CheckCollisionRaySphereEx(*this, center, radius, collisionPoint); + inline RayCollision GetCollisionSphere(::Vector3 center, float radius) const { + return GetRayCollisionSphere(*this, center, radius); } /** * Detect collision between ray and box */ inline bool CheckCollision(const ::BoundingBox& box) const { - return CheckCollisionRayBox(*this, box); + return GetRayCollisionBox(*this, box).hit; + } + + /** + * Get collision information between ray and box + */ + inline RayCollision GetCollision(const ::BoundingBox& box) const { + return GetRayCollisionBox(*this, box); } /** * Get collision info between ray and model */ - inline RayHitInfo GetCollision(const ::Model& model) const { - return GetCollisionRayModel(*this, model); + inline RayCollision GetCollision(const ::Model& model) const { + return GetRayCollisionModel(*this, model); } /** * Get collision info between ray and triangle */ - inline RayHitInfo GetCollisionTriangle(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const { - return GetCollisionRayTriangle(*this, p1, p2, p3); - } - - /** - * Get collision info between ray and ground plane (Y-normal plane) - */ - inline RayHitInfo GetCollisionGround(float groundHeight) const { - return GetCollisionRayGround(*this, groundHeight); + inline RayCollision GetCollisionTriangle(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const { + return GetRayCollisionTriangle(*this, p1, p2, p3); } private: diff --git a/include/RayCollision.hpp b/include/RayCollision.hpp new file mode 100644 index 0000000..99f4023 --- /dev/null +++ b/include/RayCollision.hpp @@ -0,0 +1,60 @@ +#ifndef RAYLIB_CPP_INCLUDE_RAYHITINFO_HPP_ +#define RAYLIB_CPP_INCLUDE_RAYHITINFO_HPP_ + +#include "./raylib.hpp" +#include "./raylib-cpp-utils.hpp" + +namespace raylib { +/** + * Raycast hit information + */ +class RayCollision : public ::RayCollision { + public: + RayCollision(const ::RayCollision& ray) { + set(ray); + } + + RayCollision(bool hit, float distance, ::Vector3 point, ::Vector3 normal) : ::RayCollision{hit, distance, point, normal} {} + + /** + * Get collision info between ray and mesh + */ + RayCollision(const ::Ray& ray, const ::Mesh& mesh, const ::Matrix& transform) { + set(::GetRayCollisionMesh(ray, mesh, transform)); + } + + /** + * Get collision info between ray and model + */ + RayCollision(const ::Ray& ray, const ::Model& model) { + set(::GetRayCollisionModel(ray, model)); + } + + /** + * Get collision info between ray and triangle + */ + RayCollision(const ::Ray& ray, ::Vector3 p1, ::Vector3 p2, ::Vector3 p3) { + set(::GetRayCollisionTriangle(ray, p1, p2, p3)); + } + + RayCollision& operator=(const ::RayCollision& ray) { + set(ray); + return *this; + } + + GETTERSETTER(bool, Hit, hit) + GETTERSETTER(float, Distance, distance) + GETTERSETTER(::Vector3, Position, point) + GETTERSETTER(::Vector3, Normal, normal) + + private: + inline void set(const ::RayCollision& ray) { + hit = ray.hit; + distance = ray.distance; + point = ray.point; + normal = ray.normal; + } +}; +} // namespace raylib + +#endif // RAYLIB_CPP_INCLUDE_RAYHITINFO_HPP_ diff --git a/include/RayHitInfo.hpp b/include/RayHitInfo.hpp deleted file mode 100644 index 1bbf16d..0000000 --- a/include/RayHitInfo.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef RAYLIB_CPP_INCLUDE_RAYHITINFO_HPP_ -#define RAYLIB_CPP_INCLUDE_RAYHITINFO_HPP_ - -#include "./raylib.hpp" -#include "./raylib-cpp-utils.hpp" - -namespace raylib { -/** - * Raycast hit information - */ -class RayHitInfo : public ::RayHitInfo { - public: - RayHitInfo(const ::RayHitInfo& ray) { - set(ray); - } - - RayHitInfo(bool hit, float distance, ::Vector3 position, ::Vector3 normal) : ::RayHitInfo{hit, distance, position, normal} {} - - /** - * Get collision info between ray and mesh - */ - RayHitInfo(const ::Ray& ray, const ::Mesh& mesh, const ::Matrix& transform) { - set(::GetCollisionRayMesh(ray, mesh, transform)); - } - - /** - * Get collision info between ray and model - */ - RayHitInfo(const ::Ray& ray, const ::Model& model) { - set(::GetCollisionRayModel(ray, model)); - } - - /** - * Get collision info between ray and triangle - */ - RayHitInfo(const ::Ray& ray, ::Vector3 p1, ::Vector3 p2, ::Vector3 p3) { - set(::GetCollisionRayTriangle(ray, p1, p2, p3)); - } - - /** - * Get collision info between ray and ground plane (Y-normal plane) - */ - RayHitInfo(const ::Ray& ray, float groundHeight) { - set(::GetCollisionRayGround(ray, groundHeight)); - } - - RayHitInfo& operator=(const ::RayHitInfo& ray) { - set(ray); - return *this; - } - - GETTERSETTER(bool, Hit, hit) - GETTERSETTER(float, Distance, distance) - GETTERSETTER(::Vector3, Position, position) - GETTERSETTER(::Vector3, Normal, normal) - - private: - inline void set(const ::RayHitInfo& ray) { - hit = ray.hit; - distance = ray.distance; - position = ray.position; - normal = ray.normal; - } -}; -} // namespace raylib - -#endif // RAYLIB_CPP_INCLUDE_RAYHITINFO_HPP_ diff --git a/include/Sound.hpp b/include/Sound.hpp index ab03208..527f7dd 100644 --- a/include/Sound.hpp +++ b/include/Sound.hpp @@ -23,7 +23,7 @@ class Sound : public ::Sound { Sound(Sound&& other) { set(other); - other.sampleCount = 0; + other.frameCount = 0; other.stream = { 0, 0, 0, 0 }; }; @@ -39,7 +39,7 @@ class Sound : public ::Sound { Unload(); } - GETTERSETTER(unsigned int, SampleCount, sampleCount) + GETTERSETTER(unsigned int, FrameCount, frameCount) GETTERSETTER(::AudioStream, Stream, stream) Sound& operator=(Sound&& other) { @@ -49,7 +49,7 @@ class Sound : public ::Sound { Unload(); set(other); - other.sampleCount = 0; + other.frameCount = 0; other.stream = { 0, 0, 0, 0 }; return *this; @@ -67,7 +67,7 @@ class Sound : public ::Sound { * Update sound buffer with new data, assuming it's the same sample count. */ inline Sound& Update(const void *data) { - ::UpdateSound(*this, data, static_cast(sampleCount)); + ::UpdateSound(*this, data, static_cast(frameCount)); return *this; } @@ -151,7 +151,7 @@ class Sound : public ::Sound { private: inline void set(const ::Sound& sound) { - sampleCount = sound.sampleCount; + frameCount = sound.frameCount; stream = sound.stream; } }; diff --git a/include/Texture.hpp b/include/Texture.hpp index 4021015..60d65a9 100644 --- a/include/Texture.hpp +++ b/include/Texture.hpp @@ -139,7 +139,7 @@ class Texture : public ::Texture { * Get pixel data from GPU texture and return an Image */ inline ::Image GetData() const { - return ::GetTextureData(*this); + return ::LoadImageFromTexture(*this); } /** diff --git a/include/Wave.hpp b/include/Wave.hpp index 5b716ff..de0270a 100644 --- a/include/Wave.hpp +++ b/include/Wave.hpp @@ -17,12 +17,12 @@ class Wave : public ::Wave { } Wave( - unsigned int sampleCount = 0, + unsigned int frameCount = 0, unsigned int sampleRate = 0, unsigned int sampleSize = 0, unsigned int channels = 0, void *data = nullptr - ) : ::Wave{sampleCount, sampleRate, sampleSize, channels, data} { } + ) : ::Wave{frameCount, sampleRate, sampleSize, channels, data} { } /** * Load wave data from file @@ -45,7 +45,7 @@ class Wave : public ::Wave { Wave(Wave&& other) { set(other); - other.sampleCount = 0; + other.frameCount = 0; other.sampleRate = 0; other.sampleSize = 0; other.channels = 0; @@ -59,7 +59,7 @@ class Wave : public ::Wave { Unload(); } - GETTERSETTER(unsigned int, SampleCount, sampleCount) + GETTERSETTER(unsigned int, FrameCount, frameCount) GETTERSETTER(unsigned int, SampleRate, sampleRate) GETTERSETTER(unsigned int, SampleSize, sampleSize) GETTERSETTER(unsigned int, Channels, channels) @@ -89,7 +89,7 @@ class Wave : public ::Wave { Unload(); set(other); - other.sampleCount = 0; + other.frameCount = 0; other.sampleRate = 0; other.sampleSize = 0; other.channels = 0; @@ -177,7 +177,7 @@ class Wave : public ::Wave { private: inline void set(const ::Wave& wave) { - sampleCount = wave.sampleCount; + frameCount = wave.frameCount; sampleRate = wave.sampleRate; sampleSize = wave.sampleSize; channels = wave.channels; diff --git a/include/raylib-cpp.hpp b/include/raylib-cpp.hpp index 96e7979..c05d745 100644 --- a/include/raylib-cpp.hpp +++ b/include/raylib-cpp.hpp @@ -49,7 +49,7 @@ #include "./Mouse.hpp" #include "./Music.hpp" #include "./Ray.hpp" -#include "./RayHitInfo.hpp" +#include "./RayCollision.hpp" #include "./Rectangle.hpp" #include "./RenderTexture.hpp" #include "./Shader.hpp" From d0a04603dcfc08ed2e5a3f8b15d8c5bf1ae472e9 Mon Sep 17 00:00:00 2001 From: Sophie Kirschner Date: Sun, 17 Oct 2021 21:57:59 +0300 Subject: [PATCH 2/6] More updates to sync with raylib master This commit fixes some additional issues revealed by trying to compile the examples. --- examples/core/core_random_values.cpp | 2 +- examples/models/models_first_person_maze.cpp | 2 +- examples/shapes/shapes_collision_area.cpp | 2 +- examples/textures/textures_bunnymark.cpp | 4 ++-- include/Color.hpp | 4 ++-- include/Font.hpp | 4 ++-- include/Material.hpp | 4 ++-- include/Music.hpp | 4 ++-- include/Rectangle.hpp | 6 +++--- include/RenderTexture.hpp | 8 ++++---- include/physac.hpp | 2 +- vendor/raylib | 2 +- 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/core/core_random_values.cpp b/examples/core/core_random_values.cpp index c4e0677..98338cf 100644 --- a/examples/core/core_random_values.cpp +++ b/examples/core/core_random_values.cpp @@ -47,7 +47,7 @@ int main() { DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON); - DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY); + DrawText(TextFormat("%i", randValue), 360, 180, 80, LIGHTGRAY); } EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/models/models_first_person_maze.cpp b/examples/models/models_first_person_maze.cpp index d3b473f..709b545 100644 --- a/examples/models/models_first_person_maze.cpp +++ b/examples/models/models_first_person_maze.cpp @@ -30,7 +30,7 @@ int main(void) // NOTE: By default each cube is mapped to one part of texture atlas raylib::Texture texture("resources/cubicmap_atlas.png"); // Load map texture - model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture + model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture // Get map image data to be used for collision detection Color *mapPixels = imMap.LoadColors(); diff --git a/examples/shapes/shapes_collision_area.cpp b/examples/shapes/shapes_collision_area.cpp index bd06a7d..94166ab 100644 --- a/examples/shapes/shapes_collision_area.cpp +++ b/examples/shapes/shapes_collision_area.cpp @@ -89,7 +89,7 @@ int main(void) DrawText("COLLISION!", GetScreenWidth()/2 - MeasureText("COLLISION!", 20)/2, screenUpperLimit/2 - 10, 20, BLACK); // Draw collision area - DrawText(FormatText("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK); + DrawText(TextFormat("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK); } DrawFPS(10, 10); diff --git a/examples/textures/textures_bunnymark.cpp b/examples/textures/textures_bunnymark.cpp index ae3264a..c7b123b 100644 --- a/examples/textures/textures_bunnymark.cpp +++ b/examples/textures/textures_bunnymark.cpp @@ -103,8 +103,8 @@ int main(void) } DrawRectangle(0, 0, screenWidth, 40, BLACK); - DrawText(FormatText("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN); - DrawText(FormatText("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); + DrawText(TextFormat("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN); + DrawText(TextFormat("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); DrawFPS(10, 10); } diff --git a/include/Color.hpp b/include/Color.hpp index 79ca649..e5b6ead 100644 --- a/include/Color.hpp +++ b/include/Color.hpp @@ -46,7 +46,7 @@ class Color : public ::Color { /** * Get Color structure from hexadecimal value */ - Color(int hexValue) { + Color(unsigned int hexValue) { set(::GetColor(hexValue)); } @@ -199,7 +199,7 @@ class Color : public ::Color { return *this; } - inline Color& DrawRectangleLines(::Rectangle rec, int lineThick) { + inline Color& DrawRectangleLines(::Rectangle rec, float lineThick) { ::DrawRectangleLinesEx(rec, lineThick, *this); return *this; } diff --git a/include/Font.hpp b/include/Font.hpp index 711bec4..9caf0c6 100644 --- a/include/Font.hpp +++ b/include/Font.hpp @@ -46,7 +46,7 @@ class Font : public ::Font { other.baseSize = 0; other.glyphCount = 0; other.glyphPadding = 0; - other.texture = { 0 }; + other.texture = {}; other.recs = nullptr; other.glyphs = nullptr; } @@ -84,7 +84,7 @@ class Font : public ::Font { other.baseSize = 0; other.glyphCount = 0; other.glyphPadding = 0; - other.texture = { 0 }; + other.texture = {}; other.recs = nullptr; other.glyphs = nullptr; diff --git a/include/Material.hpp b/include/Material.hpp index 4a77b9c..7b8c1c4 100644 --- a/include/Material.hpp +++ b/include/Material.hpp @@ -30,7 +30,7 @@ class Material : public ::Material { set(other); other.maps = nullptr; - other.shader = { 0 }; + other.shader = {}; } ~Material() { @@ -68,7 +68,7 @@ class Material : public ::Material { set(other); other.maps = nullptr; - other.shader = { 0 }; + other.shader = {}; return *this; } diff --git a/include/Music.hpp b/include/Music.hpp index 6e5c756..cee7856 100644 --- a/include/Music.hpp +++ b/include/Music.hpp @@ -39,7 +39,7 @@ class Music : public ::Music { other.ctxData = nullptr; other.looping = false; other.frameCount = 0; - other.stream = { 0 }; + other.stream = {}; } /** @@ -74,7 +74,7 @@ class Music : public ::Music { other.ctxData = nullptr; other.looping = false; other.frameCount = 0; - other.stream = { 0 }; + other.stream = {}; return *this; } diff --git a/include/Rectangle.hpp b/include/Rectangle.hpp index 437cf2e..4283894 100644 --- a/include/Rectangle.hpp +++ b/include/Rectangle.hpp @@ -81,7 +81,7 @@ class Rectangle : public ::Rectangle { return *this; } - inline Rectangle& DrawLines(::Color color, int lineThick) { + inline Rectangle& DrawLines(::Color color, float lineThick) { ::DrawRectangleLinesEx(*this, lineThick, color); return *this; } @@ -91,8 +91,8 @@ class Rectangle : public ::Rectangle { return *this; } - inline Rectangle& DrawRoundedLines(float roundness, int segments, int lineThick, - ::Color color) { + inline Rectangle& DrawRoundedLines(float roundness, int segments, + float lineThick, ::Color color) { ::DrawRectangleRoundedLines(*this, roundness, segments, lineThick, color); return *this; } diff --git a/include/RenderTexture.hpp b/include/RenderTexture.hpp index 7df17a8..3e03c2d 100644 --- a/include/RenderTexture.hpp +++ b/include/RenderTexture.hpp @@ -26,8 +26,8 @@ class RenderTexture : public ::RenderTexture { set(other); other.id = 0; - other.texture = { 0 }; - other.depth = { 0 }; + other.texture = {}; + other.depth = {}; } GETTERSETTER(unsigned int, Id, id) @@ -50,8 +50,8 @@ class RenderTexture : public ::RenderTexture { set(other); other.id = 0; - other.texture = { 0 }; - other.depth = { 0 }; + other.texture = {}; + other.depth = {}; return *this; } diff --git a/include/physac.hpp b/include/physac.hpp index 7a1be5c..8adbea8 100644 --- a/include/physac.hpp +++ b/include/physac.hpp @@ -7,7 +7,7 @@ #ifdef __cplusplus extern "C" { #endif -#include "physac.h" // NOLINT +#include "extras/physac.h" // NOLINT #ifdef __cplusplus } #endif diff --git a/vendor/raylib b/vendor/raylib index b6c8d34..a1db022 160000 --- a/vendor/raylib +++ b/vendor/raylib @@ -1 +1 @@ -Subproject commit b6c8d343dca2ef19c23c50975328a028124cf3cb +Subproject commit a1db0220a1582a568ce05257d1e5b602132602a1 From 1eab050c2f8987521a1de66955ff716fea4a8d22 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 4 Nov 2021 19:04:00 -0400 Subject: [PATCH 3/6] Update to raylib 4.0.0 --- vendor/raylib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/raylib b/vendor/raylib index a1db022..0851960 160000 --- a/vendor/raylib +++ b/vendor/raylib @@ -1 +1 @@ -Subproject commit a1db0220a1582a568ce05257d1e5b602132602a1 +Subproject commit 0851960397f02a477d80eda2239f90fae14dec64 From 340117f27994df1b44a04e535da4cc75281514da Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 4 Nov 2021 19:51:59 -0400 Subject: [PATCH 4/6] Updates for raylib 4.0.0 --- CHANGELOG.md | 1 + CMakeLists.txt | 2 +- include/Functions.hpp | 7 ------- include/Gamepad.hpp | 7 ------- include/Image.hpp | 20 ++++++++++++++++++++ include/Mesh.hpp | 20 ++++++++++++++++++-- include/Music.hpp | 8 ++++++++ include/Texture.hpp | 7 +++++++ package.json | 2 +- projects/CMake/CMakeLists.txt | 2 +- 10 files changed, 57 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 578c0ad..a97b318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [x.x.x] - xxxx-xx-xx ### Changes +- Update to raylib 4.0.0 - For tests, replaced catch.hpp with `assert()` calls - Added assignment operators for objects ([#142](https://github.com/RobLoach/raylib-cpp/pull/142) by [@marciejewiczow](https://github.com/maciejewiczow)) - Replaced `NULL` with `nullptr` diff --git a/CMakeLists.txt b/CMakeLists.txt index 222caa6..d03283a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.11) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") project (raylib-cpp - VERSION 3.7.0 + VERSION 4.0.0 DESCRIPTION "raylib-cpp C++ Object Oriented Wrapper for raylib" HOMEPAGE_URL "https://github.com/robloach/raylib-cpp" LANGUAGES C CXX) diff --git a/include/Functions.hpp b/include/Functions.hpp index b1efac3..301812c 100644 --- a/include/Functions.hpp +++ b/include/Functions.hpp @@ -189,13 +189,6 @@ RLCPPAPI inline void OpenURL(const std::string& url) { return ::OpenURL(url.c_str()); } -/** - * Check gamepad name (if available) - */ -RLCPPAPI inline bool IsGamepadName(int gamepad, const std::string& name) { - return ::IsGamepadName(gamepad, name.c_str()); -} - /** * Update camera depending on selected mode */ diff --git a/include/Gamepad.hpp b/include/Gamepad.hpp index 1781992..b92d353 100644 --- a/include/Gamepad.hpp +++ b/include/Gamepad.hpp @@ -45,13 +45,6 @@ class Gamepad { return ::IsGamepadAvailable(number); } - /** - * Check gamepad name (if available) - */ - inline bool IsName(const std::string& name) const { - return ::IsGamepadName(number, name.c_str()); - } - /** * Return gamepad internal name id */ diff --git a/include/Image.hpp b/include/Image.hpp index 8efe2d7..ce290a5 100644 --- a/include/Image.hpp +++ b/include/Image.hpp @@ -42,6 +42,10 @@ class Image : public ::Image { set(::GenImageColor(width, height, color)); } + Image(const std::string& text, int fontSize, ::Color color = {255, 255, 255, 255}) { + set(::ImageText(text.c_str(), fontSize, color)); + } + Image(const ::Font& font, const std::string& text, float fontSize, float spacing, ::Color tint = {255, 255, 255, 255}) { set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint)); @@ -279,6 +283,22 @@ class Image : public ::Image { return *this; } + /** + * Clear alpha channel to desired color + */ + inline Image& AlphaClear(::Color color, float threshold) { + ::ImageAlphaClear(this, color, threshold); + return *this; + } + + /** + * Apply alpha mask to image + */ + inline Image& AlphaMask(::Color color, const ::Image& alphaMask) { + ::ImageAlphaMask(this, alphaMask); + return *this; + } + /** * Premultiply alpha channel */ diff --git a/include/Mesh.hpp b/include/Mesh.hpp index 97aa46b..0000388 100644 --- a/include/Mesh.hpp +++ b/include/Mesh.hpp @@ -19,7 +19,23 @@ class Mesh : public ::Mesh { set(mesh); } - Mesh(int vertexCount, int triangleCount) : ::Mesh{vertexCount, triangleCount} {} + Mesh(int vertexCount, int triangleCount) : ::Mesh{ + vertexCount, + triangleCount, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + 0, + nullptr + } {} /** * Load meshes from model file @@ -133,7 +149,7 @@ class Mesh : public ::Mesh { GETTERSETTER(unsigned short *, Indices, indices) // NOLINT GETTERSETTER(float *, AnimVertices, animVertices) GETTERSETTER(float *, AnimNormals, animNormals) - GETTERSETTER(int *, BoneIds, boneIds) + GETTERSETTER(unsigned char *, BoneIds, boneIds) GETTERSETTER(float *, BoneWeights, boneWeights) GETTERSETTER(unsigned int, VaoId, vaoId) GETTERSETTER(unsigned int *, VboId, vboId) diff --git a/include/Music.hpp b/include/Music.hpp index cee7856..caf0f39 100644 --- a/include/Music.hpp +++ b/include/Music.hpp @@ -126,6 +126,14 @@ class Music : public ::Music { return *this; } + /** + * Seek music to a position (in seconds) + */ + inline Music& Seek(float position) { + SeekMusicStream(*this, position); + return *this; + } + /** * Check if music is playing */ diff --git a/include/Texture.hpp b/include/Texture.hpp index 60d65a9..481c2a3 100644 --- a/include/Texture.hpp +++ b/include/Texture.hpp @@ -255,6 +255,13 @@ class Texture : public ::Texture { return *this; } + /** + * Set texture and rectangle to be used on shapes drawing. + */ + inline Texture& SetShapes(const ::Rectangle& source) { + ::SetShapesTexture(*this, source); + } + private: inline void set(const ::Texture& texture) { id = texture.id; diff --git a/package.json b/package.json index 1e22c1a..fc548d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "raylib-cpp", - "version": "3.7.0", + "version": "4.0.0", "description": "raylib-cpp: C++ Object-Oriented Wrapper for raylib", "homepage": "https://github.com/robloach/raylib-cpp", "bugs": { diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index ff97ad2..94d1d52 100644 --- a/projects/CMake/CMakeLists.txt +++ b/projects/CMake/CMakeLists.txt @@ -8,7 +8,7 @@ if (NOT raylib_FOUND) FetchContent_Declare( raylib GIT_REPOSITORY https://github.com/raysan5/raylib.git - GIT_TAG b6c8d343dca2ef19c23c50975328a028124cf3cb + GIT_TAG 0851960397f02a477d80eda2239f90fae14dec64 ) FetchContent_GetProperties(raylib) if (NOT raylib_POPULATED) # Have we downloaded raylib yet? From da7a4725621a51fbbaf85bf5d8ab0e6cb57139ac Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 4 Nov 2021 20:23:49 -0400 Subject: [PATCH 5/6] Fix tests --- include/Image.hpp | 10 +--------- include/Texture.hpp | 1 + tests/CMakeLists.txt | 3 +++ tests/raylib_test.cpp | 3 ++- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/Image.hpp b/include/Image.hpp index ce290a5..8c93efb 100644 --- a/include/Image.hpp +++ b/include/Image.hpp @@ -267,14 +267,6 @@ class Image : public ::Image { return *this; } - /** - * Apply alpha mask to image - */ - inline Image& AlphaMask(const ::Image& alphaMask) { - ::ImageAlphaMask(this, alphaMask); - return *this; - } - /** * Crop image depending on alpha value */ @@ -294,7 +286,7 @@ class Image : public ::Image { /** * Apply alpha mask to image */ - inline Image& AlphaMask(::Color color, const ::Image& alphaMask) { + inline Image& AlphaMask(const ::Image& alphaMask) { ::ImageAlphaMask(this, alphaMask); return *this; } diff --git a/include/Texture.hpp b/include/Texture.hpp index 481c2a3..8a52c5b 100644 --- a/include/Texture.hpp +++ b/include/Texture.hpp @@ -260,6 +260,7 @@ class Texture : public ::Texture { */ inline Texture& SetShapes(const ::Rectangle& source) { ::SetShapesTexture(*this, source); + return *this; } private: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b314947..b1fc96d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,3 +14,6 @@ target_link_libraries(raylib_test raylib-cpp raylib) # Test add_test(NAME raylib_test COMMAND raylib_test) + +# Copy all the resources +file(COPY resources/ DESTINATION "resources/") diff --git a/tests/raylib_test.cpp b/tests/raylib_test.cpp index 228fc41..b17efd3 100644 --- a/tests/raylib_test.cpp +++ b/tests/raylib_test.cpp @@ -26,7 +26,8 @@ int main() { // Math raylib::Vector2 direction(50, 50); raylib::Vector2 newDirection = direction.Rotate(30); - assert((int)newDirection.x == 18); + std::cout << "Out: " << newDirection.x << std::endl; + assert((int)newDirection.x == 57); // raylib::GetDirectoryFiles() std::vector files = raylib::GetDirectoryFiles(::GetWorkingDirectory()); From 0213c8f8966a9c9513aa4865371db3c22ff8dc66 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 4 Nov 2021 21:51:36 -0400 Subject: [PATCH 6/6] v4.0.0 --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a97b318..814b3f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [x.x.x] - xxxx-xx-xx +## [4.0.0] - 2021-11-04 ### Changes -- Update to raylib 4.0.0 +- Update to [raylib 4.0.0](https://github.com/raysan5/raylib/releases/tag/4.0.0) - For tests, replaced catch.hpp with `assert()` calls - Added assignment operators for objects ([#142](https://github.com/RobLoach/raylib-cpp/pull/142) by [@marciejewiczow](https://github.com/maciejewiczow)) - Replaced `NULL` with `nullptr`