diff --git a/CMakeLists.txt b/CMakeLists.txt index ba1f240..dc50a76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,8 @@ cmake_minimum_required(VERSION 3.22) project(sortiva - LANGUAGES CXX - VERSION 1.0.0 + LANGUAGES CXX + VERSION 1.0.0 ) # ======================================================== @@ -30,35 +30,35 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # Build static # It then sets the folder property for the target. function(put_targets_into_folder) - set(oneValueArgs FOLDER) - set(multiValueArgs TARGETS) - cmake_parse_arguments(ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(oneValueArgs FOLDER) + set(multiValueArgs TARGETS) + cmake_parse_arguments(ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - foreach(target ${ARGS_TARGETS}) - # Check if target exists - if (NOT TARGET ${target}) - message(FATAL_ERROR "${target} target not found") - endif() + foreach(target ${ARGS_TARGETS}) + # Check if target exists + if (NOT TARGET ${target}) + message(FATAL_ERROR "${target} target not found") + endif() - # Get the actual target (if it is aliased) - get_target_property(actual_target ${target} ALIASED_TARGET) - if (NOT actual_target) - set(actual_target ${target}) - endif() + # Get the actual target (if it is aliased) + get_target_property(actual_target ${target} ALIASED_TARGET) + if (NOT actual_target) + set(actual_target ${target}) + endif() - # Set the folder property for the target - set_target_properties(${actual_target} PROPERTIES FOLDER ${ARGS_FOLDER}) - endforeach() + # Set the folder property for the target + set_target_properties(${actual_target} PROPERTIES FOLDER ${ARGS_FOLDER}) + endforeach() endfunction() function(find_files var_name path) - set(sources) - foreach(ext ${ARGN}) - file(GLOB_RECURSE files "${path}/*.${ext}") - list(APPEND sources ${files}) - endforeach() - set(${var_name} ${${var_name}} ${sources} PARENT_SCOPE) + set(sources) + foreach(ext ${ARGN}) + file(GLOB_RECURSE files "${path}/*.${ext}") + list(APPEND sources ${files}) + endforeach() + set(${var_name} ${${var_name}} ${sources} PARENT_SCOPE) endfunction() # ======================================================== @@ -87,9 +87,9 @@ FetchContent_MakeAvailable(sol2) # --- Add Lua FetchContent_Declare( - lua - GIT_REPOSITORY "https://github.com/marovira/lua" - GIT_TAG "5.4.4" + lua + GIT_REPOSITORY "https://github.com/marovira/lua" + GIT_TAG "5.4.4" ) FetchContent_MakeAvailable(lua) @@ -103,11 +103,11 @@ set(SOL2_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) # that are shared among all targets. function(set_common_properties target) - target_link_libraries(${target} PRIVATE sol2::sol2) # Link with Sol2 - target_compile_definitions(${target} PRIVATE SOL_ALL_SAFETIES_ON=1) - target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) # Include project headers - target_sources(${target} PRIVATE ${SVA_COMMON_FILES}) # Include common files - target_link_libraries(${target} PRIVATE lua::lua) + target_link_libraries(${target} PRIVATE sol2::sol2) # Link with Sol2 + target_compile_definitions(${target} PRIVATE SOL_ALL_SAFETIES_ON=1) + target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) # Include project headers + target_sources(${target} PRIVATE ${SVA_COMMON_FILES}) # Include common files + target_link_libraries(${target} PRIVATE lua::lua) endfunction() # ======================================================== @@ -118,7 +118,7 @@ set(GUI_TARGET_NAME "${PROJECT_NAME}") # --- Create GUI Executable find_files(SVA_GUI_FILES "./src/" hpp cpp h c hxx cxx) add_executable(${GUI_TARGET_NAME} - ${SVA_GUI_FILES} + ${SVA_GUI_FILES} ) source_group(TREE ${PROJECT_SOURCE_DIR}/src/ PREFIX "Source" FILES ${SVA_GUI_FILES}) @@ -127,53 +127,68 @@ source_group(TREE ${PROJECT_SOURCE_DIR}/src/ PREFIX "Source" FILES ${SVA_GUI_FIL # RAYLIB # --------------- # Dependencies -set(RAYLIB_VERSION 5.0) +set(RAYLIB_VERSION 5.5) find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED if (NOT raylib_FOUND) # If there's none, fetch and build raylib - include(FetchContent) - FetchContent_Declare( - raylib - DOWNLOAD_EXTRACT_TIMESTAMP OFF - URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz - ) - FetchContent_GetProperties(raylib) - if (NOT raylib_POPULATED) # Have we downloaded raylib yet? - set(FETCHCONTENT_QUIET NO) - FetchContent_MakeAvailable(raylib) - set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples - endif() + include(FetchContent) + FetchContent_Declare( + raylib + DOWNLOAD_EXTRACT_TIMESTAMP OFF + URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz + ) + FetchContent_GetProperties(raylib) + if (NOT raylib_POPULATED) # Have we downloaded raylib yet? + set(FETCHCONTENT_QUIET NO) + FetchContent_MakeAvailable(raylib) + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples + endif() endif() -target_link_libraries(${GUI_TARGET_NAME} PRIVATE raylib) +# raylib-cpp +find_package(raylib_cpp QUIET) +if (NOT raylib_cpp_FOUND) + if (NOT DEFINED RAYLIB_CPP_VERSION) + set(RAYLIB_CPP_VERSION next) + endif() + include(FetchContent) + FetchContent_Declare( + raylib_cpp + GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git + GIT_TAG ${RAYLIB_CPP_VERSION} + ) + FetchContent_MakeAvailable(raylib_cpp) +endif() + +target_link_libraries(${GUI_TARGET_NAME} PRIVATE raylib raylib_cpp) # Checks if OSX and links appropriate frameworks (Only required on MacOS) if (APPLE) - target_link_libraries(${PROJECT_NAME} "-framework IOKit") - target_link_libraries(${PROJECT_NAME} "-framework Cocoa") - target_link_libraries(${PROJECT_NAME} "-framework OpenGL") + target_link_libraries(${PROJECT_NAME} "-framework IOKit") + target_link_libraries(${PROJECT_NAME} "-framework Cocoa") + target_link_libraries(${PROJECT_NAME} "-framework OpenGL") endif() - + set_common_properties(${GUI_TARGET_NAME}) put_targets_into_folder( - FOLDER "ThirdParty/raylib" - TARGETS - raylib uninstall + FOLDER "ThirdParty/raylib" + TARGETS + raylib raylib_cpp uninstall ) put_targets_into_folder( - FOLDER "ThirdParty/lua" - TARGETS - lua lua_lib + FOLDER "ThirdParty/lua" + TARGETS + lua lua_lib ) put_targets_into_folder( - FOLDER "ThirdParty/glfw" - TARGETS - glfw update_mappings + FOLDER "ThirdParty/glfw" + TARGETS + glfw update_mappings ) @@ -182,17 +197,17 @@ put_targets_into_folder( set(SVA_CREATE_INCLUDES_TARGET ON CACHE BOOL "Create an includes target") if(${SVA_CREATE_INCLUDES_TARGET}) - set(INCLUDES_TARGET_NAME "includes") - set(INCLUDE_FILES) - find_files( - INCLUDE_FILES - "include/" - hpp h hxx - ) - message(STATUS "Include files: ${INCLUDE_FILES}") - add_custom_target(${INCLUDES_TARGET_NAME} - SOURCES - ${INCLUDE_FILES} - ) - source_group(TREE ${PROJECT_SOURCE_DIR}/include/ PREFIX "Source" FILES ${INCLUDE_FILES}) + set(INCLUDES_TARGET_NAME "includes") + set(INCLUDE_FILES) + find_files( + INCLUDE_FILES + "include/" + hpp h hxx + ) + message(STATUS "Include files: ${INCLUDE_FILES}") + add_custom_target(${INCLUDES_TARGET_NAME} + SOURCES + ${INCLUDE_FILES} + ) + source_group(TREE ${PROJECT_SOURCE_DIR}/include/ PREFIX "Source" FILES ${INCLUDE_FILES}) endif() diff --git a/include/raylibs/raylib-cpp.hpp b/include/raylibs/raylib-cpp.hpp new file mode 100644 index 0000000..1ac27ba --- /dev/null +++ b/include/raylibs/raylib-cpp.hpp @@ -0,0 +1,80 @@ +/** + * [raylib-cpp](https://github.com/RobLoach/raylib-cpp) is a C++ wrapper library for raylib, a simple and easy-to-use library to enjoy videogames programming. This C++ header provides object-oriented wrappers around raylib's struct interfaces. + * + * @see raylib namespace for a list of all available classes. + * @mainpage raylib-cpp + * @include core_basic_window.cpp + * @author Rob Loach (RobLoach) + * @copyright zlib/libpng + * + * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified, + * BSD-like license that allows static linking with closed source software: + * + * Copyright 2020 Rob Loach (RobLoach) + * + * This software is provided "as-is", without any express or implied warranty. In no event + * will the authors be held liable for any damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, including commercial + * applications, and to alter it and redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not claim that you + * wrote the original software. If you use this software in a product, an acknowledgment + * in the product documentation would be appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be misrepresented + * as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_ +#define RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_ + +#include "./AudioDevice.hpp" +#include "./AudioStream.hpp" +#include "./AutomationEventList.hpp" +#include "./BoundingBox.hpp" +#include "./Camera2D.hpp" +#include "./Camera3D.hpp" +#include "./Color.hpp" +#include "./FileData.hpp" +#include "./FileText.hpp" +#include "./Font.hpp" +#include "./Functions.hpp" +#include "./Gamepad.hpp" +#include "./Image.hpp" +#include "./Keyboard.hpp" +#include "./Material.hpp" +#include "./Matrix.hpp" +#include "./Mesh.hpp" +#include "./Model.hpp" +#include "./ModelAnimation.hpp" +#include "./Mouse.hpp" +#include "./Music.hpp" +#include "./Ray.hpp" +#include "./RayCollision.hpp" +#include "./RaylibException.hpp" +#include "./Rectangle.hpp" +#include "./RenderTexture.hpp" +#include "./Shader.hpp" +#include "./Sound.hpp" +#include "./Text.hpp" +#include "./Texture.hpp" +#include "./TextureUnmanaged.hpp" +#include "./Touch.hpp" +#include "./Vector2.hpp" +#include "./Vector3.hpp" +#include "./Vector4.hpp" +#include "./VrStereoConfig.hpp" +#include "./Wave.hpp" +#include "./Window.hpp" + +/** + * All raylib-cpp classes and functions appear in the raylib namespace. + */ +namespace raylib { +// Nothing. +} // namespace raylib + +#endif // RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_ diff --git a/src/sortiva.cpp b/src/sortiva.cpp index 918aff9..20b45d6 100644 --- a/src/sortiva.cpp +++ b/src/sortiva.cpp @@ -3,16 +3,10 @@ #include #include -#define RL_COLOR(COLOR) rl::##COLOR -namespace rl { -#include -} - -Sortiva::Sortiva() +Sortiva::Sortiva() : wnd(1280, 720, "Sortiva", rl::FLAG_WINDOW_RESIZABLE | rl::FLAG_WINDOW_TRANSPARENT) { - rl::InitWindow(1280, 720, "Sortiva"); - if (!rl::IsWindowReady()) + if (!wnd.IsWindowReady()) { printf("Window could not be initialized\n"); exit(-1); diff --git a/src/sortiva.hpp b/src/sortiva.hpp index bfe21d8..6b7525e 100644 --- a/src/sortiva.hpp +++ b/src/sortiva.hpp @@ -1,6 +1,10 @@ #pragma once #include +#include +#include + +namespace rl = raylib; class Sortiva final { @@ -10,6 +14,7 @@ public: void run(); private: + rl::Window wnd; int m_Width; int m_Height; bool m_Running;