29 Commits

Author SHA1 Message Date
a9e56b9e25 fix logging 2022-11-08 18:26:24 +01:00
eeb8be6a8e update spdlog to v1.11.0 2022-11-08 17:47:58 +01:00
c4bd4fd678 merge test into main workflow 2022-11-07 01:54:45 +01:00
9f6e9defb0 make tests auto terminate 2022-11-07 01:54:45 +01:00
5ed71690c7 run tests using headless X 2022-11-07 01:54:45 +01:00
e108d14e1d forgot imgui cmake version 2022-11-06 15:34:13 +01:00
20dd451cd0 fix linker warning and add lto example as comment 2022-11-06 15:31:38 +01:00
3f03bbbd49 windows ci timed out 2022-11-01 19:01:09 +01:00
9af3df5550 fix SDL_main windows thingy 2022-11-01 18:44:34 +01:00
8e5471480c fix vcpkg sdl package not properly exposing linkage flags 2022-11-01 15:41:41 +01:00
8ace6e51f9 fix msvc complaining 2022-11-01 00:15:05 +01:00
2b6a6b3e0c enable windows ci 2022-11-01 00:15:05 +01:00
dffbad65d2 fix cmake sdl finding, find_package for each cmake scope 2022-11-01 00:15:05 +01:00
4d0f731d8d better cmake for emscripten flags 2022-10-30 18:18:20 +01:00
c13dff8eb3 add some more c++17 2022-10-30 18:18:20 +01:00
8cc473b9fc fix emscripten + tracy wrong include path 2022-10-30 18:18:20 +01:00
53c7bc1477 add emscripten to the ci 2022-10-30 18:18:20 +01:00
7d983244b2 update nlohmann::json to v3.11.2 2022-10-30 02:36:30 +02:00
26a1f4b101 fix: use newer action/checkout 2022-10-27 17:29:21 +02:00
5004e30e18 update tracy to v0.9 and adopt 2022-10-27 16:36:40 +02:00
cc40740cf1 update physfs to latest (v3.2.0) 2022-10-01 22:44:29 +02:00
3d03881002 add simple tracy build to github ci 2022-08-11 16:00:43 +02:00
3b2cd5c62b update Tracy to v0.8.2.1 2022-08-11 16:00:43 +02:00
ee16ca5356 update soloud to latest 2022-08-08 14:54:54 +02:00
4b707a7adb update physfs to latest 2022-08-08 13:22:01 +02:00
e1bf5fefc0 fix imgui now requiring atleast c++11 2022-08-03 16:09:22 +02:00
e65878509e update dear ImGui to v1.88 2022-08-03 01:58:55 +02:00
5ed74d956d update googletest to v1.12.1 2022-08-03 01:49:04 +02:00
989e3f7dda change default bloom factor to a more reasonable 0.8 2022-08-02 14:53:21 +02:00
104 changed files with 1319 additions and 507 deletions

View File

@ -9,6 +9,8 @@ on:
env: env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug BUILD_TYPE: Debug
EM_VERSION: 2.0.24
EM_CACHE_FOLDER: 'emsdk-cache'
jobs: jobs:
linux: linux:
@ -20,14 +22,14 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
# TODO: cache # TODO: cache
- name: Install Dependencies - name: Install Dependencies
run: sudo apt update && sudo apt -y install libsdl2-dev run: sudo apt update && sudo apt -y install libsdl2-dev xserver-xorg-video-dummy
- name: Configure CMake - name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
@ -35,11 +37,20 @@ jobs:
- name: Build - name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
#- name: Test - name: Test
#working-directory: ${{github.workspace}}/build working-directory: ${{github.workspace}}/build
## Execute tests defined by the CMake configuration. # Execute tests defined by the CMake configuration.
## See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
#run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure #run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
# TODO: look into xinit
env:
DISPLAY: :0
run: |
sudo Xorg :0 -config ${{github.workspace}}/.github/workflows/x/dummy-1920x1080.conf -noautoBindGPU &
sleep 20s
ctest --output-on-failure --timeout 20
sudo pkill -15 Xorg
linux_gles: linux_gles:
timeout-minutes: 10 timeout-minutes: 10
@ -47,7 +58,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
@ -62,13 +73,64 @@ jobs:
- name: Build - name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
linux_tracy:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Dependencies
run: sudo apt update && sudo apt -y install libsdl2-dev
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTRACY_ENABLE=ON
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
emscripten:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
#- name: Install Dependencies
#run: sudo apt update && sudo apt -y install libsdl2-dev
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
with:
# Make sure to set a version number!
version: ${{env.EM_VERSION}}
# This is the name of the cache folder.
# The cache folder will be placed in the build directory,
# so make sure it doesn't conflict with anything!
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
- name: Verify
run: emcc --check
- name: Configure CMake
run: emcmake cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DMM_OPENGL_3_GLES=ON
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
macos: macos:
timeout-minutes: 10 timeout-minutes: 10
runs-on: macos-latest runs-on: macos-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
@ -83,30 +145,29 @@ jobs:
- name: Build - name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
# TODO: for some reason vcpkg find sdl does not work, despite the find_package REQUIRE not failing windows:
#windows: timeout-minutes: 15 # TODO: caching
#timeout-minutes: 10
#runs-on: windows-latest runs-on: windows-latest
#steps: steps:
#- uses: actions/checkout@v2 - uses: actions/checkout@v3
#with: with:
#submodules: recursive submodules: recursive
## TODO: cache # TODO: cache
#- name: Install Dependencies - name: Install Dependencies
#run: vcpkg install sdl2:x64-windows run: vcpkg install sdl2[core,vulkan]:x64-windows
## setup vs env # setup vs env
#- uses: ilammy/msvc-dev-cmd@v1 - uses: ilammy/msvc-dev-cmd@v1
#with: with:
#arch: amd64 arch: amd64
#- name: Configure CMake - name: Configure CMake
#run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
#- name: Build - name: Build
#run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4

View File

@ -0,0 +1,21 @@
# https://wiki.archlinux.org/title/Xorg
Section "Monitor"
Identifier "dummy_monitor"
HorizSync 28.0-80.0
VertRefresh 48.0-75.0
Modeline "1920x1080" 172.80 1920 2040 2248 2576 1080 1081 1084 1118
EndSection
Section "Device"
Identifier "dummy_card"
VideoRam 256000
Driver "dummy"
EndSection
Section "Screen"
Identifier "dummy_screen"
Device "dummy_card"
Monitor "dummy_monitor"
SubSection "Display"
EndSubSection
EndSection

View File

@ -20,9 +20,16 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
# add this to your projects cmake to enable ipo # add this to your projects cmake to enable ipo
#include(CheckIPOSupported) #if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
#check_ipo_supported() #include(CheckIPOSupported)
#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) #check_ipo_supported(RESULT HAVE_LTO)
#if(HAVE_LTO)
#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
#message(STATUS "Enabled LTO")
#else()
#message(STATUS "LTO not supported")
#endif()
#endif()
# enable test # enable test
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)

View File

@ -26,6 +26,7 @@ add_subdirectory("physfs")
if(NOT MM_HEADLESS) if(NOT MM_HEADLESS)
if(NOT EMSCRIPTEN) if(NOT EMSCRIPTEN)
# TODO: move into imgui and soload, since they are the one requireing this
if(VCPKG_TARGET_TRIPLET) if(VCPKG_TARGET_TRIPLET)
find_package(SDL2 CONFIG REQUIRED) find_package(SDL2 CONFIG REQUIRED)
else() # HACK: fix sdl find module else() # HACK: fix sdl find module

1
external/glm.cmake vendored
View File

