diff --git a/Makefile b/Makefile index 04bbb48d..9a8e220b 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ UF_LIBS = # EXT_LIBS = -lpng16 -lz -lassimp -lsfml-main -lsfml-system -lsfml-window -lsfml-graphics -llua52 # EXT_LIBS = -lpng16 -lz -lassimp -ljsoncpp -lopenal32 -lalut -lvorbis -lvorbisfile -logg -lfreetype EXT_LIBS = -#FLAGS = -std=c++0x -Wall -g -DUF_USE_JSON -DUF_USE_NCURSES -DUF_USE_OPENGL -DUF_USE_GLEW +#FLAGS = -Og -DUF_DISABLE_ALIGNAS -std=c++20 -Wno-c++11-narrowing -Wno-narrowing -g -DVK_USE_PLATFORM_WIN32_KHR -DUF_USE_VULKAN -DGLM_ENABLE_EXPERIMENTAL -DUF_USE_JSON -DUF_USE_NCURSES -DUF_USE_OPENAL -DUF_USE_VORBIS -DUF_USE_FREETYPE -DUSE_OPENVR_MINGW FLAGS = -std=c++20 -Wno-c++11-narrowing -Wno-narrowing -g -DVK_USE_PLATFORM_WIN32_KHR -DUF_USE_VULKAN -DGLM_ENABLE_EXPERIMENTAL -DUF_USE_JSON -DUF_USE_NCURSES -DUF_USE_OPENAL -DUF_USE_VORBIS -DUF_USE_FREETYPE -DUSE_OPENVR_MINGW #-march=native LIB_NAME = uf diff --git a/bin/data/shaders/base.frag.glsl b/bin/data/shaders/base.frag.glsl index c87cec11..3277d475 100644 --- a/bin/data/shaders/base.frag.glsl +++ b/bin/data/shaders/base.frag.glsl @@ -3,19 +3,20 @@ layout (binding = 1) uniform sampler2D samplerColor; layout (location = 0) in vec2 inUv; -layout (location = 1) in vec3 inPosition; +layout (location = 1) in vec4 inColor; layout (location = 2) in vec3 inNormal; -layout (location = 3) in vec4 inColor; +layout (location = 3) in vec3 inPosition; layout (location = 0) out vec4 outAlbedoSpecular; -layout (location = 1) out vec4 outPosition; -layout (location = 2) out vec4 outNormal; +layout (location = 1) out vec4 outNormal; +layout (location = 2) out vec4 outPosition; void main() { outAlbedoSpecular = texture(samplerColor, inUv); if ( outAlbedoSpecular.a < 0.001 ) discard; outAlbedoSpecular.rgb *= inColor.rgb; outAlbedoSpecular.a = 1; -// outPosition = vec4(inPosition, 1.0); -// outNormal = vec4(normalize(inNormal), 1.0); + + outNormal = vec4(inNormal,1); + outPosition = vec4(inPosition,1); } \ No newline at end of file diff --git a/bin/data/shaders/base.stereo.vert.glsl b/bin/data/shaders/base.stereo.vert.glsl index 0b0af656..18a8318b 100644 --- a/bin/data/shaders/base.stereo.vert.glsl +++ b/bin/data/shaders/base.stereo.vert.glsl @@ -20,9 +20,9 @@ layout (binding = 0) uniform UBO { } ubo; layout (location = 0) out vec2 outUv; -layout (location = 1) out vec3 outPosition; +layout (location = 1) out vec4 outColor; layout (location = 2) out vec3 outNormal; -layout (location = 3) out vec4 outColor; +layout (location = 3) out vec3 outPosition; out gl_PerVertex { vec4 gl_Position; @@ -35,9 +35,7 @@ void main() { outPosition = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0)); outNormal = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inNormal.xyz, 0.0)); - -// outPosition = vec3(ubo.matrices.model * vec4(inPos.xyz, 1.0)); -// outNormal = vec3(ubo.matrices.model * vec4(inNormal.xyz, 0.0)); + outNormal = normalize(outNormal); gl_Position = ubo.matrices.projection[PushConstant.pass] * ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0); } \ No newline at end of file diff --git a/bin/data/shaders/base.vert.glsl b/bin/data/shaders/base.vert.glsl deleted file mode 100644 index 1bb77302..00000000 --- a/bin/data/shaders/base.vert.glsl +++ /dev/null @@ -1,39 +0,0 @@ -#version 450 - -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec2 inUv; -layout (location = 2) in vec3 inNormal; - -layout( push_constant ) uniform PushBlock { - uint pass; -} PushConstant; - -struct Matrices { - mat4 model; - mat4 view[2]; - mat4 projection[2]; -}; - -layout (binding = 0) uniform UBO { - Matrices matrices; - vec4 color; -} ubo; - -layout (location = 0) out vec2 outUv; -layout (location = 1) out vec3 outPositionEye; -layout (location = 2) out vec3 outNormalEye; -layout (location = 3) out vec4 outColor; - -out gl_PerVertex { - vec4 gl_Position; -}; - - -void main() { - outUv = inUv; - outPositionEye = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0)); - outNormalEye = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inNormal.xyz, 0.0)); - outColor = ubo.color; - - gl_Position = ubo.matrices.projection[PushConstant.pass] * ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0); -} \ No newline at end of file diff --git a/bin/data/shaders/display.frag.glsl b/bin/data/shaders/display.frag.glsl deleted file mode 100644 index 1ca52c32..00000000 --- a/bin/data/shaders/display.frag.glsl +++ /dev/null @@ -1,10 +0,0 @@ -#version 450 - -layout (input_attachment_index = 0, binding = 1) uniform subpassInput samplerOutput; - -layout (location = 0) in vec2 inUv; -layout (location = 0) out vec4 outFragColor; - -void main() { - outFragColor = subpassLoad(samplerOutput); -} \ No newline at end of file diff --git a/bin/data/shaders/display.rendertarget.frag.glsl b/bin/data/shaders/display.rendertarget.frag.glsl index 00d969ef..641f6d2d 100644 --- a/bin/data/shaders/display.rendertarget.frag.glsl +++ b/bin/data/shaders/display.rendertarget.frag.glsl @@ -3,8 +3,7 @@ layout (binding = 1) uniform sampler samp; layout (binding = 2) uniform texture2D albedoTexture; -layout (binding = 3) uniform texture2D positionTexture; -layout (binding = 4) uniform texture2D normalTexture; +layout (binding = 3) uniform texture2D normalTexture; struct Cursor { vec2 position; @@ -17,8 +16,7 @@ layout (location = 1) in float inAlpha; layout (location = 2) in Cursor inCursor; layout (location = 0) out vec4 outAlbedoSpecular; -layout (location = 1) out vec4 outPosition; -layout (location = 2) out vec4 outNormal; +layout (location = 1) out vec4 outNormal; void main() { outAlbedoSpecular = texture(sampler2D(albedoTexture, samp), inUv); @@ -26,7 +24,6 @@ void main() { vec2 uv = gl_FragCoord.xy / textureSize(albedoTexture, 0); // uv.x = 1-uv.x; outAlbedoSpecular = texture(sampler2D(albedoTexture, samp), uv); - outPosition = texture(sampler2D(positionTexture, samp), uv); outNormal = texture(sampler2D(normalTexture, samp), uv); if ( outAlbedoSpecular.a < 0.01f ) outAlbedoSpecular = vec4(0,0,0,1); return; diff --git a/bin/data/shaders/display.rendertarget.vert.glsl b/bin/data/shaders/display.rendertarget.vert.glsl index 7ee36239..651c07f7 100644 --- a/bin/data/shaders/display.rendertarget.vert.glsl +++ b/bin/data/shaders/display.rendertarget.vert.glsl @@ -27,7 +27,7 @@ struct Matrices { layout (binding = 0) uniform UBO { Matrices matrices; Cursor cursor; - float alpha; + vec2 alpha; } ubo; void main() { diff --git a/bin/data/shaders/display.subpass.frag.glsl b/bin/data/shaders/display.subpass.frag.glsl index 39df87b0..609843a7 100644 --- a/bin/data/shaders/display.subpass.frag.glsl +++ b/bin/data/shaders/display.subpass.frag.glsl @@ -1,22 +1,29 @@ #version 450 +#define BASE_LIGHTS_SIZE 16 +layout (constant_id = 0) const uint LIGHTS = BASE_LIGHTS_SIZE; + layout (input_attachment_index = 0, binding = 1) uniform subpassInput samplerAlbedo; -layout (input_attachment_index = 0, binding = 2) uniform subpassInput samplerPosition; -layout (input_attachment_index = 0, binding = 3) uniform subpassInput samplerNormal; -layout (input_attachment_index = 0, binding = 4) uniform subpassInput samplerDepth; +layout (input_attachment_index = 0, binding = 2) uniform subpassInput samplerNormal; +layout (input_attachment_index = 0, binding = 3) uniform subpassInput samplerPosition; +// layout (input_attachment_index = 0, binding = 4) uniform subpassInput samplerDepth; +layout (binding = 5) uniform sampler2D samplerShadows[BASE_LIGHTS_SIZE]; layout (location = 0) in vec2 inUv; layout (location = 1) in flat uint inPushConstantPass; layout (location = 0) out vec4 outFragColor; -layout (constant_id = 0) const uint LIGHTS = 32; struct Light { vec3 position; float power; vec3 color; float radius; + int type; + int shadowed; + mat4 view; + mat4 projection; }; struct Matrices { @@ -78,31 +85,117 @@ void phong( Light light, vec4 albedoSpecular, inout vec3 i ) { i += Id * light.power; } +bool debugShadow( Light light, uint i ) { + return false; + + vec4 positionClip = light.projection * light.view * vec4(position.world, 1.0); + positionClip.xyz /= positionClip.w; + float lightDepth = texture(samplerShadows[i], positionClip.xy * 0.5 + 0.5).r; + + float eyeDepth = positionClip.z; + eyeDepth = lightDepth; + float bias = 0.0005; + + if ( positionClip.x < -1 || positionClip.x >= 1 ) eyeDepth = 1; + else if ( positionClip.y < -1 || positionClip.y >= 1 ) eyeDepth = 1; + else if ( positionClip.z < 0 || positionClip.z >= 1 ) eyeDepth = 1; + // else eyeDepth /= 0.00526; + + outFragColor.rgb = vec3( 1 - eyeDepth ); + outFragColor.a = 1; + + return true; +} + +float shadowFactor( Light light, uint i ) { + vec4 positionClip = light.projection * light.view * vec4(position.world, 1.0); + positionClip.xyz /= positionClip.w; + float lightDepth = texture(samplerShadows[i], positionClip.xy * 0.5 + 0.5).r; + float eyeDepth = positionClip.z; + float bias = 0.0005; + // bias = max(0.05 * (1.0 - dot(normal.eye, light.position.xyz - position.eye)), bias); + +// eyeDepth /= 0.00526; +// lightDepth /= 0.00526; + + eyeDepth = 1 - eyeDepth; + lightDepth = 1 - lightDepth; + + if ( positionClip.x < -1 || positionClip.x >= 1 ) return 0.0; + if ( positionClip.y < -1 || positionClip.y >= 1 ) return 0.0; + if ( positionClip.z < 0 || positionClip.z >= 1 ) return 0.0; + + return eyeDepth - bias < lightDepth ? 1.0 : 0.0; +} + void main() { vec4 albedoSpecular = subpassLoad(samplerAlbedo); - position.eye = subpassLoad(samplerPosition).rgb; normal.eye = subpassLoad(samplerNormal).rgb; + position.eye = subpassLoad(samplerPosition).rgb; { - float depth = subpassLoad(samplerDepth).r; + mat4 iView = inverse( ubo.matrices.view[inPushConstantPass] ); + vec4 positionWorld = iView * vec4(position.eye, 1); + position.world = positionWorld.xyz; + } +/* + { mat4 iProj = inverse( ubo.matrices.projection[inPushConstantPass] ); + mat4 iView = inverse( ubo.matrices.view[inPushConstantPass] ); + + float depth = subpassLoad(samplerDepth).r; + + if ( false ) { + depth /= 0.00526; + outFragColor.rgb = vec3( 1 - depth ); + outFragColor.a = 1; + return; + } + vec4 positionClip = vec4(inUv * 2.0 - 1.0, depth, 1.0); - positionClip.y *= -1; vec4 positionEye = iProj * positionClip; positionEye /= positionEye.w; position.eye = positionEye.xyz; + + vec4 positionWorld = iView * positionEye; + position.world = positionWorld.xyz; } +*/ vec3 fragColor = albedoSpecular.rgb * ubo.ambient.rgb; bool lit = false; for ( uint i = 0; i < LIGHTS; ++i ) { Light light = ubo.lights[i]; + if ( light.power <= 0.001 ) continue; lit = true; + light.position.xyz = vec3(ubo.matrices.view[inPushConstantPass] * vec4(light.position.xyz, 1)); + + if ( light.shadowed > 0 ) { + float shadowFactor = shadowFactor( light, i ); + if ( shadowFactor <= 0.0001 ) continue; + } phong( light, albedoSpecular, fragColor ); } + if ( !lit ) fragColor = albedoSpecular.rgb; + fog(fragColor); + outFragColor = vec4(fragColor,1); +/* + if ( !false ) { + float depth = texture(samplerShadows[0], inUv).r; + depth /= 0.00526; + outFragColor = vec4( vec3(1 - depth), 1 ); + return; + } else if ( !false ) { + outFragColor = vec4( texture(samplerShadows[0], inUv).rgb, 1 ); + return; + } else { + outFragColor = vec4( inUv.x, 0, inUv.y, 1 ); + return; + } +*/ } \ No newline at end of file diff --git a/bin/data/shaders/heightmap.frag.glsl b/bin/data/shaders/heightmap.frag.glsl index 77e8fd76..7aa5d840 100644 --- a/bin/data/shaders/heightmap.frag.glsl +++ b/bin/data/shaders/heightmap.frag.glsl @@ -3,19 +3,17 @@ layout (binding = 1) uniform sampler2D samplerColor; layout (location = 0) in vec2 inUv; -layout (location = 1) in vec3 inPosition; -layout (location = 2) in vec3 inNormal; -layout (location = 3) in vec4 inColor; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec4 inColor; layout (location = 0) out vec4 outAlbedoSpecular; -layout (location = 1) out vec4 outPosition; -layout (location = 2) out vec4 outNormal; +layout (location = 1) out vec4 outNormal; void main() { outAlbedoSpecular = texture(samplerColor, inUv); outAlbedoSpecular = vec4(1,1,1,1); outAlbedoSpecular.rgb *= inColor.rgb; outAlbedoSpecular.a = 1; - outPosition = vec4(inPosition, 1.0); +// outPosition = vec4(inPosition, 1.0); outNormal = vec4(normalize(inNormal), 1.0); } \ No newline at end of file diff --git a/bin/data/shaders/heightmap.stereo.vert.glsl b/bin/data/shaders/heightmap.stereo.vert.glsl index bca53477..692ac3b2 100644 --- a/bin/data/shaders/heightmap.stereo.vert.glsl +++ b/bin/data/shaders/heightmap.stereo.vert.glsl @@ -21,9 +21,8 @@ layout (binding = 0) uniform UBO { } ubo; layout (location = 0) out vec2 outUv; -layout (location = 1) out vec3 outPosition; -layout (location = 2) out vec3 outNormal; -layout (location = 3) out vec4 outColor; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec4 outColor; out gl_PerVertex { vec4 gl_Position; @@ -34,7 +33,7 @@ void main() { outUv = inUv; // outColor = ubo.color; - outPosition = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0)); +// outPosition = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0)); outNormal = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inNormal.xyz, 0.0)); // outPosition = vec3(ubo.matrices.model * vec4(inPos.xyz, 1.0)); diff --git a/bin/data/shaders/line.frag.glsl b/bin/data/shaders/line.frag.glsl index 20964f0d..b996dd27 100644 --- a/bin/data/shaders/line.frag.glsl +++ b/bin/data/shaders/line.frag.glsl @@ -1,7 +1,6 @@ #version 450 -layout (location = 0) in vec3 inPosition; -layout (location = 1) in vec3 inColor; +layout (location = 0) in vec3 inColor; layout (location = 0) out vec4 outAlbedoSpecular; diff --git a/bin/data/shaders/line.stereo.vert.glsl b/bin/data/shaders/line.stereo.vert.glsl index 863f2b34..45f26062 100644 --- a/bin/data/shaders/line.stereo.vert.glsl +++ b/bin/data/shaders/line.stereo.vert.glsl @@ -17,8 +17,7 @@ layout (binding = 0) uniform UBO { vec4 color; } ubo; -layout (location = 0) out vec3 outPosition; -layout (location = 1) out vec4 outColor; +layout (location = 0) out vec4 outColor; out gl_PerVertex { vec4 gl_Position; @@ -28,7 +27,7 @@ out gl_PerVertex { void main() { outColor = ubo.color; - outPosition = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0)); +// outPosition = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0)); gl_Position = ubo.matrices.projection[PushConstant.pass] * ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0); } \ No newline at end of file diff --git a/bin/data/shaders/terrain.frag.glsl b/bin/data/shaders/terrain.frag.glsl index db1e9385..cfe7cd4b 100644 --- a/bin/data/shaders/terrain.frag.glsl +++ b/bin/data/shaders/terrain.frag.glsl @@ -3,18 +3,18 @@ layout (binding = 1) uniform sampler2D samplerColor; layout (location = 0) in vec2 inUv; -layout (location = 1) in vec3 inPosition; +layout (location = 1) in vec4 inColor; layout (location = 2) in vec3 inNormal; -layout (location = 3) in vec4 inColor; +layout (location = 3) in vec3 inPosition; layout (location = 0) out vec4 outAlbedoSpecular; -layout (location = 1) out vec4 outPosition; -layout (location = 2) out vec4 outNormal; +layout (location = 1) out vec4 outNormal; +layout (location = 2) out vec4 outPosition; void main() { outAlbedoSpecular = texture(samplerColor, inUv); - outAlbedoSpecular.rgb *= inColor.rgb; + // outAlbedoSpecular.rgb *= inColor.rgb; outAlbedoSpecular.a = 1; - outPosition = vec4(inPosition, 1.0); - outNormal = vec4(normalize(inNormal), 1.0); + outNormal = vec4(inNormal,1); + outPosition = vec4(inPosition,1); } \ No newline at end of file diff --git a/bin/data/shaders/terrain.stereo.vert.glsl b/bin/data/shaders/terrain.stereo.vert.glsl index bca53477..2740f83b 100644 --- a/bin/data/shaders/terrain.stereo.vert.glsl +++ b/bin/data/shaders/terrain.stereo.vert.glsl @@ -21,9 +21,9 @@ layout (binding = 0) uniform UBO { } ubo; layout (location = 0) out vec2 outUv; -layout (location = 1) out vec3 outPosition; +layout (location = 1) out vec4 outColor; layout (location = 2) out vec3 outNormal; -layout (location = 3) out vec4 outColor; +layout (location = 3) out vec3 outPosition; out gl_PerVertex { vec4 gl_Position; @@ -36,9 +36,7 @@ void main() { outPosition = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0)); outNormal = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inNormal.xyz, 0.0)); - -// outPosition = vec3(ubo.matrices.model * vec4(inPos.xyz, 1.0)); -// outNormal = vec3(ubo.matrices.model * vec4(inNormal.xyz, 0.0)); + outNormal = normalize(outNormal); outColor.a = (inColor >> 24u) & 0xFF; outColor.b = (inColor >> 16u) & 0xFF; diff --git a/bin/data/shaders/terrain.vert.glsl b/bin/data/shaders/terrain.vert.glsl deleted file mode 100644 index 8b88188a..00000000 --- a/bin/data/shaders/terrain.vert.glsl +++ /dev/null @@ -1,47 +0,0 @@ -#version 450 - -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec2 inUv; -layout (location = 2) in vec3 inNormal; -layout (location = 3) in uint inColor; - -layout( push_constant ) uniform PushBlock { - uint pass; -} PushConstant; - -struct Matrices { - mat4 model; - mat4 view[2]; - mat4 projection[2]; -}; - -layout (binding = 0) uniform UBO { - Matrices matrices; - vec4 color; -} ubo; - -layout (location = 0) out vec2 outUv; -layout (location = 1) out vec3 outPositionEye; -layout (location = 2) out vec3 outNormalEye; -layout (location = 3) out vec4 outColor; - -out gl_PerVertex { - vec4 gl_Position; -}; - - -void main() { - outUv = inUv; - outPositionEye = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0)); - outNormalEye = vec3(ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inNormal.xyz, 0.0)); -// outColor = ubo.color; - - outColor.a = (inColor >> 24u) & 0xFF; - outColor.b = (inColor >> 16u) & 0xFF; - outColor.g = (inColor >> 8u) & 0xFF; - outColor.r = (inColor ) & 0xFF; - outColor.rgb /= 256.0; - outColor.a = 0.5; - - gl_Position = ubo.matrices.projection[PushConstant.pass] * ubo.matrices.view[PushConstant.pass] * ubo.matrices.model * vec4(inPos.xyz, 1.0); -} \ No newline at end of file diff --git a/engine/inc/gltf/json.hpp b/engine/inc/gltf/json.hpp new file mode 100644 index 00000000..c9af0bed --- /dev/null +++ b/engine/inc/gltf/json.hpp @@ -0,0 +1,20406 @@ +/* + __ _____ _____ _____ + __| | __| | | | JSON for Modern C++ +| | |__ | | | | | | version 3.5.0 +|_____|_____|_____|_|___| https://github.com/nlohmann/json + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2013-2018 Niels Lohmann . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef NLOHMANN_JSON_HPP +#define NLOHMANN_JSON_HPP + +#define NLOHMANN_JSON_VERSION_MAJOR 3 +#define NLOHMANN_JSON_VERSION_MINOR 5 +#define NLOHMANN_JSON_VERSION_PATCH 0 + +#include // all_of, find, for_each +#include // assert +#include // and, not, or +#include // nullptr_t, ptrdiff_t, size_t +#include // hash, less +#include // initializer_list +#include // istream, ostream +#include // random_access_iterator_tag +#include // accumulate +#include // string, stoi, to_string +#include // declval, forward, move, pair, swap + +// #include +#ifndef NLOHMANN_JSON_FWD_HPP +#define NLOHMANN_JSON_FWD_HPP + +#include // int64_t, uint64_t +#include // map +#include // allocator +#include // string +#include // vector + +/*! +@brief namespace for Niels Lohmann +@see https://github.com/nlohmann +@since version 1.0.0 +*/ +namespace nlohmann +{ +/*! +@brief default JSONSerializer template argument + +This serializer ignores the template arguments and uses ADL +([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) +for serialization. +*/ +template +struct adl_serializer; + +template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer> +class basic_json; + +/*! +@brief JSON Pointer + +A JSON pointer defines a string syntax for identifying a specific value +within a JSON document. It can be used with functions `at` and +`operator[]`. Furthermore, JSON pointers are the base for JSON patches. + +@sa [RFC 6901](https://tools.ietf.org/html/rfc6901) + +@since version 2.0.0 +*/ +template +class json_pointer; + +/*! +@brief default JSON class + +This type is the default specialization of the @ref basic_json class which +uses the standard template types. + +@since version 1.0.0 +*/ +using json = basic_json<>; +} // namespace nlohmann + +#endif + +// #include + + +// This file contains all internal macro definitions +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them + +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif + +// disable float-equal warnings on GCC/clang +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + +// disable documentation warnings on clang +#if defined(__clang__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdocumentation" +#endif + +// allow for portable deprecation warnings +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #define JSON_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) + #define JSON_DEPRECATED __declspec(deprecated) +#else + #define JSON_DEPRECATED +#endif + +// allow to disable exceptions +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) + #define JSON_THROW(exception) throw exception + #define JSON_TRY try + #define JSON_CATCH(exception) catch(exception) + #define JSON_INTERNAL_CATCH(exception) catch(exception) +#else + #define JSON_THROW(exception) std::abort() + #define JSON_TRY if(true) + #define JSON_CATCH(exception) if(false) + #define JSON_INTERNAL_CATCH(exception) if(false) +#endif + +// override exception macros +#if defined(JSON_THROW_USER) + #undef JSON_THROW + #define JSON_THROW JSON_THROW_USER +#endif +#if defined(JSON_TRY_USER) + #undef JSON_TRY + #define JSON_TRY JSON_TRY_USER +#endif +#if defined(JSON_CATCH_USER) + #undef JSON_CATCH + #define JSON_CATCH JSON_CATCH_USER + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_CATCH_USER +#endif +#if defined(JSON_INTERNAL_CATCH_USER) + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER +#endif + +// manual branch prediction +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #define JSON_LIKELY(x) __builtin_expect(!!(x), 1) + #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else + #define JSON_LIKELY(x) x + #define JSON_UNLIKELY(x) x +#endif + +// C++ language standard detection +#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 +#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 +#endif + +/*! +@brief macro to briefly define a mapping between an enum and JSON +@def NLOHMANN_JSON_SERIALIZE_ENUM +@since version 3.4.0 +*/ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [e](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [j](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ + } + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + +// #include + + +#include // not +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type + +namespace nlohmann +{ +namespace detail +{ +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + +template +using uncvref_t = typename std::remove_cv::type>::type; + +// implementation of C++14 index_sequence and affiliates +// source: https://stackoverflow.com/a/32223343 +template +struct index_sequence +{ + using type = index_sequence; + using value_type = std::size_t; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +template +struct merge_and_renumber; + +template +struct merge_and_renumber, index_sequence> + : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; + +template +struct make_index_sequence + : merge_and_renumber < typename make_index_sequence < N / 2 >::type, + typename make_index_sequence < N - N / 2 >::type > {}; + +template<> struct make_index_sequence<0> : index_sequence<> {}; +template<> struct make_index_sequence<1> : index_sequence<0> {}; + +template +using index_sequence_for = make_index_sequence; + +// dispatch utility (taken from ranges-v3) +template struct priority_tag : priority_tag < N - 1 > {}; +template<> struct priority_tag<0> {}; + +// taken from ranges-v3 +template +struct static_const +{ + static constexpr T value{}; +}; + +template +constexpr T static_const::value; +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // not +#include // numeric_limits +#include // false_type, is_constructible, is_integral, is_same, true_type +#include // declval + +// #include + +// #include + + +#include // random_access_iterator_tag + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; +} // namespace detail +} // namespace nlohmann + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template +struct iterator_types {}; + +template +struct iterator_types < + It, + void_t> +{ + using difference_type = typename It::difference_type; + using value_type = typename It::value_type; + using pointer = typename It::pointer; + using reference = typename It::reference; + using iterator_category = typename It::iterator_category; +}; + +// This is required as some compilers implement std::iterator_traits in a way that +// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. +template +struct iterator_traits +{ +}; + +template +struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> + : iterator_types +{ +}; + +template +struct iterator_traits::value>> +{ + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T*; + using reference = T&; +}; +} +} + +// #include + +// #include + + +#include + +// #include + + +// http://en.cppreference.com/w/cpp/experimental/is_detected +namespace nlohmann +{ +namespace detail +{ +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + void operator=(nonesuch const&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template