From 0c7c3a6c0eff90b5364d6421279b1e24a4960621 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 9 Nov 2024 17:52:19 -0500 Subject: [PATCH 1/2] Remove duplicate operator statements --- examples/CMakeLists.txt | 2 +- include/AudioStream.hpp | 6 +- include/AutomationEventList.hpp | 6 +- include/Font.hpp | 10 ++-- include/Image.hpp | 12 ++-- include/Material.hpp | 2 +- include/MeshUnmanaged.hpp | 6 ++ include/Model.hpp | 6 +- include/Music.hpp | 6 +- include/RenderTexture.hpp | 2 +- include/ShaderUnmanaged.hpp | 2 +- include/Sound.hpp | 6 +- include/TextureUnmanaged.hpp | 8 +-- include/Vector2.hpp | 90 ---------------------------- include/Vector3.hpp | 87 --------------------------- include/Vector4.hpp | 2 - include/Wave.hpp | 6 +- package.json | 2 +- projects/CMake/CMakeLists.txt | 4 +- projects/Doxygen/doxygen-awesome-css | 2 +- 20 files changed, 47 insertions(+), 220 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 34303298..6c2c8aaa 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -15,7 +15,7 @@ if (NOT raylib_FOUND) FetchContent_Declare( raylib GIT_REPOSITORY https://github.com/raysan5/raylib.git - GIT_TAG 9b3d019 + GIT_TAG d8feef5 GIT_SHALLOW 1 ) FetchContent_GetProperties(raylib) diff --git a/include/AudioStream.hpp b/include/AudioStream.hpp index d41aa171..5b6217aa 100644 --- a/include/AudioStream.hpp +++ b/include/AudioStream.hpp @@ -88,7 +88,7 @@ class AudioStream : public ::AudioStream { * Unload audio stream and free memory */ void Unload() { - if (IsReady()) { + if (IsValid()) { ::UnloadAudioStream(*this); } } @@ -182,7 +182,7 @@ class AudioStream : public ::AudioStream { /** * Retrieve whether or not the audio stream is ready. */ - bool IsReady() const { return ::IsAudioStreamReady(*this); } + bool IsValid() const { return ::IsAudioStreamValid(*this); } /** * Load audio stream (to stream raw audio pcm data) @@ -192,7 +192,7 @@ class AudioStream : public ::AudioStream { void Load(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) { Unload(); set(::LoadAudioStream(SampleRate, SampleSize, Channels)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load audio stream"); } } diff --git a/include/AutomationEventList.hpp b/include/AutomationEventList.hpp index 6bdb0991..1c71560b 100644 --- a/include/AutomationEventList.hpp +++ b/include/AutomationEventList.hpp @@ -71,7 +71,7 @@ class AutomationEventList : public ::AutomationEventList { void Load(const char* fileName) { Unload(); set(::LoadAutomationEventList(fileName)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load automation event list"); } } @@ -80,7 +80,7 @@ class AutomationEventList : public ::AutomationEventList { * Update audio stream buffers with data */ void Unload() { - if (!IsReady()) { + if (!IsValid()) { return; } @@ -96,7 +96,7 @@ class AutomationEventList : public ::AutomationEventList { #endif } - bool IsReady() { return events != nullptr; } + bool IsValid() { return events != nullptr; } bool Export(const char* fileName) { return ::ExportAutomationEventList(*this, fileName); } diff --git a/include/Font.hpp b/include/Font.hpp index 4a62567c..2bcda420 100644 --- a/include/Font.hpp +++ b/include/Font.hpp @@ -158,7 +158,7 @@ class Font : public ::Font { */ void Load(const std::string& fileName) { set(::LoadFont(fileName.c_str())); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Font with from file: " + fileName); } } @@ -175,14 +175,14 @@ class Font : public ::Font { */ void Load(const std::string& fileName, int fontSize, int* fontChars, int charCount) { set(::LoadFontEx(fileName.c_str(), fontSize, fontChars, charCount)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Font with from file with font size: " + fileName); } } void Load(const ::Image& image, ::Color key, int firstChar) { set(::LoadFontFromImage(image, key, firstChar)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Font with from image"); } } @@ -195,7 +195,7 @@ class Font : public ::Font { int* fontChars, int charsCount) { set(::LoadFontFromMemory(fileType.c_str(), fileData, dataSize, fontSize, fontChars, charsCount)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Font " + fileType + " with from file data"); } } @@ -203,7 +203,7 @@ class Font : public ::Font { /** * Returns if the font is ready to be used. */ - bool IsReady() const { return ::IsFontReady(*this); } + bool IsValid() const { return ::IsFontValid(*this); } /** * Draw text using font and additional parameters. diff --git a/include/Image.hpp b/include/Image.hpp index c40d3c24..329bc77e 100644 --- a/include/Image.hpp +++ b/include/Image.hpp @@ -208,7 +208,7 @@ class Image : public ::Image { */ void Load(const std::string& fileName) { set(::LoadImage(fileName.c_str())); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Image from file: " + fileName); } } @@ -222,7 +222,7 @@ class Image : public ::Image { */ void Load(const std::string& fileName, int width, int height, int format, int headerSize) { set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Image from file: " + fileName); } } @@ -236,7 +236,7 @@ class Image : public ::Image { */ void Load(const std::string& fileName, int* frames) { set(::LoadImageAnim(fileName.c_str(), frames)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Image from file: " + fileName); } } @@ -250,7 +250,7 @@ class Image : public ::Image { */ void Load(const std::string& fileType, const unsigned char* fileData, int dataSize) { set(::LoadImageFromMemory(fileType.c_str(), fileData, dataSize)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Image data with file type: " + fileType); } } @@ -264,7 +264,7 @@ class Image : public ::Image { */ void Load(const ::Texture2D& texture) { set(::LoadImageFromTexture(texture)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Image from texture."); } } @@ -728,7 +728,7 @@ class Image : public ::Image { * * @return True or false depending on whether the Image has been loaded. */ - bool IsReady() const { return ::IsImageReady(*this); } + bool IsValid() const { return ::IsImageValid(*this); } protected: void set(const ::Image& image) { data = image.data; diff --git a/include/Material.hpp b/include/Material.hpp index f3ca4521..36fac358 100644 --- a/include/Material.hpp +++ b/include/Material.hpp @@ -104,7 +104,7 @@ class Material : public ::Material { /** * Check if material is ready */ - bool IsReady() const { return ::IsMaterialReady(*this); } + bool IsValid() const { return ::IsMaterialValid(*this); } protected: void set(const ::Material& material) { shader = material.shader; diff --git a/include/MeshUnmanaged.hpp b/include/MeshUnmanaged.hpp index 15e09fd4..4a54ba1c 100644 --- a/include/MeshUnmanaged.hpp +++ b/include/MeshUnmanaged.hpp @@ -210,6 +210,12 @@ class MeshUnmanaged : public ::Mesh { * Load model from generated mesh */ operator raylib::Model() { return ::LoadModelFromMesh(*this); } + + /** + * Returns whether or not the Mesh is valid. + */ + bool IsValid() { return ::IsModelValid(*this); } + protected: void set(const ::Mesh& mesh) { vertexCount = mesh.vertexCount; diff --git a/include/Model.hpp b/include/Model.hpp index 8962f0f7..eb412b11 100644 --- a/include/Model.hpp +++ b/include/Model.hpp @@ -183,7 +183,7 @@ class Model : public ::Model { /** * Determines whether or not the Model has data in it. */ - bool IsReady() const { return ::IsModelReady(*this); } + bool IsValid() const { return ::IsModelValid(*this); } /** * Loads a Model from the given file. @@ -192,7 +192,7 @@ class Model : public ::Model { */ void Load(const std::string& fileName) { set(::LoadModel(fileName.c_str())); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Model from " + fileName); } } @@ -204,7 +204,7 @@ class Model : public ::Model { */ void Load(const ::Mesh& mesh) { set(::LoadModelFromMesh(mesh)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Model from Mesh"); } } diff --git a/include/Music.hpp b/include/Music.hpp index 897c4e89..1a90df6a 100644 --- a/include/Music.hpp +++ b/include/Music.hpp @@ -183,7 +183,7 @@ class Music : public ::Music { */ void Load(const std::string& fileName) { set(::LoadMusicStream(fileName.c_str())); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException(TextFormat("Failed to load Music from file: %s", fileName.c_str())); } } @@ -195,7 +195,7 @@ class Music : public ::Music { */ void Load(const std::string& fileType, unsigned char* data, int dataSize) { set(::LoadMusicStreamFromMemory(fileType.c_str(), data, dataSize)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException(TextFormat("Failed to load Music from %s file dat", fileType.c_str())); } } @@ -205,7 +205,7 @@ class Music : public ::Music { * * @return True or false depending on whether the Music has been loaded. */ - bool IsReady() const { return ::IsMusicReady(*this); } + bool IsValid() const { return ::IsMusicValid(*this); } protected: void set(const ::Music& music) { stream = music.stream; diff --git a/include/RenderTexture.hpp b/include/RenderTexture.hpp index c8182c03..9adbb79f 100644 --- a/include/RenderTexture.hpp +++ b/include/RenderTexture.hpp @@ -103,7 +103,7 @@ class RenderTexture : public ::RenderTexture { /** * Retrieves whether or not the render texture is ready. */ - bool IsReady() const { return ::IsRenderTextureReady(*this); } + bool IsValid() const { return ::IsRenderTextureValid(*this); } protected: void set(const ::RenderTexture& renderTexture) { id = renderTexture.id; diff --git a/include/ShaderUnmanaged.hpp b/include/ShaderUnmanaged.hpp index 628cda27..3904acc1 100644 --- a/include/ShaderUnmanaged.hpp +++ b/include/ShaderUnmanaged.hpp @@ -133,7 +133,7 @@ class ShaderUnmanaged : public ::Shader { /** * Retrieves whether or not the shader is ready. */ - bool IsReady() const { return id != 0 && locs != nullptr; } + bool IsValid() const { return ::IsShaderValid(*this); } protected: void set(const ::Shader& shader) { id = shader.id; diff --git a/include/Sound.hpp b/include/Sound.hpp index f7b0ec01..a74f46e9 100644 --- a/include/Sound.hpp +++ b/include/Sound.hpp @@ -164,7 +164,7 @@ class Sound : public ::Sound { */ void Load(const std::string& fileName) { set(::LoadSound(fileName.c_str())); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Sound from file"); } } @@ -176,7 +176,7 @@ class Sound : public ::Sound { */ void Load(const ::Wave& wave) { set(::LoadSoundFromWave(wave)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Wave"); } } @@ -186,7 +186,7 @@ class Sound : public ::Sound { * * @return True or false depending on whether the Sound buffer is loaded. */ - bool IsReady() const { return ::IsSoundReady(*this); } + bool IsValid() const { return ::IsSoundValid(*this); } protected: void set(const ::Sound& sound) { frameCount = sound.frameCount; diff --git a/include/TextureUnmanaged.hpp b/include/TextureUnmanaged.hpp index 241fed50..a7ce9aaa 100644 --- a/include/TextureUnmanaged.hpp +++ b/include/TextureUnmanaged.hpp @@ -96,7 +96,7 @@ class TextureUnmanaged : public ::Texture { */ void Load(const ::Image& image) { set(::LoadTextureFromImage(image)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Texture from Image"); } } @@ -106,7 +106,7 @@ class TextureUnmanaged : public ::Texture { */ void Load(const ::Image& image, int layoutType) { set(::LoadTextureCubemap(image, layoutType)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Texture from Cubemap"); } } @@ -116,7 +116,7 @@ class TextureUnmanaged : public ::Texture { */ void Load(const std::string& fileName) { set(::LoadTexture(fileName.c_str())); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Texture from file: " + fileName); } } @@ -319,7 +319,7 @@ class TextureUnmanaged : public ::Texture { * * @return True or false depending on whether the Texture has data. */ - bool IsReady() const { return id != 0; } + bool IsValid() const { return IsTextureValid(*this); } protected: void set(const ::Texture& texture) { id = texture.id; diff --git a/include/Vector2.hpp b/include/Vector2.hpp index 1834225b..20cfd431 100644 --- a/include/Vector2.hpp +++ b/include/Vector2.hpp @@ -54,126 +54,36 @@ class Vector2 : public ::Vector2 { */ Vector2 Add(const ::Vector2& vector2) const { return Vector2Add(*this, vector2); } - /** - * Add two vectors (v1 + v2) - */ - Vector2 operator+(const ::Vector2& vector2) const { return Vector2Add(*this, vector2); } - - /** - * Add two vectors (v1 + v2) - */ - Vector2& operator+=(const ::Vector2& vector2) { - set(Vector2Add(*this, vector2)); - - return *this; - } - /** * Subtract two vectors (v1 - v2) */ Vector2 Subtract(const ::Vector2& vector2) const { return Vector2Subtract(*this, vector2); } - /** - * Subtract two vectors (v1 - v2) - */ - Vector2 operator-(const ::Vector2& vector2) const { return Vector2Subtract(*this, vector2); } - - /** - * Subtract two vectors (v1 - v2) - */ - Vector2& operator-=(const ::Vector2& vector2) { - set(Vector2Subtract(*this, vector2)); - - return *this; - } - /** * Negate vector */ Vector2 Negate() const { return Vector2Negate(*this); } - /** - * Negate vector - */ - Vector2 operator-() const { return Vector2Negate(*this); } - /** * Multiply vector by vector */ Vector2 Multiply(const ::Vector2& vector2) const { return Vector2Multiply(*this, vector2); } - /** - * Multiply vector by vector - */ - Vector2 operator*(const ::Vector2& vector2) const { return Vector2Multiply(*this, vector2); } - - /** - * Multiply vector by vector - */ - Vector2& operator*=(const ::Vector2& vector2) { - set(Vector2Multiply(*this, vector2)); - - return *this; - } - /** * Scale vector (multiply by value) */ Vector2 Scale(const float scale) const { return Vector2Scale(*this, scale); } - /** - * Scale vector (multiply by value) - */ - Vector2 operator*(const float scale) const { return Vector2Scale(*this, scale); } - - /** - * Scale vector (multiply by value) - */ - Vector2& operator*=(const float scale) { - set(Vector2Scale(*this, scale)); - - return *this; - } - /** * Divide vector by vector */ Vector2 Divide(const ::Vector2& vector2) const { return Vector2Divide(*this, vector2); } - /** - * Divide vector by vector - */ - Vector2 operator/(const ::Vector2& vector2) const { return Vector2Divide(*this, vector2); } - - /** - * Divide vector by vector - */ - Vector2& operator/=(const ::Vector2& vector2) { - set(Vector2Divide(*this, vector2)); - - return *this; - } - /** * Divide vector by value */ Vector2 Divide(const float div) const { return ::Vector2{x / div, y / div}; } - /** - * Divide vector by value - */ - Vector2 operator/(const float div) const { return Divide(div); } - - /** - * Divide vector by value - */ - Vector2& operator/=(const float div) { - this->x /= div; - this->y /= div; - - return *this; - } - /** * Normalize provided vector */ diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 2c51d99e..19f4f117 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -49,123 +49,36 @@ class Vector3 : public ::Vector3 { */ Vector3 Add(const ::Vector3& vector3) const { return Vector3Add(*this, vector3); } - /** - * Add two vectors - */ - Vector3 operator+(const ::Vector3& vector3) const { return Vector3Add(*this, vector3); } - - Vector3& operator+=(const ::Vector3& vector3) { - set(Vector3Add(*this, vector3)); - - return *this; - } - /** * Subtract two vectors. */ Vector3 Subtract(const ::Vector3& vector3) const { return Vector3Subtract(*this, vector3); } - /** - * Subtract two vectors. - */ - Vector3 operator-(const ::Vector3& vector3) const { return Vector3Subtract(*this, vector3); } - - Vector3& operator-=(const ::Vector3& vector3) { - set(Vector3Subtract(*this, vector3)); - - return *this; - } - /** * Negate provided vector (invert direction) */ Vector3 Negate() const { return Vector3Negate(*this); } - /** - * Negate provided vector (invert direction) - */ - Vector3 operator-() const { return Vector3Negate(*this); } - /** * Multiply vector by vector */ Vector3 Multiply(const ::Vector3& vector3) const { return Vector3Multiply(*this, vector3); } - /** - * Multiply vector by vector - */ - Vector3 operator*(const ::Vector3& vector3) const { return Vector3Multiply(*this, vector3); } - - /** - * Multiply vector by vector - */ - Vector3& operator*=(const ::Vector3& vector3) { - set(Vector3Multiply(*this, vector3)); - - return *this; - } - /** * Multiply vector by scalar */ Vector3 Scale(const float scaler) const { return Vector3Scale(*this, scaler); } - /** - * Multiply vector by scalar - */ - Vector3 operator*(const float scaler) const { return Vector3Scale(*this, scaler); } - - /** - * Multiply vector by scalar - */ - Vector3& operator*=(const float scaler) { - set(Vector3Scale(*this, scaler)); - - return *this; - } - /** * Divide vector by vector */ Vector3 Divide(const ::Vector3& vector3) const { return Vector3Divide(*this, vector3); } - /** - * Divide vector by vector - */ - Vector3 operator/(const ::Vector3& vector3) const { return Vector3Divide(*this, vector3); } - - /** - * Divide vector by vector - */ - Vector3& operator/=(const ::Vector3& vector3) { - x /= vector3.x; - y /= vector3.y; - z /= vector3.z; - - return *this; - } - /** * Divide a vector by a value. */ Vector3 Divide(const float div) const { return ::Vector3{x / div, y / div, z / div}; } - /** - * Divide a vector by a value. - */ - Vector3 operator/(const float div) const { return Divide(div); } - - /** - * Divide a vector by a value. - */ - Vector3& operator/=(const float div) { - x /= div; - y /= div; - z /= div; - - return *this; - } - /** * Calculate vector length */ diff --git a/include/Vector4.hpp b/include/Vector4.hpp index 2cc66b18..16f06d5c 100644 --- a/include/Vector4.hpp +++ b/include/Vector4.hpp @@ -56,8 +56,6 @@ class Vector4 : public ::Vector4 { #ifndef RAYLIB_CPP_NO_MATH Vector4 Multiply(const ::Vector4& vector4) const { return QuaternionMultiply(*this, vector4); } - Vector4 operator*(const ::Vector4& vector4) const { return QuaternionMultiply(*this, vector4); } - Vector4 Lerp(const ::Vector4& vector4, float amount) const { return QuaternionLerp(*this, vector4, amount); } Vector4 Nlerp(const ::Vector4& vector4, float amount) const { return QuaternionNlerp(*this, vector4, amount); } diff --git a/include/Wave.hpp b/include/Wave.hpp index ca37f7b7..62c88c73 100644 --- a/include/Wave.hpp +++ b/include/Wave.hpp @@ -172,7 +172,7 @@ class Wave : public ::Wave { */ void Load(const std::string& fileName) { set(::LoadWave(fileName.c_str())); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Wave from file: " + fileName); } } @@ -184,7 +184,7 @@ class Wave : public ::Wave { */ void Load(const std::string& fileType, const unsigned char* fileData, int dataSize) { set(::LoadWaveFromMemory(fileType.c_str(), fileData, dataSize)); - if (!IsReady()) { + if (!IsValid()) { throw RaylibException("Failed to load Wave from file data of type: " + fileType); } } @@ -194,7 +194,7 @@ class Wave : public ::Wave { * * @return True or false depending on whether the wave data has been loaded. */ - bool IsReady() const { return ::IsWaveReady(*this); } + bool IsValid() const { return ::IsWaveValid(*this); } protected: void set(const ::Wave& wave) { frameCount = wave.frameCount; diff --git a/package.json b/package.json index 3f9b0d75..615102d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "raylib-cpp", - "version": "5.0.2", + "version": "5.5.0", "description": "raylib-cpp: C++ Object-Oriented Wrapper for raylib", "main": "index.js", "private": true, diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index bef41ebe..e7d9836c 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 9b3d019 + GIT_TAG d8feef5 GIT_SHALLOW 1 ) FetchContent_MakeAvailable(raylib) @@ -18,7 +18,7 @@ endif() find_package(raylib_cpp QUIET) if (NOT raylib_cpp_FOUND) if (NOT DEFINED RAYLIB_CPP_VERSION) - set(RAYLIB_CPP_VERSION v5.0.2) + set(RAYLIB_CPP_VERSION next) endif() include(FetchContent) FetchContent_Declare( diff --git a/projects/Doxygen/doxygen-awesome-css b/projects/Doxygen/doxygen-awesome-css index 40e9b25b..568f56cd 160000 --- a/projects/Doxygen/doxygen-awesome-css +++ b/projects/Doxygen/doxygen-awesome-css @@ -1 +1 @@ -Subproject commit 40e9b25b6174dd3b472d8868f63323a870dfeeb8 +Subproject commit 568f56cde6ac78b6dfcc14acd380b2e745c301ea From 51fd49e749e284b6ae87f6d8b6e38ded9ab935e7 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 14 Nov 2024 13:12:48 -0500 Subject: [PATCH 2/2] Make raylib not introduce the operators --- examples/CMakeLists.txt | 2 +- include/Vector2.hpp | 91 +++++++++++++++++++++++++++++++++++ include/Vector3.hpp | 87 +++++++++++++++++++++++++++++++++ include/Vector4.hpp | 2 + include/raymath.hpp | 1 + projects/CMake/CMakeLists.txt | 2 +- tests/raylib_cpp_test.cpp | 4 +- 7 files changed, 185 insertions(+), 4 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6c2c8aaa..f074f093 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -15,7 +15,7 @@ if (NOT raylib_FOUND) FetchContent_Declare( raylib GIT_REPOSITORY https://github.com/raysan5/raylib.git - GIT_TAG d8feef5 + GIT_TAG 5e6cdf3 GIT_SHALLOW 1 ) FetchContent_GetProperties(raylib) diff --git a/include/Vector2.hpp b/include/Vector2.hpp index 20cfd431..a42eb842 100644 --- a/include/Vector2.hpp +++ b/include/Vector2.hpp @@ -54,36 +54,127 @@ class Vector2 : public ::Vector2 { */ Vector2 Add(const ::Vector2& vector2) const { return Vector2Add(*this, vector2); } + /** + * Add two vectors (v1 + v2) + */ + Vector2 operator+(const ::Vector2& vector2) const { return Vector2Add(*this, vector2); } + + /** + * Add two vectors (v1 + v2) + */ + Vector2& operator+=(const ::Vector2& vector2) { + set(Vector2Add(*this, vector2)); + + return *this; + } + /** * Subtract two vectors (v1 - v2) */ Vector2 Subtract(const ::Vector2& vector2) const { return Vector2Subtract(*this, vector2); } + /** + * Subtract two vectors (v1 - v2) + */ + Vector2 operator-(const ::Vector2& vector2) const { return Vector2Subtract(*this, vector2); } + + /** + * Subtract two vectors (v1 - v2) + */ + Vector2& operator-=(const ::Vector2& vector2) { + set(Vector2Subtract(*this, vector2)); + + return *this; + } + /** * Negate vector */ Vector2 Negate() const { return Vector2Negate(*this); } + /** + * Negate vector + */ + Vector2 operator-() const { return Vector2Negate(*this); } + /** * Multiply vector by vector */ Vector2 Multiply(const ::Vector2& vector2) const { return Vector2Multiply(*this, vector2); } + /** + * Multiply vector by vector + */ + Vector2 operator*(const ::Vector2& vector2) const { return Vector2Multiply(*this, vector2); } + + /** + * Multiply vector by vector + */ + Vector2& operator*=(const ::Vector2& vector2) { + set(Vector2Multiply(*this, vector2)); + + return *this; + } + /** * Scale vector (multiply by value) */ Vector2 Scale(const float scale) const { return Vector2Scale(*this, scale); } + /** + * Scale vector (multiply by value) + */ + Vector2 operator*(const float scale) const { return Vector2Scale(*this, scale); } + + /** + * Scale vector (multiply by value) + */ + Vector2& operator*=(const float scale) { + set(Vector2Scale(*this, scale)); + + return *this; + } + /** * Divide vector by vector */ Vector2 Divide(const ::Vector2& vector2) const { return Vector2Divide(*this, vector2); } + + /** + * Divide vector by vector + */ + Vector2 operator/(const ::Vector2& vector2) const { return Vector2Divide(*this, vector2); } + + /** + * Divide vector by vector + */ + Vector2& operator/=(const ::Vector2& vector2) { + set(Vector2Divide(*this, vector2)); + + return *this; + } + /** * Divide vector by value */ Vector2 Divide(const float div) const { return ::Vector2{x / div, y / div}; } + /** + * Divide vector by value + */ + Vector2 operator/(const float div) const { return Divide(div); } + + /** + * Divide vector by value + */ + Vector2& operator/=(const float div) { + this->x /= div; + this->y /= div; + + return *this; + } + /** * Normalize provided vector */ diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 19f4f117..2c51d99e 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -49,36 +49,123 @@ class Vector3 : public ::Vector3 { */ Vector3 Add(const ::Vector3& vector3) const { return Vector3Add(*this, vector3); } + /** + * Add two vectors + */ + Vector3 operator+(const ::Vector3& vector3) const { return Vector3Add(*this, vector3); } + + Vector3& operator+=(const ::Vector3& vector3) { + set(Vector3Add(*this, vector3)); + + return *this; + } + /** * Subtract two vectors. */ Vector3 Subtract(const ::Vector3& vector3) const { return Vector3Subtract(*this, vector3); } + /** + * Subtract two vectors. + */ + Vector3 operator-(const ::Vector3& vector3) const { return Vector3Subtract(*this, vector3); } + + Vector3& operator-=(const ::Vector3& vector3) { + set(Vector3Subtract(*this, vector3)); + + return *this; + } + /** * Negate provided vector (invert direction) */ Vector3 Negate() const { return Vector3Negate(*this); } + /** + * Negate provided vector (invert direction) + */ + Vector3 operator-() const { return Vector3Negate(*this); } + /** * Multiply vector by vector */ Vector3 Multiply(const ::Vector3& vector3) const { return Vector3Multiply(*this, vector3); } + /** + * Multiply vector by vector + */ + Vector3 operator*(const ::Vector3& vector3) const { return Vector3Multiply(*this, vector3); } + + /** + * Multiply vector by vector + */ + Vector3& operator*=(const ::Vector3& vector3) { + set(Vector3Multiply(*this, vector3)); + + return *this; + } + /** * Multiply vector by scalar */ Vector3 Scale(const float scaler) const { return Vector3Scale(*this, scaler); } + /** + * Multiply vector by scalar + */ + Vector3 operator*(const float scaler) const { return Vector3Scale(*this, scaler); } + + /** + * Multiply vector by scalar + */ + Vector3& operator*=(const float scaler) { + set(Vector3Scale(*this, scaler)); + + return *this; + } + /** * Divide vector by vector */ Vector3 Divide(const ::Vector3& vector3) const { return Vector3Divide(*this, vector3); } + /** + * Divide vector by vector + */ + Vector3 operator/(const ::Vector3& vector3) const { return Vector3Divide(*this, vector3); } + + /** + * Divide vector by vector + */ + Vector3& operator/=(const ::Vector3& vector3) { + x /= vector3.x; + y /= vector3.y; + z /= vector3.z; + + return *this; + } + /** * Divide a vector by a value. */ Vector3 Divide(const float div) const { return ::Vector3{x / div, y / div, z / div}; } + /** + * Divide a vector by a value. + */ + Vector3 operator/(const float div) const { return Divide(div); } + + /** + * Divide a vector by a value. + */ + Vector3& operator/=(const float div) { + x /= div; + y /= div; + z /= div; + + return *this; + } + /** * Calculate vector length */ diff --git a/include/Vector4.hpp b/include/Vector4.hpp index 16f06d5c..2cc66b18 100644 --- a/include/Vector4.hpp +++ b/include/Vector4.hpp @@ -56,6 +56,8 @@ class Vector4 : public ::Vector4 { #ifndef RAYLIB_CPP_NO_MATH Vector4 Multiply(const ::Vector4& vector4) const { return QuaternionMultiply(*this, vector4); } + Vector4 operator*(const ::Vector4& vector4) const { return QuaternionMultiply(*this, vector4); } + Vector4 Lerp(const ::Vector4& vector4, float amount) const { return QuaternionLerp(*this, vector4, amount); } Vector4 Nlerp(const ::Vector4& vector4, float amount) const { return QuaternionNlerp(*this, vector4, amount); } diff --git a/include/raymath.hpp b/include/raymath.hpp index d7f03520..f166488e 100644 --- a/include/raymath.hpp +++ b/include/raymath.hpp @@ -15,6 +15,7 @@ extern "C" { #pragma GCC diagnostic push // These throw a warnings on visual studio, need to check if __GNUC__ is defined to use it. #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif +#define RAYMATH_DISABLE_CPP_OPERATORS #include "raymath.h" // NOLINT #ifdef __GNUC__ #pragma GCC diagnostic pop diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index e7d9836c..8fe355ca 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 d8feef5 + GIT_TAG 5e6cdf3 GIT_SHALLOW 1 ) FetchContent_MakeAvailable(raylib) diff --git a/tests/raylib_cpp_test.cpp b/tests/raylib_cpp_test.cpp index 59fee1b5..45524095 100644 --- a/tests/raylib_cpp_test.cpp +++ b/tests/raylib_cpp_test.cpp @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) { { // Loading raylib::Image image(path + "/resources/feynman.png"); - Assert(image.IsReady()); + Assert(image.IsValid()); // Chaining image.Crop(100, 100).Resize(50, 50); @@ -108,7 +108,7 @@ int main(int argc, char* argv[]) { // Wave { raylib::Wave wave(path + "/resources/weird.wav"); - Assert(wave.IsReady(), "Expected wave to be loaded correctly"); + Assert(wave.IsValid(), "Expected wave to be loaded correctly"); } // RaylibException