@ -2,4 +2,5 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
add_library(glm INTERFACE) add_library(glm INTERFACE)
target_include_directories(glm INTERFACE "${CMAKE_CURRENT_LIST_DIR}/glm") target_include_directories(glm INTERFACE "${CMAKE_CURRENT_LIST_DIR}/glm")
target_compile_definitions(glm INTERFACE GLM_ENABLE_EXPERIMENTAL)

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(imgui C CXX) project(imgui C CXX)
@ -39,12 +39,14 @@ set(HPP_FILES
add_library(imgui ${CPP_FILES} ${HPP_FILES}) add_library(imgui ${CPP_FILES} ${HPP_FILES})
target_compile_features(imgui PUBLIC cxx_std_11)
if(MM_OPENGL_3_GLES) if(MM_OPENGL_3_GLES)
target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_ES3) target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_ES3)
target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM) # bug? target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM) # bug?
else() else()
target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLAD) target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLAD)
target_link_libraries(imgui glad) target_link_libraries(imgui PUBLIC glad)
endif() endif()
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
@ -54,15 +56,21 @@ target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui") # i
target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1) target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1)
if(EMSCRIPTEN) if(EMSCRIPTEN)
set_target_properties(imgui PROPERTIES COMPILE_FLAGS "-s USE_SDL=2 -s USE_WEBGL2=1 -s FULL_ES2=1 -s FULL_ES3=1") target_compile_options(imgui PUBLIC -sUSE_SDL=2)
set_target_properties(imgui PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s USE_WEBGL2=1 -s FULL_ES2=1 -s FULL_ES3=1") target_link_libraries(imgui PUBLIC -sUSE_SDL=2 -sUSE_WEBGL2=1 -sFULL_ES3=1)
elseif(ANDROID) elseif(ANDROID)
target_link_libraries(imgui SDL) target_link_libraries(imgui PUBLIC SDL)
elseif(VCPKG_TARGET_TRIPLET) elseif(VCPKG_TARGET_TRIPLET)
target_link_libraries(imgui SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static) target_link_libraries(imgui
PUBLIC
SDL2::SDL2
#PRIVATE
#SDL2::SDL2main
#SDL2::SDL2-static
)
else() else()
target_include_directories(imgui PUBLIC "${SDL2_INCLUDE_DIR}") target_include_directories(imgui PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(imgui ${SDL2_LIBRARY}) target_link_libraries(imgui PUBLIC ${SDL2_LIBRARY})
endif() endif()
target_compile_definitions(imgui PUBLIC ImTextureID=unsigned\ long) target_compile_definitions(imgui PUBLIC ImTextureID=unsigned\ long)

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
@ -12,7 +12,7 @@
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 1 #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2
#warning "Already included a different version of the library!" #warning "Already included a different version of the library!"
#endif #endif
#endif #endif
@ -20,7 +20,7 @@
#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_PATCH 1 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum)
#ifndef JSON_DIAGNOSTICS #ifndef JSON_DIAGNOSTICS
#define JSON_DIAGNOSTICS 0 #define JSON_DIAGNOSTICS 0
@ -42,38 +42,59 @@
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
#endif #endif
#define NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) \ #ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
json_v ## major ## _ ## minor ## _ ## patch #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
#define NLOHMANN_JSON_ABI_PREFIX(major, minor, patch) \ #endif
NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch)
#define NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) a ## b ## c // Construct the namespace ABI tags component
#define NLOHMANN_JSON_ABI_CONCAT(a, b, c) \ #define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b
NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) #define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
#define NLOHMANN_JSON_ABI_STRING \ #define NLOHMANN_JSON_ABI_TAGS \
NLOHMANN_JSON_ABI_CONCAT( \ NLOHMANN_JSON_ABI_TAGS_CONCAT( \
NLOHMANN_JSON_ABI_PREFIX( \
NLOHMANN_JSON_VERSION_MAJOR, \
NLOHMANN_JSON_VERSION_MINOR, \
NLOHMANN_JSON_VERSION_PATCH), \
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
// Construct the namespace version component
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
_v ## major ## _ ## minor ## _ ## patch
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
#define NLOHMANN_JSON_NAMESPACE_VERSION
#else
#define NLOHMANN_JSON_NAMESPACE_VERSION \
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
NLOHMANN_JSON_VERSION_MINOR, \
NLOHMANN_JSON_VERSION_PATCH)
#endif
// Combine namespace components
#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
#ifndef NLOHMANN_JSON_NAMESPACE #ifndef NLOHMANN_JSON_NAMESPACE
#define NLOHMANN_JSON_NAMESPACE nlohmann::NLOHMANN_JSON_ABI_STRING #define NLOHMANN_JSON_NAMESPACE \
nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
NLOHMANN_JSON_ABI_TAGS, \
NLOHMANN_JSON_NAMESPACE_VERSION)
#endif #endif
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
#define NLOHMANN_JSON_NAMESPACE_BEGIN \ #define NLOHMANN_JSON_NAMESPACE_BEGIN \
namespace nlohmann \ namespace nlohmann \
{ \ { \
inline namespace NLOHMANN_JSON_ABI_STRING \ inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
NLOHMANN_JSON_ABI_TAGS, \
NLOHMANN_JSON_NAMESPACE_VERSION) \
{ {
#endif #endif
#ifndef NLOHMANN_JSON_NAMESPACE_END #ifndef NLOHMANN_JSON_NAMESPACE_END
#define NLOHMANN_JSON_NAMESPACE_END \ #define NLOHMANN_JSON_NAMESPACE_END \
} /* namespace (abi_string) */ \ } /* namespace (inline namespace) NOLINT(readability/namespace) */ \
} /* namespace nlohmann */ } // namespace nlohmann
#endif #endif

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2009 Florian Loitsch <https://florian.loitsch.com/> // SPDX-FileCopyrightText: 2009 Florian Loitsch <https://florian.loitsch.com/>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
@ -267,9 +267,15 @@ inline void to_json(BasicJsonType& j, T b) noexcept
external_constructor<value_t::boolean>::construct(j, b); external_constructor<value_t::boolean>::construct(j, b);
} }
template<typename BasicJsonType, template < typename BasicJsonType, typename BoolRef,
enable_if_t<std::is_convertible<const std::vector<bool>::reference&, typename BasicJsonType::boolean_t>::value, int> = 0> enable_if_t <
inline void to_json(BasicJsonType& j, const std::vector<bool>::reference& b) noexcept ((std::is_same<std::vector<bool>::reference, BoolRef>::value
&& !std::is_same <std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value)
|| (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
&& !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
typename BasicJsonType::boolean_t >::value))
&& std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int > = 0 >
inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept
{ {
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b)); external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b));
} }

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
@ -20,7 +20,6 @@
#include <string> // char_traits, string #include <string> // char_traits, string
#include <utility> // make_pair, move #include <utility> // make_pair, move
#include <vector> // vector #include <vector> // vector
#include <map> // map
#include <nlohmann/detail/exceptions.hpp> #include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/input/input_adapters.hpp> #include <nlohmann/detail/input/input_adapters.hpp>
@ -1953,7 +1952,7 @@ class binary_reader
return false; return false;
} }
if (size_and_type.first != string_t::npos) if (size_and_type.first != npos)
{ {
if (size_and_type.second != 0) if (size_and_type.second != 0)
{ {
@ -2186,7 +2185,7 @@ class binary_reader
for (auto i : dim) for (auto i : dim)
{ {
result *= i; result *= i;
if (result == 0 || result == string_t::npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be string_t::npos as it is used to initialize size in get_ubjson_size_type() if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type()
{ {
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr));
} }
@ -2232,7 +2231,7 @@ class binary_reader
*/ */
bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result, bool inside_ndarray = false) bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result, bool inside_ndarray = false)
{ {
result.first = string_t::npos; // size result.first = npos; // size
result.second = 0; // type result.second = 0; // type
bool is_ndarray = false; bool is_ndarray = false;
@ -2240,10 +2239,9 @@ class binary_reader
if (current == '$') if (current == '$')
{ {
std::vector<char_int_type> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type
result.second = get(); // must not ignore 'N', because 'N' maybe the type result.second = get(); // must not ignore 'N', because 'N' maybe the type
if (JSON_HEDLEY_UNLIKELY( input_format == input_format_t::bjdata && std::find(bjdx.begin(), bjdx.end(), result.second) != bjdx.end() )) if (input_format == input_format_t::bjdata
&& JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
@ -2492,23 +2490,23 @@ class binary_reader
// if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata): // if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata):
// {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]} // {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]}
if (input_format == input_format_t::bjdata && size_and_type.first != string_t::npos && (size_and_type.second & (1 << 8)) != 0) if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
{ {
std::map<char_int_type, string_t> bjdtype = {{'U', "uint8"}, {'i', "int8"}, {'u', "uint16"}, {'I', "int16"},
{'m', "uint32"}, {'l', "int32"}, {'M', "uint64"}, {'L', "int64"}, {'d', "single"}, {'D', "double"}, {'C', "char"}
};
size_and_type.second &= ~(static_cast<char_int_type>(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker size_and_type.second &= ~(static_cast<char_int_type>(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker
auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type & p, char_int_type t)
{
return p.first < t;
});
string_t key = "_ArrayType_"; string_t key = "_ArrayType_";
if (JSON_HEDLEY_UNLIKELY(bjdtype.count(size_and_type.second) == 0)) if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(bjdtype[size_and_type.second]) )) string_t type = it->second; // sax->string() takes a reference
if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))
{ {
return false; return false;
} }
@ -2535,7 +2533,7 @@ class binary_reader
return (sax->end_array() && sax->end_object()); return (sax->end_array() && sax->end_object());
} }
if (size_and_type.first != string_t::npos) if (size_and_type.first != npos)
{ {
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
{ {
@ -2598,7 +2596,7 @@ class binary_reader
} }
// do not accept ND-array size in objects in BJData // do not accept ND-array size in objects in BJData
if (input_format == input_format_t::bjdata && size_and_type.first != string_t::npos && (size_and_type.second & (1 << 8)) != 0) if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
@ -2606,7 +2604,7 @@ class binary_reader
} }
string_t key; string_t key;
if (size_and_type.first != string_t::npos) if (size_and_type.first != npos)
{ {
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first))) if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
{ {
@ -2950,6 +2948,8 @@ class binary_reader
} }
private: private:
static JSON_INLINE_VARIABLE constexpr std::size_t npos = static_cast<std::size_t>(-1);
/// input adapter /// input adapter
InputAdapterType ia; InputAdapterType ia;
@ -2967,7 +2967,44 @@ class binary_reader
/// the SAX parser /// the SAX parser
json_sax_t* sax = nullptr; json_sax_t* sax = nullptr;
// excluded markers in bjdata optimized type
#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
make_array<bjd_type>( \
bjd_type{'C', "char"}, \
bjd_type{'D', "double"}, \
bjd_type{'I', "int16"}, \
bjd_type{'L', "int64"}, \
bjd_type{'M', "uint64"}, \
bjd_type{'U', "uint8"}, \
bjd_type{'d', "single"}, \
bjd_type{'i', "int8"}, \
bjd_type{'l', "int32"}, \
bjd_type{'m', "uint32"}, \
bjd_type{'u', "uint16"})
JSON_PRIVATE_UNLESS_TESTED:
// lookup tables
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
using bjd_type = std::pair<char_int_type, string_t>;
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
}; };
#ifndef JSON_HAS_CPP_17
template<typename BasicJsonType, typename InputAdapterType, typename SAX>
constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
#endif
} // namespace detail } // namespace detail
NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
@ -846,55 +846,143 @@ class json_pointer
return result; return result;
} }
/*! public:
@brief compares two JSON pointers for equality #if JSON_HAS_THREE_WAY_COMPARISON
/// @brief compares two JSON pointers for equality
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/
template<typename RefStringTypeRhs>
bool operator==(const json_pointer<RefStringTypeRhs>& rhs) const noexcept
{
return reference_tokens == rhs.reference_tokens;
}
@param[in] lhs JSON pointer to compare /// @brief compares JSON pointer and string for equality
@param[in] rhs JSON pointer to compare /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/
@return whether @a lhs is equal to @a rhs JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer))
bool operator==(const string_t& rhs) const
{
return *this == json_pointer(rhs);
}
@complexity Linear in the length of the JSON pointer /// @brief 3-way compares two JSON pointers
template<typename RefStringTypeRhs>
@exceptionsafety No-throw guarantee: this function never throws exceptions. std::strong_ordering operator<=>(const json_pointer<RefStringTypeRhs>& rhs) const noexcept // *NOPAD*
*/ {
return reference_tokens <=> rhs.reference_tokens; // *NOPAD*
}
#else
/// @brief compares two JSON pointers for equality
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/
template<typename RefStringTypeLhs, typename RefStringTypeRhs> template<typename RefStringTypeLhs, typename RefStringTypeRhs>
// NOLINTNEXTLINE(readability-redundant-declaration) // NOLINTNEXTLINE(readability-redundant-declaration)
friend bool operator==(json_pointer<RefStringTypeLhs> const& lhs, friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
json_pointer<RefStringTypeRhs> const& rhs) noexcept; const json_pointer<RefStringTypeRhs>& rhs) noexcept;
/*! /// @brief compares JSON pointer and string for equality
@brief compares two JSON pointers for inequality /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/
template<typename RefStringTypeLhs, typename StringType>
// NOLINTNEXTLINE(readability-redundant-declaration)
friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
const StringType& rhs);
@param[in] lhs JSON pointer to compare /// @brief compares string and JSON pointer for equality
@param[in] rhs JSON pointer to compare /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/
@return whether @a lhs is not equal @a rhs template<typename RefStringTypeRhs, typename StringType>
// NOLINTNEXTLINE(readability-redundant-declaration)
friend bool operator==(const StringType& lhs,
const json_pointer<RefStringTypeRhs>& rhs);
@complexity Linear in the length of the JSON pointer /// @brief compares two JSON pointers for inequality
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/
@exceptionsafety No-throw guarantee: this function never throws exceptions.
*/
template<typename RefStringTypeLhs, typename RefStringTypeRhs> template<typename RefStringTypeLhs, typename RefStringTypeRhs>
// NOLINTNEXTLINE(readability-redundant-declaration) // NOLINTNEXTLINE(readability-redundant-declaration)
friend bool operator!=(json_pointer<RefStringTypeLhs> const& lhs, friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
json_pointer<RefStringTypeRhs> const& rhs) noexcept; const json_pointer<RefStringTypeRhs>& rhs) noexcept;
/// @brief compares JSON pointer and string for inequality
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/
template<typename RefStringTypeLhs, typename StringType>
// NOLINTNEXTLINE(readability-redundant-declaration)
friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
const StringType& rhs);
/// @brief compares string and JSON pointer for inequality
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/
template<typename RefStringTypeRhs, typename StringType>
// NOLINTNEXTLINE(readability-redundant-declaration)
friend bool operator!=(const StringType& lhs,
const json_pointer<RefStringTypeRhs>& rhs);
/// @brief compares two JSON pointer for less-than
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
// NOLINTNEXTLINE(readability-redundant-declaration)
friend bool operator<(const json_pointer<RefStringTypeLhs>& lhs,
const json_pointer<RefStringTypeRhs>& rhs) noexcept;
#endif
private:
/// the reference tokens /// the reference tokens
std::vector<string_t> reference_tokens; std::vector<string_t> reference_tokens;
}; };
#if !JSON_HAS_THREE_WAY_COMPARISON
// functions cannot be defined inside class due to ODR violations // functions cannot be defined inside class due to ODR violations
template<typename RefStringTypeLhs, typename RefStringTypeRhs> template<typename RefStringTypeLhs, typename RefStringTypeRhs>
inline bool operator==(json_pointer<RefStringTypeLhs> const& lhs, inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
json_pointer<RefStringTypeRhs> const& rhs) noexcept const json_pointer<RefStringTypeRhs>& rhs) noexcept
{ {
return lhs.reference_tokens == rhs.reference_tokens; return lhs.reference_tokens == rhs.reference_tokens;
} }
template<typename RefStringTypeLhs,
typename StringType = typename json_pointer<RefStringTypeLhs>::string_t>
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer))
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
const StringType& rhs)
{
return lhs == json_pointer<RefStringTypeLhs>(rhs);
}
template<typename RefStringTypeRhs,
typename StringType = typename json_pointer<RefStringTypeRhs>::string_t>
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer))
inline bool operator==(const StringType& lhs,
const json_pointer<RefStringTypeRhs>& rhs)
{
return json_pointer<RefStringTypeRhs>(lhs) == rhs;
}
template<typename RefStringTypeLhs, typename RefStringTypeRhs> template<typename RefStringTypeLhs, typename RefStringTypeRhs>
inline bool operator!=(json_pointer<RefStringTypeLhs> const& lhs, inline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
json_pointer<RefStringTypeRhs> const& rhs) noexcept const json_pointer<RefStringTypeRhs>& rhs) noexcept
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
template<typename RefStringTypeLhs,
typename StringType = typename json_pointer<RefStringTypeLhs>::string_t>
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer))
inline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
const StringType& rhs)
{
return !(lhs == rhs);
}
template<typename RefStringTypeRhs,
typename StringType = typename json_pointer<RefStringTypeRhs>::string_t>
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer))
inline bool operator!=(const StringType& lhs,
const json_pointer<RefStringTypeRhs>& rhs)
{
return !(lhs == rhs);
}
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
inline bool operator<(const json_pointer<RefStringTypeLhs>& lhs,
const json_pointer<RefStringTypeRhs>& rhs) noexcept
{
return lhs.reference_tokens < rhs.reference_tokens;
}
#endif
NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
@ -9,6 +9,7 @@
#pragma once #pragma once
#include <array> // array
#include <cstddef> // size_t #include <cstddef> // size_t
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
#include <utility> // index_sequence, make_index_sequence, index_sequence_for #include <utility> // index_sequence, make_index_sequence, index_sequence_for
@ -152,15 +153,19 @@ template<> struct priority_tag<0> {};
template<typename T> template<typename T>
struct static_const struct static_const
{ {
static constexpr T value{}; static JSON_INLINE_VARIABLE constexpr T value{};
}; };
#ifndef JSON_HAS_CPP_17 #ifndef JSON_HAS_CPP_17
template<typename T> template<typename T>
constexpr T static_const<T>::value; // NOLINT(readability-redundant-declaration) constexpr T static_const<T>::value;
#endif #endif
template<typename T, typename... Args>
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
{
return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};
}
} // namespace detail } // namespace detail
NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
@ -684,5 +684,57 @@ inline constexpr bool value_in_range_of(T val)
return value_in_range_of_impl1<OfType, T>::test(val); return value_in_range_of_impl1<OfType, T>::test(val);
} }
template<bool Value>
using bool_constant = std::integral_constant<bool, Value>;
///////////////////////////////////////////////////////////////////////////////
// is_c_string
///////////////////////////////////////////////////////////////////////////////
namespace impl
{
template<typename T>
inline constexpr bool is_c_string()
{
using TUnExt = typename std::remove_extent<T>::type;
using TUnCVExt = typename std::remove_cv<TUnExt>::type;
using TUnPtr = typename std::remove_pointer<T>::type;
using TUnCVPtr = typename std::remove_cv<TUnPtr>::type;
return
(std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
|| (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
}
} // namespace impl
// checks whether T is a [cv] char */[cv] char[] C string
template<typename T>
struct is_c_string : bool_constant<impl::is_c_string<T>()> {};
template<typename T>
using is_c_string_uncvref = is_c_string<uncvref_t<T>>;
///////////////////////////////////////////////////////////////////////////////
// is_transparent
///////////////////////////////////////////////////////////////////////////////
namespace impl
{
template<typename T>
inline constexpr bool is_transparent()
{
return is_detected<detect_is_transparent, T>::value;
}
} // namespace impl
// checks whether T has a member named is_transparent
template<typename T>
struct is_transparent : bool_constant<impl::is_transparent<T>()> {};
///////////////////////////////////////////////////////////////////////////////
} // namespace detail } // namespace detail
NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_END

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2008-2009 Björn Hoehrmann <bjoern@hoehrmann.de> // SPDX-FileCopyrightText: 2008-2009 Björn Hoehrmann <bjoern@hoehrmann.de>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
@ -514,7 +514,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
object = nullptr; // silence warning, see #821 object = nullptr; // silence warning, see #821
if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
{ {
JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.1", nullptr)); // LCOV_EXCL_LINE JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.2", nullptr)); // LCOV_EXCL_LINE
} }
break; break;
} }
@ -2194,14 +2194,24 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this)); JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this));
} }
private:
template<typename KeyType>
using is_comparable_with_object_key = detail::is_comparable <
object_comparator_t, const typename object_t::key_type&, KeyType >;
template<typename ValueType>
using value_return_type = std::conditional <
detail::is_c_string_uncvref<ValueType>::value,
string_t, typename std::decay<ValueType>::type >;
public:
/// @brief access specified object element with default value /// @brief access specified object element with default value
/// @sa https://json.nlohmann.me/api/basic_json/value/ /// @sa https://json.nlohmann.me/api/basic_json/value/
// this is the value(const typename object_t::key_type&) overload template < class ValueType, detail::enable_if_t <
template < class KeyType, class ValueType, detail::enable_if_t < !detail::is_transparent<object_comparator_t>::value
std::is_same<KeyType, typename object_t::key_type>::value
&& detail::is_getable<basic_json_t, ValueType>::value && detail::is_getable<basic_json_t, ValueType>::value
&& !std::is_same<value_t, ValueType>::value, int > = 0 > && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
typename std::decay<ValueType>::type value(const KeyType& key, ValueType && default_value) const ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
{ {
// value only works for objects // value only works for objects
if (JSON_HEDLEY_LIKELY(is_object())) if (JSON_HEDLEY_LIKELY(is_object()))
@ -2210,7 +2220,32 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
const auto it = find(key); const auto it = find(key);
if (it != end()) if (it != end())
{ {
return it->template get<typename std::decay<ValueType>::type>(); return it->template get<ValueType>();
}
return default_value;
}
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this));
}
/// @brief access specified object element with default value
/// @sa https://json.nlohmann.me/api/basic_json/value/
template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
detail::enable_if_t <
!detail::is_transparent<object_comparator_t>::value
&& detail::is_getable<basic_json_t, ReturnType>::value
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
ReturnType value(const typename object_t::key_type& key, ValueType && default_value) const
{
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if key is found, return value and given default value otherwise
const auto it = find(key);
if (it != end())
{
return it->template get<ReturnType>();
} }
return std::forward<ValueType>(default_value); return std::forward<ValueType>(default_value);
@ -2221,36 +2256,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief access specified object element with default value /// @brief access specified object element with default value
/// @sa https://json.nlohmann.me/api/basic_json/value/ /// @sa https://json.nlohmann.me/api/basic_json/value/
/// overload for a default value of type const char* template < class ValueType, class KeyType, detail::enable_if_t <
string_t value(const typename object_t::key_type& key, const char* default_value) const detail::is_transparent<object_comparator_t>::value
{ && !detail::is_json_pointer<KeyType>::value
return value(key, string_t(default_value)); && is_comparable_with_object_key<KeyType>::value
} && detail::is_getable<basic_json_t, ValueType>::value
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
// these two functions, in conjunction with value(const KeyType &, ValueType &&), ValueType value(KeyType && key, const ValueType& default_value) const
// resolve an ambiguity that would otherwise occur between the json_pointer and
// typename object_t::key_type & overloads
template < class ValueType, detail::enable_if_t <
detail::is_getable<basic_json_t, ValueType>::value
&& !std::is_same<value_t, ValueType>::value, int > = 0 >
typename std::decay<ValueType>::type value(const char* key, ValueType && default_value) const
{
return value(typename object_t::key_type(key), std::forward<ValueType>(default_value));
}
string_t value(const char* key, const char* default_value) const
{
return value(typename object_t::key_type(key), string_t(default_value));
}
/// @brief access specified object element with default value
/// @sa https://json.nlohmann.me/api/basic_json/value/
/// using std::is_convertible in a std::enable_if will fail when using explicit conversions
template < class KeyType, class ValueType, detail::enable_if_t <
detail::is_getable<basic_json_t, ValueType>::value
&& !std::is_same<value_t, ValueType>::value
&& detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 >
typename std::decay<ValueType>::type value(KeyType && key, ValueType && default_value) const
{ {
// value only works for objects // value only works for objects
if (JSON_HEDLEY_LIKELY(is_object())) if (JSON_HEDLEY_LIKELY(is_object()))
@ -2259,7 +2271,34 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
const auto it = find(std::forward<KeyType>(key)); const auto it = find(std::forward<KeyType>(key));
if (it != end()) if (it != end())
{ {
return it->template get<typename std::decay<ValueType>::type>(); return it->template get<ValueType>();
}
return default_value;
}
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this));
}
/// @brief access specified object element via JSON Pointer with default value
/// @sa https://json.nlohmann.me/api/basic_json/value/
template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
detail::enable_if_t <
detail::is_transparent<object_comparator_t>::value
&& !detail::is_json_pointer<KeyType>::value
&& is_comparable_with_object_key<KeyType>::value
&& detail::is_getable<basic_json_t, ReturnType>::value
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
ReturnType value(KeyType && key, ValueType && default_value) const
{
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if key is found, return value and given default value otherwise
const auto it = find(std::forward<KeyType>(key));
if (it != end())
{
return it->template get<ReturnType>();
} }
return std::forward<ValueType>(default_value); return std::forward<ValueType>(default_value);
@ -2268,20 +2307,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this));
} }
/// @brief access specified object element with default value
/// @sa https://json.nlohmann.me/api/basic_json/value/
/// overload for a default value of type const char*
template < class KeyType, detail::enable_if_t <
!detail::is_json_pointer<KeyType>::value, int > = 0 >
string_t value(KeyType && key, const char* default_value) const
{
return value(std::forward<KeyType>(key), string_t(default_value));
}
/// @brief access specified object element via JSON Pointer with default value /// @brief access specified object element via JSON Pointer with default value
/// @sa https://json.nlohmann.me/api/basic_json/value/ /// @sa https://json.nlohmann.me/api/basic_json/value/
template < class ValueType, detail::enable_if_t < template < class ValueType, detail::enable_if_t <
detail::is_getable<basic_json_t, ValueType>::value, int> = 0 > detail::is_getable<basic_json_t, ValueType>::value
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
ValueType value(const json_pointer& ptr, const ValueType& default_value) const ValueType value(const json_pointer& ptr, const ValueType& default_value) const
{ {
// value only works for objects // value only works for objects
@ -2301,29 +2331,50 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this));
} }
/// @brief access specified object element via JSON Pointer with default value
/// @sa https://json.nlohmann.me/api/basic_json/value/
template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
detail::enable_if_t <
detail::is_getable<basic_json_t, ReturnType>::value
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
ReturnType value(const json_pointer& ptr, ValueType && default_value) const
{
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if pointer resolves a value, return it or use default value
JSON_TRY
{
return ptr.get_checked(this).template get<ReturnType>();
}
JSON_INTERNAL_CATCH (out_of_range&)
{
return std::forward<ValueType>(default_value);
}
}
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this));
}
template < class ValueType, class BasicJsonType, detail::enable_if_t < template < class ValueType, class BasicJsonType, detail::enable_if_t <
detail::is_getable<basic_json_t, ValueType>::value, int> = 0 > detail::is_basic_json<BasicJsonType>::value
&& detail::is_getable<basic_json_t, ValueType>::value
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, const ValueType& default_value) const ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, const ValueType& default_value) const
{ {
return value(ptr.convert(), default_value); return value(ptr.convert(), default_value);
} }
/// @brief access specified object element via JSON Pointer with default value template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
/// @sa https://json.nlohmann.me/api/basic_json/value/ detail::enable_if_t <
/// overload for a default value of type const char* detail::is_basic_json<BasicJsonType>::value
JSON_HEDLEY_NON_NULL(3) && detail::is_getable<basic_json_t, ReturnType>::value
string_t value(const json_pointer& ptr, const char* default_value) const && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 >
{
return value(ptr, string_t(default_value));
}
template<typename BasicJsonType>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
JSON_HEDLEY_NON_NULL(3) ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value) const
string_t value(const typename ::nlohmann::json_pointer<BasicJsonType>& ptr, const char* default_value) const
{ {
return value(ptr.convert(), default_value); return value(ptr.convert(), std::forward<ValueType>(default_value));
} }
/// @brief access the first element /// @brief access the first element
@ -2685,9 +2736,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return ptr.contains(this); return ptr.contains(this);
} }
template<typename BasicJsonType> template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
bool contains(const typename ::nlohmann::json_pointer<BasicJsonType> ptr) const bool contains(const typename ::nlohmann::json_pointer<BasicJsonType>& ptr) const
{ {
return ptr.contains(this); return ptr.contains(this);
} }
@ -4566,7 +4617,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return ptr.get_checked(this); return ptr.get_checked(this);
} }
template<typename BasicJsonType> template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
{ {
@ -4580,7 +4631,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return ptr.get_checked(this); return ptr.get_checked(this);
} }
template<typename BasicJsonType> template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0>
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens)
const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) const const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) const
{ {

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
@ -51,7 +51,7 @@ class basic_json;
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
/// @sa https://json.nlohmann.me/api/json_pointer/ /// @sa https://json.nlohmann.me/api/json_pointer/
template<typename BasicJsonType> template<typename RefStringType>
class json_pointer; class json_pointer;
/*! /*!

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -2,7 +2,7 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
// __ _____ _____ _____ // __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ // __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.1 // | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json // |_____|_____|_____|_|___| https://github.com/nlohmann/json
// //
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>

View File

@ -1,6 +1,6 @@
project('nlohmann_json', project('nlohmann_json',
'cpp', 'cpp',
version : '3.11.1', version : '3.11.2',
license : 'MIT', license : 'MIT',
) )
@ -14,6 +14,7 @@ nlohmann_json_multiple_headers = declare_dependency(
if not meson.is_subproject() if not meson.is_subproject()
install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann')
install_headers('single_include/nlohmann/json_fwd.hpp', subdir: 'nlohmann')
pkgc = import('pkgconfig') pkgc = import('pkgconfig')
pkgc.generate(name: 'nlohmann_json', pkgc.generate(name: 'nlohmann_json',

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,7 @@ set(CPP_FILES
soloud/src/backend/alsa/soloud_alsa.cpp soloud/src/backend/alsa/soloud_alsa.cpp
soloud/src/backend/coreaudio/soloud_coreaudio.cpp soloud/src/backend/coreaudio/soloud_coreaudio.cpp
soloud/src/backend/null/soloud_null.cpp soloud/src/backend/null/soloud_null.cpp
soloud/src/backend/nosound/soloud_nosound.cpp
#soloud/src/backend/openal/soloud_openal.cpp #soloud/src/backend/openal/soloud_openal.cpp
#soloud/src/backend/openal/soloud_openal_dll.c #soloud/src/backend/openal/soloud_openal_dll.c
soloud/src/backend/opensles/soloud_opensles.cpp soloud/src/backend/opensles/soloud_opensles.cpp
@ -156,32 +157,38 @@ set(HPP_FILES
add_library(soloud ${CPP_FILES} ${HPP_FILES}) add_library(soloud ${CPP_FILES} ${HPP_FILES})
target_compile_definitions(soloud PRIVATE WITH_NULL) target_compile_definitions(soloud PRIVATE WITH_NULL)
target_compile_definitions(soloud PRIVATE WITH_NOSOUND)
#target_compile_definitions(soloud PRIVATE WITH_SDL2) #target_compile_definitions(soloud PRIVATE WITH_SDL2)
target_compile_definitions(soloud PRIVATE WITH_SDL2_STATIC) target_compile_definitions(soloud PRIVATE WITH_SDL2_STATIC)
target_include_directories(soloud SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/soloud/include") target_include_directories(soloud SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/soloud/include")
#if not android or emscripten if(EMSCRIPTEN)
if(VCPKG_TARGET_TRIPLET) target_compile_options(soloud PUBLIC -sUSE_SDL=2)
target_link_libraries(soloud SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static) target_link_libraries(soloud PUBLIC -sUSE_SDL=2)
elseif(VCPKG_TARGET_TRIPLET)
target_link_libraries(soloud
PUBLIC
SDL2::SDL2
#PRIVATE
#SDL2::SDL2main
#SDL2::SDL2-static
)
else() else()
target_include_directories(soloud PUBLIC "${SDL2_INCLUDE_DIR}") target_include_directories(soloud PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(soloud ${SDL2_LIBRARY}) target_link_libraries(soloud PUBLIC ${SDL2_LIBRARY})
endif() endif()
#if not android or emscripten
#if android #if android
#target_link_libraries(soloud SDL) #target_link_libraries(soloud SDL)
#endif #endif
if(EMSCRIPTEN)
set_target_properties(soloud PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(soloud PROPERTIES LINK_FLAGS "-s USE_SDL=2")
endif()
# TODO: remove # TODO: remove
if(UNIX) if(UNIX)
target_link_libraries(soloud target_link_libraries(soloud PUBLIC
-ldl -ldl
) )
endif() endif()

View File

@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
if(NOT EMSCRIPTEN) if(NOT EMSCRIPTEN)
add_library(tracy_client add_library(tracy_client
"${CMAKE_CURRENT_LIST_DIR}/tracy/Tracy.hpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/Tracy.hpp"
"${CMAKE_CURRENT_LIST_DIR}/tracy/TracyLua.hpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyLua.hpp"
"${CMAKE_CURRENT_LIST_DIR}/tracy/TracyVulkan.hpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyVulkan.hpp"
"${CMAKE_CURRENT_LIST_DIR}/tracy/TracyOpenGL.hpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyOpenGL.hpp"
"${CMAKE_CURRENT_LIST_DIR}/tracy/TracyClient.cpp" "${CMAKE_CURRENT_LIST_DIR}/tracy/public/TracyClient.cpp"
) )
if(TRACY_ENABLE) if(TRACY_ENABLE)
@ -18,7 +18,7 @@ if(NOT EMSCRIPTEN)
target_compile_features(tracy_client PUBLIC cxx_std_17) target_compile_features(tracy_client PUBLIC cxx_std_17)
target_include_directories(tracy_client PUBLIC "${CMAKE_CURRENT_LIST_DIR}") target_include_directories(tracy_client PUBLIC "${CMAKE_CURRENT_LIST_DIR}/tracy/public")
if(UNIX) if(UNIX)
target_link_libraries(tracy_client dl) target_link_libraries(tracy_client dl)
@ -32,7 +32,7 @@ else() # EMSCRIPTEN
target_compile_features(tracy_client INTERFACE cxx_std_17) target_compile_features(tracy_client INTERFACE cxx_std_17)
target_include_directories(tracy_client INTERFACE "${CMAKE_CURRENT_LIST_DIR}") target_include_directories(tracy_client INTERFACE "${CMAKE_CURRENT_LIST_DIR}/tracy/public")
endif() endif()

View File

@ -24,6 +24,8 @@ add_library(engine
target_include_directories(engine PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(engine PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_compile_features(engine PUBLIC cxx_std_17)
target_link_libraries(engine target_link_libraries(engine
tracy_client tracy_client
logger logger

View File

@ -69,11 +69,11 @@ void Engine::cleanup(void) {
} }
void Engine::update(void) { void Engine::update(void) {
FrameMarkStart("update") FrameMarkStart("update");
_update_strategy->doUpdate(*this); _update_strategy->doUpdate(*this);
FrameMarkEnd("update") FrameMarkEnd("update");
} }
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__

View File

@ -0,0 +1,43 @@
#pragma once
#include <mm/engine.hpp>
namespace MM::Services {
// counts X times and stops engine
// useful for automatic testing
class CountDown : public Service {
public:
CountDown(int64_t start) : _counter(start) {}
const char* name(void) override { return "CountDown"; }
bool enable(Engine&, std::vector<UpdateStrategies::TaskInfo>& task_array) override {
// add task
task_array.push_back(
UpdateStrategies::TaskInfo{"CountDown::tick"}
.phase(UpdateStrategies::update_phase_t::POST)
.fn([this](Engine& e) { this->tick(e); })
);
return true;
}
void disable(Engine&) override {}
private:
void tick(Engine& engine) {
_counter--;
if (_counter == 0) {
engine.stop();
}
}
private:
int64_t _counter = 0;
};
} // MM::Services

View File

@ -72,7 +72,7 @@ bool Sequential::disableService(const entt::id_type service_id) {
} }
void Sequential::doUpdate(MM::Engine& engine) { void Sequential::doUpdate(MM::Engine& engine) {
ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate") ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate");
// TODO: caching // TODO: caching
std::set<update_key_t> pre_tasks; std::set<update_key_t> pre_tasks;
std::set<update_key_t> main_tasks; std::set<update_key_t> main_tasks;
@ -93,22 +93,22 @@ void Sequential::doUpdate(MM::Engine& engine) {
} }
{ // pre { // pre
ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::pre") ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::pre");
doGraphSequential(engine, pre_tasks); doGraphSequential(engine, pre_tasks);
} }
{ // main { // main
ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::main") ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::main");
doGraphSequential(engine, main_tasks); doGraphSequential(engine, main_tasks);
} }
{ // post { // post
ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::post") ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::post");
doGraphSequential(engine, post_tasks); doGraphSequential(engine, post_tasks);
} }
{ // simulate async { // simulate async
ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::async") ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::async");
for (size_t i = 0; !_async_queue.empty() && i < _max_async_per_tick; i++) { for (size_t i = 0; !_async_queue.empty() && i < _max_async_per_tick; i++) {
_async_queue.back()(engine); _async_queue.back()(engine);
_async_queue.pop_back(); _async_queue.pop_back();
@ -116,7 +116,7 @@ void Sequential::doUpdate(MM::Engine& engine) {
} }
{ {
ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::deferred") ZoneScopedN("MM::UpdateStrategies::Sequential::doUpdate::deferred");
if (!_deferred_queue.empty()) { if (!_deferred_queue.empty()) {
for (auto&& fn : _deferred_queue) { for (auto&& fn : _deferred_queue) {
fn(engine); fn(engine);

View File

@ -14,7 +14,7 @@ add_library(filesystem_service
target_include_directories(filesystem_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(filesystem_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(filesystem_service target_link_libraries(filesystem_service PUBLIC
engine engine
logger logger
entt entt
@ -30,14 +30,22 @@ if(NOT MM_HEADLESS)
#endif #endif
if(EMSCRIPTEN) if(EMSCRIPTEN)
set_target_properties(filesystem_service PROPERTIES COMPILE_FLAGS "-s USE_SDL=2") target_compile_options(filesystem_service PUBLIC -sUSE_SDL=2)
set_target_properties(filesystem_service PROPERTIES LINK_FLAGS "-s USE_SDL=2") target_link_libraries(filesystem_service PUBLIC -sUSE_SDL=2)
elseif(VCPKG_TARGET_TRIPLET) elseif(VCPKG_TARGET_TRIPLET)
target_link_libraries(filesystem_service SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static) find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(filesystem_service
PUBLIC
SDL2::SDL2
SDL2::SDL2main
#SDL2::SDL2-static
)
else() else()
#if not android or emscripten #if not android or emscripten
find_package(SDL2 REQUIRED)
target_include_directories(filesystem_service PUBLIC "${SDL2_INCLUDE_DIR}") target_include_directories(filesystem_service PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(filesystem_service ${SDL2_LIBRARY}) target_link_libraries(filesystem_service PUBLIC ${SDL2_LIBRARY})
#endif #endif
endif() endif()
endif() endif()

View File

@ -33,6 +33,7 @@ bool FilesystemService::enable(Engine&, std::vector<UpdateStrategies::TaskInfo>&
return false; return false;
} }
// TODO: why exclude EMSCRIPTEN here? also wrong macro
#if !defined(MM_HEADLESS) && !defined(EMSCRIPTEN) #if !defined(MM_HEADLESS) && !defined(EMSCRIPTEN)
char* pref_path = SDL_GetPrefPath("made_of_jelly", _app_name); char* pref_path = SDL_GetPrefPath("made_of_jelly", _app_name);
#else #else
@ -197,7 +198,7 @@ FilesystemService::fs_file_t FilesystemService::open(const char* filepath, Files
phys_file = PHYSFS_openAppend(filepath); phys_file = PHYSFS_openAppend(filepath);
break; break;
default: default:
LOG_ERROR("invalid fopen mode {} for '{}'", t, filepath); LOG_ERROR("invalid fopen mode {} for '{}'", static_cast<int>(t), filepath);
return nullptr; return nullptr;
} }

View File

@ -4,6 +4,8 @@
//#include <physfs.h> //#include <physfs.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <SDL.h> // SDL_main
#include <mm/fs_const_archiver.hpp> #include <mm/fs_const_archiver.hpp>
#include <mm/logger.hpp> #include <mm/logger.hpp>

View File

@ -7,6 +7,7 @@
#include <mm/services/imgui_s.hpp> #include <mm/services/imgui_s.hpp>
#include <mm/services/imgui_menu_bar.hpp> #include <mm/services/imgui_menu_bar.hpp>
#include <mm/services/engine_tools.hpp> #include <mm/services/engine_tools.hpp>
#include <mm/services/count_down.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/opengl/render_tasks/imgui.hpp> #include <mm/opengl/render_tasks/imgui.hpp>
@ -38,10 +39,14 @@ TEST(imgui_scene_tools, it) {
rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine); rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine);
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
engine.run(); engine.run();
sdl_ss.destroyWindow(); sdl_ss.destroyWindow();
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {

View File

@ -1,4 +1,3 @@
#include "nlohmann/json_fwd.hpp"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <mm/engine.hpp> #include <mm/engine.hpp>
@ -8,6 +7,7 @@
#include <mm/services/filesystem.hpp> #include <mm/services/filesystem.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/imgui_s.hpp> #include <mm/services/imgui_s.hpp>
#include <mm/services/count_down.hpp>
#include <mm/opengl/render_tasks/imgui.hpp> #include <mm/opengl/render_tasks/imgui.hpp>
@ -183,9 +183,13 @@ TEST(imgui_json_editor, basic) {
}; };
engine.addService<TestWindow>(); // engine dtr ????????????????? engine.addService<TestWindow>(); // engine dtr ?????????????????
ASSERT_TRUE(engine.enableService<TestWindow>()); ASSERT_TRUE(engine.enableService<TestWindow>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
engine.run(); engine.run();
sdl_ss.destroyWindow(); sdl_ss.destroyWindow();

View File

@ -10,6 +10,7 @@
#include <mm/services/imgui_s.hpp> #include <mm/services/imgui_s.hpp>
#include <mm/services/imgui_menu_bar.hpp> #include <mm/services/imgui_menu_bar.hpp>
#include <mm/services/engine_tools.hpp> #include <mm/services/engine_tools.hpp>
#include <mm/services/count_down.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/opengl/render_tasks/imgui.hpp> #include <mm/opengl/render_tasks/imgui.hpp>
@ -54,6 +55,11 @@ TEST(imgui_scene_tools, it) {
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiSceneToolsService>()); ASSERT_TRUE(engine.enableService<MM::Services::ImGuiSceneToolsService>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine); rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine);
engine.run(); engine.run();

View File

@ -10,6 +10,7 @@
#include <mm/services/imgui_s.hpp> #include <mm/services/imgui_s.hpp>
#include <mm/services/imgui_menu_bar.hpp> #include <mm/services/imgui_menu_bar.hpp>
#include <mm/services/engine_tools.hpp> #include <mm/services/engine_tools.hpp>
#include <mm/services/count_down.hpp>
#include <mm/opengl/render_tasks/imgui.hpp> #include <mm/opengl/render_tasks/imgui.hpp>
@ -171,6 +172,11 @@ TEST(imgui_sound, basic) {
engine.addService<ImGuiSpeechy>(); engine.addService<ImGuiSpeechy>();
ASSERT_TRUE(engine.enableService<ImGuiSpeechy>()); ASSERT_TRUE(engine.enableService<ImGuiSpeechy>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
engine.run(); engine.run();
sdl_ss.destroyWindow(); sdl_ss.destroyWindow();

View File

@ -1,4 +1,3 @@
#include <functional>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <mm/resource_manager.hpp> #include <mm/resource_manager.hpp>
@ -11,6 +10,7 @@
#include <mm/services/imgui_s.hpp> #include <mm/services/imgui_s.hpp>
#include <mm/services/imgui_menu_bar.hpp> #include <mm/services/imgui_menu_bar.hpp>
#include <mm/services/engine_tools.hpp> #include <mm/services/engine_tools.hpp>
#include <mm/services/count_down.hpp>
#include <mm/opengl/render_tasks/imgui.hpp> #include <mm/opengl/render_tasks/imgui.hpp>
@ -19,6 +19,8 @@
#include <mm/imgui/file_text_editor.hpp> #include <mm/imgui/file_text_editor.hpp>
#include <mm/imgui/file_shader_editor.hpp> #include <mm/imgui/file_shader_editor.hpp>
#include <functional>
static char* argv0; static char* argv0;
using namespace entt::literals; using namespace entt::literals;
@ -72,6 +74,11 @@ TEST(imgui_text_edit, it) {
}); });
ASSERT_TRUE(engine.enableService<TemplateUpdateMainService>()); ASSERT_TRUE(engine.enableService<TemplateUpdateMainService>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
engine.run(); engine.run();
// TODO: clear asset manager // TODO: clear asset manager
@ -112,6 +119,12 @@ TEST(imgui_text_edit, shader) {
}); });
ASSERT_TRUE(engine.enableService<TemplateUpdateMainService>()); ASSERT_TRUE(engine.enableService<TemplateUpdateMainService>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
// TODO: fix non existant files
fte.open("shader/quad_renderer/vert.glsl"); fte.open("shader/quad_renderer/vert.glsl");
fse.open("shader/quad_renderer/frag.glsl"); fse.open("shader/quad_renderer/frag.glsl");

View File

@ -7,6 +7,7 @@
#include <mm/services/filesystem.hpp> #include <mm/services/filesystem.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/imgui_s.hpp> #include <mm/services/imgui_s.hpp>
#include <mm/services/count_down.hpp>
#include <mm/opengl/render_tasks/imgui.hpp> #include <mm/opengl/render_tasks/imgui.hpp>
@ -68,6 +69,11 @@ TEST(imgui_widgets, basic) {
engine.addService<TestWindow>(); engine.addService<TestWindow>();
ASSERT_TRUE(engine.enableService<TestWindow>()); ASSERT_TRUE(engine.enableService<TestWindow>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
engine.run(); engine.run();
sdl_ss.destroyWindow(); sdl_ss.destroyWindow();

View File

@ -15,12 +15,9 @@ target_link_libraries(input_service
sdl_service sdl_service
) )
if(EMSCRIPTEN) #if(NOT EMSCRIPTEN)
set_target_properties(input_service PROPERTIES COMPILE_FLAGS "-s USE_SDL=2") #target_include_directories(input_service PUBLIC "${SDL2_INCLUDE_DIR}")
set_target_properties(input_service PROPERTIES LINK_FLAGS "-s USE_SDL=2") #endif()
else()
target_include_directories(input_service PUBLIC "${SDL2_INCLUDE_DIR}")
endif()
if (BUILD_TESTING) if (BUILD_TESTING)
add_subdirectory(test) add_subdirectory(test)

View File

@ -29,5 +29,7 @@ target_link_libraries(input_service_visualizer_test
gtest_main gtest_main
) )
add_test(NAME input_service_visualizer_test COMMAND input_service_visualizer_test) if(NOT MM_AUTOTEST)
add_test(NAME input_service_visualizer_test COMMAND input_service_visualizer_test)
endif()

View File

@ -146,3 +146,8 @@ TEST(input_service, input_visualizer) {
sdl_ss.destroyWindow(); sdl_ss.destroyWindow();
} }
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -35,7 +35,7 @@ class tracy_sink : public ::spdlog::sinks::base_sink <Mutex> {
spdlog::memory_buf_t formatted; spdlog::memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted); base_sink<Mutex>::formatter_->format(msg, formatted);
auto string = fmt::to_string(formatted); auto string = fmt::to_string(formatted);
TracyMessageC(string.data(), string.size(), level_to_color(msg.level)) TracyMessageC(string.data(), string.size(), level_to_color(msg.level));
} }
void flush_() override { void flush_() override {

View File

@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(opengl_primitives CXX) project(opengl_primitives CXX)
file(GLOB_RECURSE CPP_FILES src/*.cpp)
file(GLOB_RECURSE HPP_FILES src/*.hpp)
add_library(opengl_primitives add_library(opengl_primitives
src/mm/opengl/buffer.hpp src/mm/opengl/buffer.hpp
src/mm/opengl/buffer.cpp src/mm/opengl/buffer.cpp
@ -31,7 +28,7 @@ add_library(opengl_primitives
target_include_directories(opengl_primitives PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(opengl_primitives PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(opengl_primitives target_link_libraries(opengl_primitives PUBLIC
glm glm
stb_image stb_image
#sdl #sdl
@ -43,14 +40,16 @@ target_link_libraries(opengl_primitives
) )
if(MM_OPENGL_3_GLES) if(MM_OPENGL_3_GLES)
target_link_libraries(opengl_primitives "GL") # TODO: make more specific target_link_libraries(opengl_primitives PUBLIC "GL") # TODO: make more specific
if(EMSCRIPTEN) if(EMSCRIPTEN)
set_target_properties(opengl_primitives PROPERTIES COMPILE_FLAGS "-s USE_WEBGL2=1 -s USE_SDL=2") # USE_SDL=2 inherited from sdl_service
set_target_properties(opengl_primitives PROPERTIES LINK_FLAGS "-s USE_WEBGL2=1 -s USE_SDL=2") # TODO: USE_WEBGL2 -> MIN_WEBGL_VERSION=2 maybe
# technically only FULL_ES3 would be needed
target_link_libraries(opengl_primitives PUBLIC -sUSE_WEBGL2=1 -sFULL_ES3=1)
endif() endif()
else() else()
target_link_libraries(opengl_primitives glad) target_link_libraries(opengl_primitives PUBLIC glad)
endif() endif()
if (BUILD_TESTING) if (BUILD_TESTING)

View File

@ -55,15 +55,16 @@ FBOBuilder& FBOBuilder::setTarget(FrameBufferObject::Target target) {
FBOBuilder& FBOBuilder::attachTexture(std::shared_ptr<Texture> tex, GLuint attachment_type) { FBOBuilder& FBOBuilder::attachTexture(std::shared_ptr<Texture> tex, GLuint attachment_type) {
GLenum target; GLenum target;
switch (_currTarget) { switch (_currTarget) {
case FrameBufferObject::Target::RW:
target = GL_FRAMEBUFFER;
break;
case FrameBufferObject::Target::R: case FrameBufferObject::Target::R:
target = GL_READ_FRAMEBUFFER; target = GL_READ_FRAMEBUFFER;
break; break;
case FrameBufferObject::Target::W: case FrameBufferObject::Target::W:
target = GL_DRAW_FRAMEBUFFER; target = GL_DRAW_FRAMEBUFFER;
break; break;
//case FrameBufferObject::Target::RW:
default:
target = GL_FRAMEBUFFER;
break;
} }
if (tex->samples == 0u) { if (tex->samples == 0u) {

View File

@ -17,7 +17,6 @@ add_library(opengl_renderer_s
target_include_directories(opengl_renderer_s PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(opengl_renderer_s PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
add_definitions(-DGLM_ENABLE_EXPERIMENTAL)
target_link_libraries(opengl_renderer_s target_link_libraries(opengl_renderer_s
engine engine
logger logger
@ -26,11 +25,6 @@ target_link_libraries(opengl_renderer_s
sdl_service sdl_service
) )
if(EMSCRIPTEN)
set_target_properties(opengl_renderer_s PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(opengl_renderer_s PROPERTIES LINK_FLAGS "-s USE_SDL=2")
endif()
############# imgui opengl renderer tools ########### ############# imgui opengl renderer tools ###########
add_library(imgui_opengl_renderer_tools add_library(imgui_opengl_renderer_tools

View File

@ -92,7 +92,7 @@ glm::vec3 Camera3D::getViewDir(void) const {
} }
std::array<glm::vec4, 6> Camera3D::getFrustumPlanes(void) const { std::array<glm::vec4, 6> Camera3D::getFrustumPlanes(void) const {
ZoneScopedN("Camera3D::getFrustumPlanes") ZoneScopedN("Camera3D::getFrustumPlanes");
std::array<glm::vec4, 6> planes; std::array<glm::vec4, 6> planes;

View File

@ -30,7 +30,7 @@ namespace MM::OpenGL::RenderTasks {
std::string color_tex {"hdr_color"}; std::string color_tex {"hdr_color"};
std::string bloom_tex {"bloom"}; std::string bloom_tex {"bloom"};
float bloom_factor {1.f}; float bloom_factor {0.8f};
void reloadShaders(MM::Engine& engine); void reloadShaders(MM::Engine& engine);

View File

@ -311,8 +311,8 @@ void LiteParticles2D::setParticleBufferSize(uint32_t new_buffer_size) {
} }
void LiteParticles2D::resetBuffers(void) { void LiteParticles2D::resetBuffers(void) {
const auto gl_buffer_type = GL_DYNAMIC_COPY;
auto reset_buffer_0 = [this](size_t i) { auto reset_buffer_0 = [this](size_t i) {
static const auto gl_buffer_type = GL_DYNAMIC_COPY;
auto* data = _particles_0_buffers[i]->map(_particle_buffer_size, gl_buffer_type); auto* data = _particles_0_buffers[i]->map(_particle_buffer_size, gl_buffer_type);
for (size_t x = 0; x < _particle_buffer_size; x++) { for (size_t x = 0; x < _particle_buffer_size; x++) {
data[x] = glm::vec4{ data[x] = glm::vec4{

View File

@ -6,6 +6,7 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/count_down.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp> #include <entt/entity/organizer.hpp>
@ -68,6 +69,11 @@ TEST(batched_spritesheet_render_task, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>(); auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.horizontalViewPortSize = 5; cam.horizontalViewPortSize = 5;
cam.setOrthographic(); cam.setOrthographic();

View File

@ -7,6 +7,7 @@
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/imgui_s.hpp> #include <mm/services/imgui_s.hpp>
#include <mm/services/count_down.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp> #include <entt/entity/organizer.hpp>
@ -64,6 +65,11 @@ TEST(blur_render_task, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
//rs.addRenderTask<MM::OpenGL::RenderTasks::SimpleRect>(engine).target_fbo = "game_view"; //rs.addRenderTask<MM::OpenGL::RenderTasks::SimpleRect>(engine).target_fbo = "game_view";
rs.addRenderTask<MM::OpenGL::RenderTasks::Clear>(engine).target_fbo = "blur_io"; rs.addRenderTask<MM::OpenGL::RenderTasks::Clear>(engine).target_fbo = "blur_io";

View File

@ -6,6 +6,7 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/count_down.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp> #include <entt/entity/organizer.hpp>
@ -39,6 +40,11 @@ TEST(fast_sky_render_task, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
rs.addRenderTask<MM::OpenGL::RenderTasks::FastSky>(engine); rs.addRenderTask<MM::OpenGL::RenderTasks::FastSky>(engine);
// setup systems // setup systems

View File

@ -6,6 +6,7 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/count_down.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp> #include <entt/entity/organizer.hpp>
@ -149,6 +150,11 @@ TEST(hdr_bloom_pipeline, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
{ // setup rendering { // setup rendering
// TODO: split vertically // TODO: split vertically
setup_textures(engine); setup_textures(engine);

View File

@ -6,6 +6,7 @@
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/imgui_s.hpp> #include <mm/services/imgui_s.hpp>
#include <mm/opengl/render_tasks/imgui.hpp> #include <mm/opengl/render_tasks/imgui.hpp>
#include <mm/services/count_down.hpp>
#include <imgui/imgui.h> #include <imgui/imgui.h>
@ -43,6 +44,11 @@ TEST(imgui_render_task, demowindow) {
rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine); rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine);
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
engine.run(); engine.run();
} }

View File

@ -6,6 +6,7 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/count_down.hpp>
#include <mm/fs_const_archiver.hpp> #include <mm/fs_const_archiver.hpp>
@ -259,6 +260,11 @@ TEST(lite_particles2d, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
// load particle types // load particle types
// before addRenderTask<LiteParticle2D> // before addRenderTask<LiteParticle2D>
// OR // OR

View File

@ -6,6 +6,7 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/count_down.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp> #include <entt/entity/organizer.hpp>
@ -49,6 +50,11 @@ TEST(simple_rect_render_task, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
rs.addRenderTask<MM::OpenGL::RenderTasks::SimpleRect>(engine); rs.addRenderTask<MM::OpenGL::RenderTasks::SimpleRect>(engine);
scene.on_construct<MM::Components::Position2D>().connect<&entt::registry::emplace_or_replace<MM::Components::Position2D_ZOffset>>(); scene.on_construct<MM::Components::Position2D>().connect<&entt::registry::emplace_or_replace<MM::Components::Position2D_ZOffset>>();

View File

@ -6,6 +6,7 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/count_down.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp> #include <entt/entity/organizer.hpp>
@ -52,6 +53,11 @@ TEST(simple_sprite_render_task, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
rs.addRenderTask<MM::OpenGL::RenderTasks::SimpleSprite>(engine); rs.addRenderTask<MM::OpenGL::RenderTasks::SimpleSprite>(engine);
scene.on_construct<MM::Components::Position2D>().connect<&entt::registry::emplace_or_replace<MM::Components::Position2D_ZOffset>>(); scene.on_construct<MM::Components::Position2D>().connect<&entt::registry::emplace_or_replace<MM::Components::Position2D_ZOffset>>();

View File

@ -6,6 +6,7 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/count_down.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp> #include <entt/entity/organizer.hpp>
@ -64,6 +65,11 @@ TEST(simple_spritesheet_render_task, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>(); auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.horizontalViewPortSize = 5; cam.horizontalViewPortSize = 5;
cam.setOrthographic(); cam.setOrthographic();
@ -136,3 +142,8 @@ TEST(simple_spritesheet_render_task, it) {
engine.run(); engine.run();
} }
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -6,6 +6,7 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/organizer_scene.hpp> #include <mm/services/organizer_scene.hpp>
#include <mm/services/opengl_renderer.hpp> #include <mm/services/opengl_renderer.hpp>
#include <mm/services/count_down.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp> #include <entt/entity/organizer.hpp>
@ -51,6 +52,11 @@ TEST(tilemap_render_task_test, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
rs.addRenderTask<MM::OpenGL::RenderTasks::Tilemap>(engine); rs.addRenderTask<MM::OpenGL::RenderTasks::Tilemap>(engine);
scene.on_construct<MM::Components::Position2D>().connect<&entt::registry::emplace_or_replace<MM::Components::Position2D_ZOffset>>(); scene.on_construct<MM::Components::Position2D>().connect<&entt::registry::emplace_or_replace<MM::Components::Position2D_ZOffset>>();
@ -121,3 +127,8 @@ TEST(tilemap_render_task_test, it) {
engine.run(); engine.run();
} }
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -12,7 +12,7 @@ add_library(sdl_service
target_include_directories(sdl_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(sdl_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_include_directories(sdl_service PUBLIC "${SDL2_INCLUDE_DIR}") target_include_directories(sdl_service PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(sdl_service target_link_libraries(sdl_service PUBLIC
entt entt
logger logger
#glm #glm
@ -25,23 +25,29 @@ target_link_libraries(sdl_service
#endif #endif
if(EMSCRIPTEN) if(EMSCRIPTEN)
set_target_properties(sdl_service PROPERTIES COMPILE_FLAGS "-s USE_SDL=2") target_compile_options(sdl_service PUBLIC -sUSE_SDL=2)
set_target_properties(sdl_service PROPERTIES LINK_FLAGS "-s USE_SDL=2") target_link_libraries(sdl_service PUBLIC -sUSE_SDL=2)
elseif(VCPKG_TARGET_TRIPLET)
find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(sdl_service
PUBLIC
SDL2::SDL2
SDL2::SDL2main
#SDL2::SDL2-static
)
else() else()
#if not android or emscripten #if not android or emscripten
find_package(SDL2 REQUIRED)
target_include_directories(sdl_service PUBLIC "${SDL2_INCLUDE_DIR}") target_include_directories(sdl_service PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(sdl_service ${SDL2_LIBRARY}) target_link_libraries(sdl_service PUBLIC ${SDL2_LIBRARY})
#endif #endif
endif() endif()
if(MM_OPENGL_3_GLES) if(MM_OPENGL_3_GLES)
target_link_libraries(sdl_service "GL") # TODO: make more specific target_link_libraries(sdl_service PRIVATE "GL") # TODO: make more specific
else() else()
target_link_libraries(sdl_service glad) target_link_libraries(sdl_service PRIVATE glad)
endif()
if(VCPKG_TARGET_TRIPLET)
target_link_libraries(sdl_service SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static)
endif() endif()
if(BUILD_TESTING) if(BUILD_TESTING)

View File

@ -152,7 +152,7 @@ bool SDLService::createGLContext(SDL_Window* win_ptr) {
TracyGpuContext; TracyGpuContext;
LOG_INFO("gl: {}", glGetString(GL_VERSION)); LOG_INFO("gl: {}", reinterpret_cast<const char*>(glGetString(GL_VERSION)));
return true; return true;
} }

View File

@ -115,3 +115,8 @@ TEST(sdl_service, event_handle_reg) {
engine.disableService<MM::Services::SDLService>(); engine.disableService<MM::Services::SDLService>();
} }
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -18,11 +18,6 @@ target_link_libraries(simple_sdl_renderer_service
sdl_service sdl_service
) )
if(EMSCRIPTEN)
set_target_properties(simple_sdl_renderer_service PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(simple_sdl_renderer_service PROPERTIES LINK_FLAGS "-s USE_SDL=2")
endif()
if (BUILD_TESTING) if (BUILD_TESTING)
add_subdirectory(test) add_subdirectory(test)
endif() endif()

View File

@ -5,6 +5,8 @@
#include <mm/services/sdl_service.hpp> #include <mm/services/sdl_service.hpp>
#include <mm/services/simple_sdl_renderer.hpp> #include <mm/services/simple_sdl_renderer.hpp>
#include <mm/services/count_down.hpp>
TEST(simple_sdl_renderer, basic) { TEST(simple_sdl_renderer, basic) {
srand(1); srand(1);
MM::Engine engine; MM::Engine engine;
@ -33,6 +35,16 @@ TEST(simple_sdl_renderer, basic) {
} }
); );
#ifdef MM_AUTOTEST
engine.addService<MM::Services::CountDown>(50); // 50 frames
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
#endif
engine.run(); engine.run();
} }
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -4,6 +4,8 @@
#include <mm/services/filesystem.hpp> #include <mm/services/filesystem.hpp>
#include <mm/soloud_filesystem_file_impl.hpp> #include <mm/soloud_filesystem_file_impl.hpp>
#include <SDL.h> // SDL_main
#include <soloud_wav.h> #include <soloud_wav.h>
#include <soloud_wavstream.h> #include <soloud_wavstream.h>
#include <soloud_monotone.h> #include <soloud_monotone.h>

View File

@ -6,6 +6,8 @@ add_library(std_utils INTERFACE)
target_include_directories(std_utils INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(std_utils INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_compile_features(std_utils INTERFACE cxx_std_17)
############################## ##############################
# curr only scalar_range # curr only scalar_range
@ -13,6 +15,8 @@ add_library(std_utils_serialize INTERFACE)
target_include_directories(std_utils_serialize INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") target_include_directories(std_utils_serialize INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_compile_features(std_utils_serialize INTERFACE cxx_std_17)
target_link_libraries(std_utils_serialize INTERFACE target_link_libraries(std_utils_serialize INTERFACE
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
) )

Some files were not shown because too many files have changed in this diff Show More