From c1744de1251f48e2e286233d3dabc562f87423c1 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 18 Mar 2023 14:45:40 -0400 Subject: [PATCH] Update to raylib v4.5.0 --- CMakeLists.txt | 2 +- examples/CMakeLists.txt | 2 +- examples/core/core_3d_camera_first_person.cpp | 88 ------------------- examples/core/core_world_screen.cpp | 4 +- examples/models/models_billboard.cpp | 4 +- examples/models/models_first_person_maze.cpp | 4 +- include/AudioStream.hpp | 2 +- include/Camera2D.hpp | 12 +-- include/Camera3D.hpp | 39 ++------ include/Font.hpp | 2 +- include/Functions.hpp | 8 -- include/Image.hpp | 4 +- include/Material.hpp | 7 ++ include/Model.hpp | 10 +-- include/Music.hpp | 2 +- include/RenderTexture.hpp | 4 +- include/Sound.hpp | 25 +----- include/Wave.hpp | 2 +- include/Window.hpp | 16 ++-- include/raylib.hpp | 12 ++- package.json | 2 +- 21 files changed, 54 insertions(+), 197 deletions(-) delete mode 100644 examples/core/core_3d_camera_first_person.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c145361e..b2c26eb5 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 4.2.8 + VERSION 4.5.0 DESCRIPTION "raylib-cpp C++ Object Oriented Wrapper for raylib" HOMEPAGE_URL "https://github.com/robloach/raylib-cpp" LANGUAGES C CXX diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index bc1c36a4..3497a52a 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 4.2.0 + GIT_TAG 4.5.0 ) FetchContent_GetProperties(raylib) if (NOT raylib_POPULATED) # Have we downloaded raylib yet? diff --git a/examples/core/core_3d_camera_first_person.cpp b/examples/core/core_3d_camera_first_person.cpp deleted file mode 100644 index 9223ed1a..00000000 --- a/examples/core/core_3d_camera_first_person.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************************* -* -* raylib [core] example - 3d camera first person -* -* This example has been created using raylib 1.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2015 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib-cpp.hpp" - -#define MAX_COLUMNS 20 - -int main() { - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - raylib::Window window(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); - - // Define the camera to look into our 3d world (position, target, up vector) - raylib::Camera camera( - raylib::Vector3(4.0f, 2.0f, 4.0f), - raylib::Vector3(0.0f, 1.8f, 0.0f), - raylib::Vector3(0.0f, 1.0f, 0.0f), - 60.0f, - CAMERA_PERSPECTIVE); - - // Generates some random columns - float heights[MAX_COLUMNS] = { 0.0f }; - raylib::Vector3 positions[MAX_COLUMNS] = { 0 }; - raylib::Color colors[MAX_COLUMNS] = { 0 }; - - for (int i = 0; i < MAX_COLUMNS; i++) { - heights[i] = static_cast(GetRandomValue(1, 12)); - positions[i] = raylib::Vector3(GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15)); - colors[i] = raylib::Color(GetRandomValue(20, 255), GetRandomValue(10, 55), 30); - } - - camera.SetMode(CAMERA_FIRST_PERSON); // Set a first person camera mode - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!window.ShouldClose()) { // Detect window close button or ESC key - // Update - //---------------------------------------------------------------------------------- - camera.Update(); // Update camera - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - { - window.ClearBackground(RAYWHITE); - - camera.BeginMode(); - { - DrawPlane(Vector3{ 0.0f, 0.0f, 0.0f }, Vector2{ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground - DrawCube(Vector3{ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall - DrawCube(Vector3{ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall - DrawCube(Vector3{ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall - - // Draw some cubes around - for (int i = 0; i < MAX_COLUMNS; i++) { - positions[i].DrawCube(2.0f, heights[i], 2.0f, colors[i]); - positions[i].DrawCubeWires(2.0f, heights[i], 2.0f, MAROON); - } - } - camera.EndMode(); - - DrawRectangle(10, 10, 220, 70, raylib::Color::SkyBlue().Fade(0.5f)); - DrawRectangleLines(10, 10, 220, 70, BLUE); - - raylib::DrawText("First person camera default controls:", 20, 20, 10, BLACK); - raylib::DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY); - raylib::DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY); - } - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - return 0; -} diff --git a/examples/core/core_world_screen.cpp b/examples/core/core_world_screen.cpp index f53486e9..2b91a5ca 100644 --- a/examples/core/core_world_screen.cpp +++ b/examples/core/core_world_screen.cpp @@ -30,8 +30,6 @@ int main() { Vector3 cubePosition; Vector2 cubeScreenPosition; - camera.SetMode(CAMERA_FREE); // Set a free camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -39,7 +37,7 @@ int main() { while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - camera.Update(); // Update camera + camera.Update(CAMERA_THIRD_PERSON); // Update camera // Calculate cube screen space position (with a little offset to be in top) cubeScreenPosition = GetWorldToScreen(Vector3{cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera); diff --git a/examples/models/models_billboard.cpp b/examples/models/models_billboard.cpp index 6a27528f..111d9af4 100644 --- a/examples/models/models_billboard.cpp +++ b/examples/models/models_billboard.cpp @@ -30,8 +30,6 @@ int main() { raylib::Texture2D bill("resources/billboard.png"); // Our texture billboard raylib::Vector3 billPosition(0.0f, 2.0f, 0.0f); // Position where draw billboard - camera.SetMode(CAMERA_ORBITAL); // Set an orbital camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -39,7 +37,7 @@ int main() { while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - camera.Update(); // Update camera + camera.Update(CAMERA_ORBITAL); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/models/models_first_person_maze.cpp b/examples/models/models_first_person_maze.cpp index 709b5451..32d1a175 100644 --- a/examples/models/models_first_person_maze.cpp +++ b/examples/models/models_first_person_maze.cpp @@ -40,8 +40,6 @@ int main(void) raylib::Vector3 mapPosition(-16.0f, 0.0f, -8.0f); // Set model position raylib::Vector3 playerPosition(camera.position); // Set player position - camera.SetMode(CAMERA_FIRST_PERSON); // Set camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -51,7 +49,7 @@ int main(void) //---------------------------------------------------------------------------------- raylib::Vector3 oldCamPos(camera.position); // Store old camera position - camera.Update(); // Update camera + camera.Update(CAMERA_FIRST_PERSON); // Update camera // Check player collision (we simplify to 2D collision detection) raylib::Vector2 playerPos(camera.position.x, camera.position.z); diff --git a/include/AudioStream.hpp b/include/AudioStream.hpp index 4a47d4f2..ccf07baf 100644 --- a/include/AudioStream.hpp +++ b/include/AudioStream.hpp @@ -195,7 +195,7 @@ class AudioStream : public ::AudioStream { * Retrieve whether or not the audio stream is ready. */ bool IsReady() { - return channels > 0; + return ::IsAudioStreamReady(*this); } /** diff --git a/include/Camera2D.hpp b/include/Camera2D.hpp index 64678d83..1381de29 100644 --- a/include/Camera2D.hpp +++ b/include/Camera2D.hpp @@ -47,17 +47,17 @@ class Camera2D : public ::Camera2D { } /** - * Returns the screen space position for a 3d world space position + * Returns the world space position for a 2d camera screen space position */ - inline Vector2 GetWorldToScreen(::Vector2 position) const { - return ::GetWorldToScreen2D(position, *this); + inline Vector2 GetScreenToWorld(::Vector2 position) const { + return ::GetScreenToWorld2D(position, *this); } /** - * Returns the world space position for a 2d camera screen space position + * Returns the screen space position for a 3d world space position */ - inline Vector2 GetScreenToWorld(::Vector2 position) const { - return ::GetScreenToWorld2D(position, *this); + inline Vector2 GetWorldToScreen(::Vector2 position) const { + return ::GetWorldToScreen2D(position, *this); } private: diff --git a/include/Camera3D.hpp b/include/Camera3D.hpp index 9f41f95b..52ebdf56 100644 --- a/include/Camera3D.hpp +++ b/include/Camera3D.hpp @@ -67,45 +67,18 @@ class Camera3D : public ::Camera3D { } /** - * Set camera mode (multiple camera modes available) - */ - inline Camera3D& SetMode(int mode) { - ::SetCameraMode(*this, mode); - return *this; - } - - /** - * Set camera alt key to combine with mouse movement (free camera) - */ - inline Camera3D& SetAltControl(int altKey) { - ::SetCameraAltControl(altKey); - return *this; - } - - /** - * Set camera smooth zoom key to combine with mouse (free camera) - */ - inline Camera3D& SetSmoothZoomControl(int szKey) { - ::SetCameraSmoothZoomControl(szKey); - return *this; - } - - /** - * Set camera move controls (1st person and 3rd person cameras) + * Update camera position for selected mode */ - inline Camera3D& SetMoveControls( - int frontKey, int backKey, - int rightKey, int leftKey, - int upKey, int downKey) { - ::SetCameraMoveControls(frontKey, backKey, rightKey, leftKey, upKey, downKey); + inline Camera3D& Update(int mode) { + ::UpdateCamera(this, mode); return *this; } /** - * Update camera position for selected mode + * Update camera movement/rotation */ - inline Camera3D& Update() { - ::UpdateCamera(this); + inline Camera3D& Update(::Vector3 movement, ::Vector3 rotation, float zoom = 1.0f) { + ::UpdateCameraPro(this, movement, rotation, zoom); return *this; } diff --git a/include/Font.hpp b/include/Font.hpp index 4d0908b4..e6bfdfad 100644 --- a/include/Font.hpp +++ b/include/Font.hpp @@ -207,7 +207,7 @@ class Font : public ::Font { * Returns if the font is ready to be used. */ bool IsReady() { - return baseSize > 0; + return ::IsFontReady(*this); } /** diff --git a/include/Functions.hpp b/include/Functions.hpp index adbc18bc..ac309d97 100644 --- a/include/Functions.hpp +++ b/include/Functions.hpp @@ -191,14 +191,6 @@ RLCPPAPI inline void OpenURL(const std::string& url) { return ::OpenURL(url.c_str()); } -/** - * Update camera depending on selected mode - */ -RLCPPAPI inline void UpdateCamera(const ::Camera& camera) { - ::Camera* cameraPointer = (::Camera*)&camera; - ::UpdateCamera(cameraPointer); -} - /** * Load an image. */ diff --git a/include/Image.hpp b/include/Image.hpp index 1c712499..5bc7d087 100644 --- a/include/Image.hpp +++ b/include/Image.hpp @@ -713,7 +713,7 @@ class Image : public ::Image { * * @return The pixel data size of the image. */ - int GetPixelDataSize() const { + inline int GetPixelDataSize() const { return ::GetPixelDataSize(width, height, format); } @@ -723,7 +723,7 @@ class Image : public ::Image { * @return True or false depending on whether the Image has been loaded. */ inline bool IsReady() const { - return data != nullptr; + return ::IsImageReady(*this); } private: diff --git a/include/Material.hpp b/include/Material.hpp index 52d46fc3..d26b4088 100644 --- a/include/Material.hpp +++ b/include/Material.hpp @@ -109,6 +109,13 @@ class Material : public ::Material { ::DrawMeshInstanced(mesh, *this, transforms, instances); } + /** + * Check if material is ready + */ + inline bool IsReady() { + return ::IsMaterialReady(*this); + } + private: void set(const ::Material& material) { shader = material.shader; diff --git a/include/Model.hpp b/include/Model.hpp index d286da1f..52c8d209 100644 --- a/include/Model.hpp +++ b/include/Model.hpp @@ -110,14 +110,6 @@ class Model : public ::Model { } } - /** - * Unload model (but not meshes) from memory (RAM and/or VRAM) - */ - inline Model& UnloadKeepMeshes() { - ::UnloadModelKeepMeshes(*this); - return *this; - } - /** * Set material for a mesh */ @@ -201,7 +193,7 @@ class Model : public ::Model { * Determines whether or not the Model has data in it. */ bool IsReady() const { - return meshCount > 0 || materialCount > 0 || boneCount > 0; + return ::IsModelReady(*this); } /** diff --git a/include/Music.hpp b/include/Music.hpp index c528a9fd..4f1a0e58 100644 --- a/include/Music.hpp +++ b/include/Music.hpp @@ -220,7 +220,7 @@ class Music : public ::Music { * @return True or false depending on whether the Music has been loaded. */ inline bool IsReady() const { - return stream.buffer != nullptr; + return ::IsMusicReady(*this); } private: diff --git a/include/RenderTexture.hpp b/include/RenderTexture.hpp index decda423..2190571b 100644 --- a/include/RenderTexture.hpp +++ b/include/RenderTexture.hpp @@ -123,8 +123,8 @@ class RenderTexture : public ::RenderTexture { /** * Retrieves whether or not the render texture is ready. */ - bool IsReady() const { - return id != 0; + inline bool IsReady() const { + return ::IsRenderTextureReady(*this); } private: diff --git a/include/Sound.hpp b/include/Sound.hpp index 4624aa64..1b6fdd2e 100644 --- a/include/Sound.hpp +++ b/include/Sound.hpp @@ -134,22 +134,6 @@ class Sound : public ::Sound { return *this; } - /** - * Play a sound (using multichannel buffer pool) - */ - inline Sound& PlayMulti() { - ::PlaySoundMulti(*this); - return *this; - } - - /** - * Stop any sound playing (using multichannel buffer pool) - */ - inline Sound& StopMulti() { - ::StopSoundMulti(); - return *this; - } - /** * Check if a sound is currently playing */ @@ -211,14 +195,7 @@ class Sound : public ::Sound { * @return True or false depending on whether the Sound buffer is loaded. */ bool IsReady() const { - return stream.buffer != nullptr; - } - - /** - * Get number of sounds playing in the multichannel - */ - int GetPlaying() { - return ::GetSoundsPlaying(); + return ::IsSoundReady(*this); } private: diff --git a/include/Wave.hpp b/include/Wave.hpp index 5628f489..e5720655 100644 --- a/include/Wave.hpp +++ b/include/Wave.hpp @@ -212,7 +212,7 @@ class Wave : public ::Wave { * @return True or false depending on whether the wave data has been loaded. */ inline bool IsReady() const { - return data != nullptr; + return ::IsWaveReady(*this); } private: diff --git a/include/Window.hpp b/include/Window.hpp index c1c93a5f..8ee78e11 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -45,7 +45,7 @@ class Window { */ inline void Init(int width = 800, int height = 450, const std::string& title = "raylib") { ::InitWindow(width, height, title.c_str()); - if (!IsWindowReady()) { + if (!::IsWindowReady()) { throw RaylibException("Failed to create Window"); } } @@ -73,13 +73,6 @@ class Window { return ::IsCursorOnScreen(); } - /** - * Check if window has been initialized successfully - */ - inline static bool IsReady() { - return ::IsWindowReady(); - } - /** * Check if window is currently fullscreen */ @@ -401,6 +394,13 @@ class Window { inline double GetTime() const { return ::GetTime(); } + + /** + * Check if window has been initialized successfully + */ + inline static bool IsReady() { + return ::IsWindowReady(); + } }; } // namespace raylib diff --git a/include/raylib.hpp b/include/raylib.hpp index deebef02..5280eff3 100644 --- a/include/raylib.hpp +++ b/include/raylib.hpp @@ -7,7 +7,17 @@ #ifdef __cplusplus extern "C" { #endif -#include "raylib.h" // NOLINT + +#ifndef RAYLIB_H_FILE +#define RAYLIB_H_FILE "raylib.h" +#endif + +#include RAYLIB_H_FILE // NOLINT + +#if !defined(RAYLIB_VERSION_MAJOR) || !defined(RAYLIB_VERSION_MINOR) || RAYLIB_VERSION_MAJOR < 4 || RAYLIB_VERSION_MINOR < 5 +#error "raylib-cpp requires at least raylib 4.5.0" +#endif + #ifdef __cplusplus } #endif diff --git a/package.json b/package.json index cce83732..f5c549d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "raylib-cpp", - "version": "4.2.8", + "version": "4.5.0", "description": "raylib-cpp: C++ Object-Oriented Wrapper for raylib", "main": "index.js", "private": true,