├── src ├── ecs.nim ├── strpool.nim ├── physics.nim ├── shaders │ ├── leb_init.sgs │ ├── leb_update.sgs │ ├── leb_update_draw.sgs │ ├── terrain_batcher.sgs │ ├── terrain_render.sgs │ ├── cbt_sum_reduction.sgs │ ├── heightmap_terrain.sgs │ ├── leb_update_merge.sgs │ ├── leb_update_split.sgs │ ├── terrain_update_merge.sgs │ ├── cbt_sum_reduction_prepass.sgs │ ├── skinned_mesh.frag │ ├── wire.frag │ ├── nuklear.frag │ ├── box.frag │ ├── wire.vert │ ├── viewer.vert │ ├── nuklear.vert │ ├── basic.vert │ ├── basic.frag │ ├── cbt_sum_reduction.comp │ ├── terrain_batcher.comp │ ├── heightmap_terrain.vert │ ├── viewer.frag │ ├── leb_init.comp │ ├── leb_update_merge.comp │ ├── terrain.frag │ ├── leb_update.comp │ ├── leb_update_draw.comp │ ├── box.vert │ ├── terrain_render.frag │ ├── leb_update_split.comp │ └── terrain.vert ├── asm │ ├── jump_x86_64_ms_pe_gas.S.o │ ├── jump_x86_64_ms_pe_masm.o │ ├── make_x86_64_ms_pe_gas.S.o │ ├── make_x86_64_ms_pe_masm.o │ ├── ontop_x86_64_ms_pe_gas.S.o │ ├── ontop_x86_64_ms_pe_masm.o │ ├── jump_i386_x86_64_sysv_macho_gas.S │ ├── jump_ppc32_ppc64_sysv_macho_gas.S │ ├── make_i386_x86_64_sysv_macho_gas.S │ ├── make_ppc32_ppc64_sysv_macho_gas.S │ ├── ontop_ppc32_ppc64_sysv_macho_gas.S │ ├── ontop_i386_x86_64_sysv_macho_gas.S │ ├── tail_ppc32_sysv_elf_gas.cpp │ ├── jump_combined_sysv_macho_gas.S │ ├── make_combined_sysv_macho_gas.S │ ├── ontop_combined_sysv_macho_gas.S │ ├── jump_combined_all_macho_gas.S │ ├── make_combined_all_macho_gas.S │ ├── ontop_combined_all_macho_gas.S │ ├── make_ppc64_sysv_xcoff_gas.S │ └── ontop_ppc64_sysv_xcoff_gas.S ├── frag.nim ├── terrain.nim ├── animation.nim ├── config.nim ├── foo.c ├── fuse.nim ├── platform.nim ├── imgui.nim ├── three_d.nim ├── terrain_plugin.nim └── config.nims ├── thirdparty ├── config.nims ├── cbt.c ├── leb.c ├── hmm.c ├── cr.cpp ├── stb_image.c ├── leb.nim ├── nuklear.c ├── Jolt │ ├── ObjectStream │ │ ├── SerializableObject.cpp │ │ ├── ObjectStreamTypes.h │ │ ├── GetPrimitiveTypeOfType.h │ │ ├── ObjectStream.cpp │ │ ├── TypeDeclarations.h │ │ ├── SerializableAttributeTyped.h │ │ ├── TypeDeclarations.cpp │ │ ├── SerializableAttributeEnum.h │ │ ├── ObjectStreamTextIn.h │ │ └── ObjectStreamBinaryIn.h │ ├── Physics │ │ ├── PhysicsLock.cpp │ │ ├── DeterminismLog.cpp │ │ ├── Collision │ │ │ ├── BroadPhase │ │ │ │ └── BroadPhase.cpp │ │ │ ├── CollectFacesMode.h │ │ │ ├── BackFaceMode.h │ │ │ ├── AABoxCast.h │ │ │ ├── ActiveEdgeMode.h │ │ │ ├── CollidePointResult.h │ │ │ ├── CollisionGroup.cpp │ │ │ ├── GroupFilterTable.cpp │ │ │ ├── PhysicsMaterialSimple.cpp │ │ │ ├── CastResult.h │ │ │ ├── ShapeFilter.h │ │ │ ├── PhysicsMaterialSimple.h │ │ │ ├── GroupFilter.h │ │ │ ├── PhysicsMaterial.cpp │ │ │ ├── GroupFilter.cpp │ │ │ ├── SortReverseAndStore.h │ │ │ ├── PhysicsMaterial.h │ │ │ └── NarrowPhaseStats.cpp │ │ ├── Body │ │ │ ├── MotionType.h │ │ │ ├── BodyAccess.cpp │ │ │ ├── BodyActivationListener.h │ │ │ ├── BodyPair.h │ │ │ ├── BodyAccess.h │ │ │ ├── MotionProperties.cpp │ │ │ ├── MotionQuality.h │ │ │ └── MassProperties.h │ │ ├── EActivation.h │ │ ├── Vehicle │ │ │ ├── VehicleController.cpp │ │ │ ├── VehicleAntiRollBar.cpp │ │ │ ├── VehicleAntiRollBar.h │ │ │ ├── VehicleTrack.cpp │ │ │ └── VehicleTrack.h │ │ ├── PhysicsUpdateContext.cpp │ │ ├── PhysicsStepListener.h │ │ ├── Constraints │ │ │ ├── MotorSettings.cpp │ │ │ ├── TwoBodyConstraint.cpp │ │ │ └── PathConstraintPathHermite.h │ │ ├── StateRecorder.h │ │ ├── Character │ │ │ └── CharacterBase.cpp │ │ └── StateRecorderImpl.h │ ├── RegisterTypes.h │ ├── Core │ │ ├── NonCopyable.h │ │ ├── UnorderedSet.h │ │ ├── UnorderedMap.h │ │ ├── IssueReporting.cpp │ │ ├── FPFlushDenormals.h │ │ ├── LinearCurve.cpp │ │ ├── Factory.h │ │ ├── Atomics.h │ │ ├── TickCounter.h │ │ ├── STLAlignedAllocator.h │ │ ├── StreamWrapper.h │ │ ├── InsertionSort.h │ │ ├── Semaphore.h │ │ ├── IssueReporting.h │ │ ├── StringTools.h │ │ ├── Memory.cpp │ │ ├── STLTempAllocator.h │ │ ├── Color.cpp │ │ ├── ByteBuffer.h │ │ ├── StreamOut.h │ │ ├── LinearCurve.h │ │ ├── Semaphore.cpp │ │ └── JobSystem.inl │ ├── Jolt.h │ ├── Math │ │ ├── UVec4.cpp │ │ ├── Swizzle.h │ │ ├── MathTypes.h │ │ ├── Float4.h │ │ ├── DynMatrix.h │ │ ├── Float2.h │ │ ├── Real.h │ │ ├── FindRoot.h │ │ ├── Double3.h │ │ ├── Float3.h │ │ ├── Trigonometry.h │ │ └── Vec3.cpp │ ├── TriangleGrouper │ │ ├── TriangleGrouperMorton.h │ │ ├── TriangleGrouperClosestCentroid.h │ │ ├── TriangleGrouper.h │ │ └── TriangleGrouperMorton.cpp │ ├── Geometry │ │ ├── Indexify.h │ │ ├── Triangle.h │ │ ├── MortonCode.h │ │ ├── OrientedBox.h │ │ ├── RayCapsule.h │ │ └── Indexify.cpp │ ├── TriangleSplitter │ │ ├── TriangleSplitterMean.h │ │ ├── TriangleSplitterLongestAxis.h │ │ ├── TriangleSplitterMorton.h │ │ ├── TriangleSplitterLongestAxis.cpp │ │ ├── TriangleSplitterMean.cpp │ │ ├── TriangleSplitterBinning.h │ │ ├── TriangleSplitterFixedLeafSize.h │ │ └── TriangleSplitter.cpp │ ├── Renderer │ │ └── DebugRendererPlayback.h │ ├── ConfigurationString.h │ └── Skeleton │ │ └── Skeleton.cpp ├── cbt.nim ├── noise.nim └── ozz-util │ └── ozz_util.h ├── README.md ├── .gitignore ├── frag.cap ├── LICENSE └── .gitmodules /src/ecs.nim: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/strpool.nim: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /thirdparty/config.nims: -------------------------------------------------------------------------------- 1 | switch("path", "./sokol-nim/src") -------------------------------------------------------------------------------- /thirdparty/cbt.c: -------------------------------------------------------------------------------- 1 | #define CBT_IMPLEMENTATION 2 | #include "cbt.h" -------------------------------------------------------------------------------- /src/physics.nim: -------------------------------------------------------------------------------- 1 | type 2 | PhysicsApi* = object 3 | 4 | var physicsApi*: PhysicsApi 5 | -------------------------------------------------------------------------------- /thirdparty/leb.c: -------------------------------------------------------------------------------- 1 | #include "cbt.h" 2 | #define LEB_IMPLEMENTATION 3 | #include "leb.h" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![FRAG](https://imgur.com/hQxxkpx.png) 2 | 3 | A WIP cross-platform game engine 4 | -------------------------------------------------------------------------------- /thirdparty/hmm.c: -------------------------------------------------------------------------------- 1 | #define HANDMADE_MATH_IMPLEMENTATION 2 | #include "HandmadeMath/HandmadeMath.h" -------------------------------------------------------------------------------- /src/shaders/leb_init.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/leb_init.sgs -------------------------------------------------------------------------------- /src/shaders/leb_update.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/leb_update.sgs -------------------------------------------------------------------------------- /src/shaders/leb_update_draw.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/leb_update_draw.sgs -------------------------------------------------------------------------------- /src/shaders/terrain_batcher.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/terrain_batcher.sgs -------------------------------------------------------------------------------- /src/shaders/terrain_render.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/terrain_render.sgs -------------------------------------------------------------------------------- /src/asm/jump_x86_64_ms_pe_gas.S.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/asm/jump_x86_64_ms_pe_gas.S.o -------------------------------------------------------------------------------- /src/asm/jump_x86_64_ms_pe_masm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/asm/jump_x86_64_ms_pe_masm.o -------------------------------------------------------------------------------- /src/asm/make_x86_64_ms_pe_gas.S.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/asm/make_x86_64_ms_pe_gas.S.o -------------------------------------------------------------------------------- /src/asm/make_x86_64_ms_pe_masm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/asm/make_x86_64_ms_pe_masm.o -------------------------------------------------------------------------------- /src/asm/ontop_x86_64_ms_pe_gas.S.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/asm/ontop_x86_64_ms_pe_gas.S.o -------------------------------------------------------------------------------- /src/asm/ontop_x86_64_ms_pe_masm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/asm/ontop_x86_64_ms_pe_masm.o -------------------------------------------------------------------------------- /src/frag.nim: -------------------------------------------------------------------------------- 1 | import api, camera 2 | 3 | export api 4 | 5 | when isMainModule: 6 | import app 7 | 8 | app.run() 9 | -------------------------------------------------------------------------------- /src/shaders/cbt_sum_reduction.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/cbt_sum_reduction.sgs -------------------------------------------------------------------------------- /src/shaders/heightmap_terrain.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/heightmap_terrain.sgs -------------------------------------------------------------------------------- /src/shaders/leb_update_merge.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/leb_update_merge.sgs -------------------------------------------------------------------------------- /src/shaders/leb_update_split.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/leb_update_split.sgs -------------------------------------------------------------------------------- /src/terrain.nim: -------------------------------------------------------------------------------- 1 | import cglm, 2 | api 3 | 4 | type 5 | TerrainApi* = object 6 | 7 | var terrainApi*: TerrainApi -------------------------------------------------------------------------------- /src/shaders/terrain_update_merge.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/terrain_update_merge.sgs -------------------------------------------------------------------------------- /src/shaders/cbt_sum_reduction_prepass.sgs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tail-Wag-Games/frag/HEAD/src/shaders/cbt_sum_reduction_prepass.sgs -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.o 2 | **/*.obj 3 | **/*.exe 4 | **/*.ilk 5 | **/*.lib 6 | **/*.pdb 7 | *.dll 8 | *.exp 9 | *.pdb 10 | frag.rdbg 11 | frag.code-workspace -------------------------------------------------------------------------------- /src/animation.nim: -------------------------------------------------------------------------------- 1 | import tnt 2 | 3 | type 4 | AnimationApi* = object 5 | draw*: proc(mvp: ptr Mat4) {.cdecl.} 6 | 7 | var animationApi*: AnimationApi 8 | -------------------------------------------------------------------------------- /thirdparty/cr.cpp: -------------------------------------------------------------------------------- 1 | #define CR_MAIN_FUNC "fragPlugin" 2 | #define CR_PLUGIN_FUNC "fragPluginEventHandler" 3 | #define CR_HOST CR_UNSAFE 4 | #define CR_DEBUG 5 | #include "cr.h" -------------------------------------------------------------------------------- /thirdparty/stb_image.c: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #include "stb/stb_image.h" 3 | #define STB_IMAGE_WRITE_IMPLEMENTATION 4 | #include "stb/stb_image_write.h" 5 | -------------------------------------------------------------------------------- /src/shaders/skinned_mesh.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = SV_Target0) out vec4 frag_color; 4 | 5 | void main() { 6 | frag_color = vec4(1.0, 0.0, 0.0, 1.0); 7 | } -------------------------------------------------------------------------------- /src/config.nim: -------------------------------------------------------------------------------- 1 | const 2 | AssetPoolSize* = 256 3 | MaxPath* = 256 4 | MaxPlugins* = 64 5 | 6 | when defined(macosx): 7 | const NaturalAlignment* = 16 8 | else: 9 | const NaturalAlignment* = 8 -------------------------------------------------------------------------------- /src/shaders/wire.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | precision lowp float; 4 | 5 | layout (location = COLOR0) flat in vec4 f_color; 6 | layout (location = SV_Target0) out vec4 out_color; 7 | 8 | void main() 9 | { 10 | out_color = f_color; 11 | } -------------------------------------------------------------------------------- /thirdparty/leb.nim: -------------------------------------------------------------------------------- 1 | import cbt 2 | 3 | {.passC: "/IC:\\Users\\Zach\\dev\\frag\\thirdparty".} 4 | {.compile: "C:\\Users\\Zach\\dev\\frag\\thirdparty\\leb.c".} 5 | 6 | proc decodeNodeAttributeArray*(node: Node; attributeArraySize: int64; attributeArray: openArray[array[3, float32]]) {.importc: "leb_DecodeNodeAttributeArray".} -------------------------------------------------------------------------------- /src/shaders/nuklear.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = COLOR0) in vec4 f_color; 4 | layout (location = TEXCOORD0) in vec2 f_uv; 5 | 6 | layout (location = SV_Target0) out vec4 frag_color; 7 | 8 | layout (binding = 0) uniform sampler2D tex; 9 | 10 | void main() { 11 | frag_color = f_color * texture(tex, f_uv); 12 | } -------------------------------------------------------------------------------- /thirdparty/nuklear.c: -------------------------------------------------------------------------------- 1 | #define NK_INCLUDE_FIXED_TYPES 2 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 3 | #define NK_INCLUDE_STANDARD_IO 4 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 5 | #define NK_INCLUDE_FONT_BAKING 6 | #define NK_INCLUDE_DEFAULT_FONT 7 | #define NK_INCLUDE_STANDARD_VARARGS 8 | #define NK_IMPLEMENTATION 9 | 10 | #include "nuklear.h" 11 | -------------------------------------------------------------------------------- /src/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct Vec2f_t { 4 | float x; 5 | float y; 6 | } Vec2f; 7 | 8 | extern void window_size(Vec2f * size); 9 | 10 | int main(void) 11 | { 12 | NimMain(); 13 | 14 | Vec2f size = { 0.0f, 0.0f }; 15 | window_size(&size); 16 | printf("window size is x: %f, y: %f\n", size.x, size.y); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /src/shaders/box.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = TEXCOORD0) in vec2 f_uv; 4 | layout (location = TEXCOORD1) flat in vec4 f_color; 5 | 6 | layout (location = SV_Target0) out vec4 frag_color; 7 | 8 | layout (binding = 0) uniform sampler2D tex_map; 9 | 10 | void main() { 11 | vec4 color = texture(tex_map, f_uv); 12 | frag_color = color * f_color; 13 | } -------------------------------------------------------------------------------- /src/fuse.nim: -------------------------------------------------------------------------------- 1 | import api 2 | 3 | var 4 | coreApi*: CoreApi 5 | pluginApi*: PluginApi 6 | appApi*: AppApi 7 | gfxApi*: GfxApi 8 | vfsApi*: VfsApi 9 | assetApi*: AssetApi 10 | cameraApi*: CameraApi 11 | 12 | appModuleHandle: pointer 13 | 14 | proc setAppModule*(handle: pointer) = 15 | appModuleHandle = handle 16 | 17 | proc getAppModule*(): pointer = 18 | appModuleHandle -------------------------------------------------------------------------------- /src/shaders/wire.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = POSITION) in vec3 a_pos; 4 | layout (location = COLOR0) in vec4 a_color; 5 | 6 | layout (location = COLOR0) flat out vec4 f_color; 7 | 8 | layout (binding = 0, std140) uniform globals { 9 | mat4 vp; 10 | }; 11 | 12 | void main() 13 | { 14 | gl_Position = vp * vec4(a_pos, 1.0); 15 | 16 | f_color = a_color; 17 | } 18 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/SerializableObject.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | JPH_IMPLEMENT_SERIALIZABLE_ABSTRACT(SerializableObject) 12 | { 13 | } 14 | 15 | JPH_NAMESPACE_END 16 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/PhysicsLock.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | #ifdef JPH_ENABLE_ASSERTS 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | thread_local PhysicsLock::LockData PhysicsLock::sLocks[4]; 14 | 15 | JPH_NAMESPACE_END 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/shaders/viewer.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #include "tone_mapping.glsl" 4 | 5 | layout (binding = 0, std140) uniform params { 6 | float u_Gamma; 7 | }; 8 | 9 | layout (binding = 0) uniform sampler2D u_FramebufferSampler; 10 | 11 | layout(location = 0) out vec2 o_TexCoord; 12 | 13 | void main(void) 14 | { 15 | o_TexCoord = vec2(gl_VertexIndex & 1, gl_VertexIndex >> 1 & 1); 16 | gl_Position = vec4(2.0 * o_TexCoord - 1.0, 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/DeterminismLog.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2022 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | #ifdef JPH_ENABLE_DETERMINISM_LOG 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | DeterminismLog DeterminismLog::sLog; 14 | 15 | JPH_NAMESPACE_END 16 | 17 | #endif // JPH_ENABLE_DETERMINISM_LOG 18 | -------------------------------------------------------------------------------- /thirdparty/Jolt/RegisterTypes.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Register all physics types with the factory 10 | extern void RegisterTypes(); 11 | 12 | /// Unregisters all types with the factory and cleans up the default material 13 | extern void UnregisterTypes(); 14 | 15 | JPH_NAMESPACE_END 16 | -------------------------------------------------------------------------------- /src/platform.nim: -------------------------------------------------------------------------------- 1 | # when defined(windows): 2 | # when defined(vcc): 3 | # proc rdtsc(): uint64 {.importc: "__rdtsc", header: "".} 4 | # when defined(macosx): 5 | # proc mach_absolute_time(): uint64 {.importc, header: "".} 6 | 7 | # # https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h 8 | # proc cycleClock*(): uint64 = 9 | # when defined(windows): 10 | # result = rdtsc() 11 | # when defined(macosx): 12 | # result = mach_absolute_time() 13 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/BroadPhase/BroadPhase.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | void BroadPhase::Init(BodyManager *inBodyManager, const BroadPhaseLayerInterface &inLayerInterface) 12 | { 13 | mBodyManager = inBodyManager; 14 | } 15 | 16 | JPH_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /src/asm/jump_i386_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "jump_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "jump_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/jump_ppc32_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__ppc__) 11 | #include "jump_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "jump_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/make_i386_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "make_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "make_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/make_ppc32_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__ppc__) 11 | #include "make_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "make_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/ontop_ppc32_ppc64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__ppc__) 11 | #include "ontop_ppc32_sysv_macho_gas.S" 12 | #elif defined(__ppc64__) 13 | #include "ontop_ppc64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /src/asm/ontop_i386_x86_64_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "ontop_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "ontop_x86_64_sysv_macho_gas.S" 14 | #else 15 | #error "No arch's" 16 | #endif 17 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/CollectFacesMode.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Whether or not to collect faces, used by CastShape and CollideShape 10 | enum class ECollectFacesMode : uint8 11 | { 12 | CollectFaces, ///< mShape1/2Face is desired 13 | NoFaces ///< mShape1/2Face is not desired 14 | }; 15 | 16 | JPH_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /src/shaders/nuklear.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = POSITION) in vec2 a_pos; 4 | layout (location = TEXCOORD0) in vec2 a_uv; 5 | layout (location = COLOR0) in vec4 a_color; 6 | 7 | layout (location = COLOR0) out vec4 f_color; 8 | layout (location = TEXCOORD0) out vec2 f_uv; 9 | 10 | layout (binding = 0, std140) uniform vs_params { 11 | vec4 disp_size; 12 | }; 13 | 14 | void main() 15 | { 16 | gl_Position = vec4(((a_pos/disp_size.xy)-0.5)*vec2(2.0,-2.0), 0.5, 1.0); 17 | f_uv = a_uv; 18 | f_color = a_color; 19 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/NonCopyable.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Class that makes another class non-copyable. Usage: Inherit from NonCopyable. 10 | class NonCopyable 11 | { 12 | public: 13 | NonCopyable() = default; 14 | NonCopyable(const NonCopyable &) = delete; 15 | void operator = (const NonCopyable &) = delete; 16 | }; 17 | 18 | JPH_NAMESPACE_END 19 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Jolt.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | // Project includes 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/UnorderedSet.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | JPH_SUPPRESS_WARNINGS_STD_END 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | template , class KeyEqual = std::equal_to> using UnorderedSet = std::unordered_set>; 14 | 15 | JPH_NAMESPACE_END 16 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Body/MotionType.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Motion type of a physics body 10 | enum class EMotionType : uint8 11 | { 12 | Static, ///< Non movable 13 | Kinematic, ///< Movable using velocities only, does not respond to forces 14 | Dynamic, ///< Responds to forces as a normal physics object 15 | }; 16 | 17 | JPH_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/EActivation.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Enum used by AddBody to determine if the body needs to be initially active 10 | enum class EActivation 11 | { 12 | Activate, ///< Activate the body, making it part of the simulation 13 | DontActivate ///< Leave activation state as it is (will not deactivate an active body) 14 | }; 15 | 16 | JPH_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Vehicle/VehicleController.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | JPH_IMPLEMENT_SERIALIZABLE_ABSTRACT(VehicleControllerSettings) 13 | { 14 | JPH_ADD_BASE_CLASS(VehicleControllerSettings, SerializableObject) 15 | } 16 | 17 | JPH_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/UnorderedMap.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | JPH_SUPPRESS_WARNINGS_STD_END 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | template , class KeyEqual = std::equal_to> using UnorderedMap = std::unordered_map>>; 14 | 15 | JPH_NAMESPACE_END 16 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/BackFaceMode.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// How collision detection functions will treat back facing triangles 10 | enum class EBackFaceMode : uint8 11 | { 12 | IgnoreBackFaces, ///< Ignore collision with back facing surfaces/triangles 13 | CollideWithBackFaces, ///< Collide with back facing surfaces/triangles 14 | }; 15 | 16 | JPH_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Body/BodyAccess.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | #ifdef JPH_ENABLE_ASSERTS 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | thread_local BodyAccess::EAccess BodyAccess::sVelocityAccess = BodyAccess::EAccess::ReadWrite; 14 | thread_local BodyAccess::EAccess BodyAccess::sPositionAccess = BodyAccess::EAccess::ReadWrite; 15 | 16 | JPH_NAMESPACE_END 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/shaders/basic.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = POSITION) in vec3 a_pos; 4 | layout (location = NORMAL) in vec3 a_normal; 5 | layout (location = TEXCOORD0) in vec2 a_uv; 6 | 7 | layout (location = TEXCOORD0) out vec2 f_uv; 8 | layout (location = TEXCOORD1) out vec3 f_normal; 9 | 10 | layout (binding = 0, std140) uniform vs_globals { 11 | mat4 viewproj_mat; 12 | mat4 world_mat; 13 | }; 14 | 15 | void main() 16 | { 17 | vec4 pos = world_mat * vec4(a_pos.xyz, 1.0); 18 | gl_Position = viewproj_mat * pos; 19 | f_uv = a_uv; 20 | 21 | f_normal = mat3(world_mat) * a_normal; 22 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/AABoxCast.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Structure that holds AABox moving linearly through 3d space 12 | struct AABoxCast 13 | { 14 | JPH_OVERRIDE_NEW_DELETE 15 | 16 | AABox mBox; ///< Axis aligned box at starting location 17 | Vec3 mDirection; ///< Direction and length of the cast (anything beyond this length will not be reported as a hit) 18 | }; 19 | 20 | JPH_NAMESPACE_END 21 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/PhysicsUpdateContext.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | PhysicsUpdateContext::PhysicsUpdateContext(TempAllocator &inTempAllocator) : 12 | mTempAllocator(&inTempAllocator), 13 | mSteps(inTempAllocator) 14 | { 15 | } 16 | 17 | PhysicsUpdateContext::~PhysicsUpdateContext() 18 | { 19 | JPH_ASSERT(mBodyPairs == nullptr); 20 | JPH_ASSERT(mActiveConstraints == nullptr); 21 | } 22 | 23 | JPH_NAMESPACE_END 24 | -------------------------------------------------------------------------------- /src/imgui.nim: -------------------------------------------------------------------------------- 1 | import nuklear 2 | 3 | type 4 | ImguiApi* = object 5 | begin*: proc(title: cstring; bounds: nk_rect; flags: nk_flags): bool {.cdecl.} 6 | finish*: proc() {.cdecl.} 7 | 8 | layoutRow*: proc(fmt: nk_layout_format; height: float32; cols: int32; ratio: ptr float32) {.cdecl.} 9 | layoutRowDynamic*: proc(height: float32; cols: int32) {.cdecl.} 10 | spacing*: proc(cols: int32) {.cdecl.} 11 | 12 | label*: proc(str: cstring; alignment: nk_flags) {.cdecl.} 13 | 14 | buttonLabel*: proc(str: cstring): bool {.cdecl.} 15 | buttonText*: proc(str: cstring; len: int32): bool {.cdecl.} 16 | 17 | render*: proc() {.cdecl.} 18 | 19 | var imguiApi*: ImguiApi 20 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/UVec4.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | // Table that shifts vector components by 4 - X floats to the left 10 | const UVec4 UVec4::sFourMinusXShuffle[5] = 11 | { 12 | UVec4(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), 13 | UVec4(0x0f0e0d0c, 0xffffffff, 0xffffffff, 0xffffffff), 14 | UVec4(0x0b0a0908, 0x0f0e0d0c, 0xffffffff, 0xffffffff), 15 | UVec4(0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0xffffffff), 16 | UVec4(0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c) 17 | }; 18 | 19 | JPH_NAMESPACE_END 20 | -------------------------------------------------------------------------------- /thirdparty/cbt.nim: -------------------------------------------------------------------------------- 1 | {.passC: "/IC:\\Users\\Zach\\dev\\frag\\thirdparty".} 2 | {.compile: "C:\\Users\\Zach\\dev\\frag\\thirdparty\\cbt.c".} 3 | 4 | type 5 | Node* = object 6 | id {.bitsize: 58.}: uint64 7 | depth {.bitsize: 6.}: uint64 8 | Tree* = object 9 | heap: ptr UncheckedArray[uint64] 10 | 11 | proc node*(id, depth: uint64): Node = 12 | result.id = id 13 | result.depth = depth 14 | 15 | proc createAtDepth*(maxDepth, depth: int64): ptr Tree {.importc: "cbt_CreateAtDepth".} 16 | proc heapByteSize*(tree: ptr Tree): int64 {.importc: "cbt_HeapByteSize".} 17 | proc getHeap*(tree: ptr Tree): ptr UncheckedArray[char] {.importc: "cbt_GetHeap".} 18 | proc release*(tree: ptr Tree) {.importc: "cbt_Release".} -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/Swizzle.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Enum indicating which component to use when swizzling 10 | enum 11 | { 12 | SWIZZLE_X = 0, ///< Use the X component 13 | SWIZZLE_Y = 1, ///< Use the Y component 14 | SWIZZLE_Z = 2, ///< Use the Z component 15 | SWIZZLE_W = 3, ///< Use the W component 16 | SWIZZLE_UNUSED = 2, ///< We always use the Z component when we don't specifically want to initialize a value, this is consistent with what is done in Vec3(x, y, z), Vec3(Float3 &) and Vec3::sLoadFloat3Unsafe 17 | }; 18 | 19 | JPH_NAMESPACE_END 20 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleGrouper/TriangleGrouperMorton.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// A class that groups triangles in batches of N according to morton code of centroid. 12 | /// Time complexity: O(N log(N)) 13 | class TriangleGrouperMorton : public TriangleGrouper 14 | { 15 | public: 16 | // See: TriangleGrouper::Group 17 | virtual void Group(const VertexList &inVertices, const IndexedTriangleList &inTriangles, int inGroupSize, Array &outGroupedTriangleIndices) override; 18 | }; 19 | 20 | JPH_NAMESPACE_END 21 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/ActiveEdgeMode.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// How to treat active/inactive edges. 10 | /// An active edge is an edge that either has no neighbouring edge or if the angle between the two connecting faces is too large, see: ActiveEdges 11 | enum class EActiveEdgeMode : uint8 12 | { 13 | CollideOnlyWithActive, ///< Do not collide with inactive edges. For physics simulation, this gives less ghost collisions. 14 | CollideWithAll, ///< Collide with all edges. Use this when you're interested in all collisions. 15 | }; 16 | 17 | JPH_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /src/asm/tail_ppc32_sysv_elf_gas.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Oliver Kowalke 2009. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #include 8 | 9 | using boost::context::detail::fcontext_t; 10 | using boost::context::detail::transfer_t; 11 | 12 | // This C++ tail of ontop_fcontext() allocates transfer_t{ from, vp } 13 | // on the stack. If fn() throws a C++ exception, then the C++ runtime 14 | // must remove this tail's stack frame. 15 | extern "C" transfer_t 16 | ontop_fcontext_tail( int ignore, void * vp, transfer_t (* fn)(transfer_t), fcontext_t const from) { 17 | return fn( transfer_t{ from, vp }); 18 | } 19 | -------------------------------------------------------------------------------- /src/shaders/basic.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | layout (location = TEXCOORD0) in vec2 f_uv; 3 | layout (location = TEXCOORD1) in vec3 f_normal; 4 | 5 | layout (location = SV_Target0) out vec4 frag_color; 6 | 7 | layout (binding = 0) uniform sampler2D tex_diffuse_map; 8 | 9 | layout (binding = 0, std140) uniform fs_globals { 10 | vec4 light_dir; 11 | vec4 mtl_color; 12 | }; 13 | 14 | void main() { 15 | vec3 normal = normalize(f_normal); 16 | vec3 lv = -light_dir.xyz; 17 | float n_dot_l = max(0.3, dot(normal, lv)); 18 | 19 | vec4 color = texture(tex_diffuse_map, f_uv) * vec4(mtl_color.xyz, 1.0); 20 | color = vec4(sqrt(color.xyz), color.w); 21 | vec4 final_color = vec4(color.xyz*n_dot_l, color.w); 22 | frag_color = vec4(final_color.xyz*final_color.xyz, final_color.w); 23 | } -------------------------------------------------------------------------------- /src/asm/jump_combined_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "jump_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "jump_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "jump_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "jump_ppc64_sysv_macho_gas.S" 18 | #elif defined(__arm__) 19 | #include "jump_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "jump_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /src/asm/make_combined_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "make_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "make_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "make_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "make_ppc64_sysv_macho_gas.S" 18 | #elif defined(__arm__) 19 | #include "make_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "make_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/MathTypes.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | class Vec3; 10 | class DVec3; 11 | class Vec4; 12 | class UVec4; 13 | class Vec8; 14 | class UVec8; 15 | class Quat; 16 | class Mat44; 17 | class DMat44; 18 | 19 | // Types to use for passing arguments to functions 20 | using Vec3Arg = Vec3; 21 | #ifdef JPH_USE_AVX 22 | using DVec3Arg = DVec3; 23 | #else 24 | using DVec3Arg = const DVec3 &; 25 | #endif 26 | using Vec4Arg = Vec4; 27 | using UVec4Arg = UVec4; 28 | using Vec8Arg = Vec8; 29 | using UVec8Arg = UVec8; 30 | using QuatArg = Quat; 31 | using Mat44Arg = const Mat44 &; 32 | using DMat44Arg = const DMat44 &; 33 | 34 | JPH_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/asm/ontop_combined_sysv_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__i386__) 11 | #include "ontop_i386_sysv_macho_gas.S" 12 | #elif defined(__x86_64__) 13 | #include "ontop_x86_64_sysv_macho_gas.S" 14 | #elif defined(__ppc__) 15 | #include "ontop_ppc32_sysv_macho_gas.S" 16 | #elif defined(__ppc64__) 17 | #include "ontop_ppc64_sysv_macho_gas.S" 18 | #elif defined(__arm__) 19 | #include "ontop_arm_aapcs_macho_gas.S" 20 | #elif defined(__arm64__) 21 | #include "ontop_arm64_aapcs_macho_gas.S" 22 | #else 23 | #error "No arch's" 24 | #endif 25 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/IssueReporting.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | JPH_SUPPRESS_WARNINGS_STD_END 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | static void DummyTrace([[maybe_unused]] const char *inFMT, ...) 14 | { 15 | JPH_ASSERT(false); 16 | }; 17 | 18 | TraceFunction Trace = DummyTrace; 19 | 20 | #ifdef JPH_ENABLE_ASSERTS 21 | 22 | static bool DummyAssertFailed(const char *inExpression, const char *inMessage, const char *inFile, uint inLine) 23 | { 24 | return true; // Trigger breakpoint 25 | }; 26 | 27 | AssertFailedFunction AssertFailed = DummyAssertFailed; 28 | 29 | #endif // JPH_ENABLE_ASSERTS 30 | 31 | JPH_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleGrouper/TriangleGrouperClosestCentroid.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// A class that groups triangles in batches of N. 12 | /// Starts with centroid with lowest X coordinate and finds N closest centroids, this repeats until all groups have been found. 13 | /// Time complexity: O(N^2) 14 | class TriangleGrouperClosestCentroid : public TriangleGrouper 15 | { 16 | public: 17 | // See: TriangleGrouper::Group 18 | virtual void Group(const VertexList &inVertices, const IndexedTriangleList &inTriangles, int inGroupSize, Array &outGroupedTriangleIndices) override; 19 | }; 20 | 21 | JPH_NAMESPACE_END 22 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Geometry/Indexify.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Take a list of triangles and get the unique set of vertices and use them to create indexed triangles. 13 | /// Vertices that are less than inVertexWeldDistance apart will be combined to a single vertex. 14 | void Indexify(const TriangleList &inTriangles, VertexList &outVertices, IndexedTriangleList &outTriangles, float inVertexWeldDistance = 1.0e-4f); 15 | 16 | /// Take a list of indexed triangles and unpack them 17 | void Deindexify(const VertexList &inVertices, const IndexedTriangleList &inTriangles, TriangleList &outTriangles); 18 | 19 | JPH_NAMESPACE_END 20 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/ObjectStreamTypes.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | // Note: Order is important, an enum is created and its value is stored in a binary stream! 6 | JPH_DECLARE_PRIMITIVE(uint8) 7 | JPH_DECLARE_PRIMITIVE(uint16) 8 | JPH_DECLARE_PRIMITIVE(int) 9 | JPH_DECLARE_PRIMITIVE(uint32) 10 | JPH_DECLARE_PRIMITIVE(uint64) 11 | JPH_DECLARE_PRIMITIVE(float) 12 | JPH_DECLARE_PRIMITIVE(bool) 13 | JPH_DECLARE_PRIMITIVE(String) 14 | JPH_DECLARE_PRIMITIVE(Float3) 15 | JPH_DECLARE_PRIMITIVE(Vec3) 16 | JPH_DECLARE_PRIMITIVE(Vec4) 17 | JPH_DECLARE_PRIMITIVE(Quat) 18 | JPH_DECLARE_PRIMITIVE(Mat44) 19 | JPH_DECLARE_PRIMITIVE(double) 20 | JPH_DECLARE_PRIMITIVE(DVec3) 21 | JPH_DECLARE_PRIMITIVE(DMat44) 22 | JPH_DECLARE_PRIMITIVE(Double3) 23 | 24 | #undef JPH_DECLARE_PRIMITIVE 25 | -------------------------------------------------------------------------------- /src/shaders/cbt_sum_reduction.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(std430, binding = 0) buffer cbt_Buffer { 4 | uint heap[]; 5 | } u_CbtBuffers[1]; 6 | 7 | #include "cbt.glsl" 8 | 9 | # define CBT_LOCAL_SIZE_X 256 10 | 11 | layout (binding = 0, std140) uniform params { 12 | int u_PassID; 13 | }; 14 | 15 | layout (local_size_x = CBT_LOCAL_SIZE_X, 16 | local_size_y = 1, 17 | local_size_z = 1) in; 18 | 19 | void main(void) 20 | { 21 | const int cbtID = 0; 22 | uint cnt = (1u << u_PassID); 23 | uint threadID = gl_GlobalInvocationID.x; 24 | 25 | if (threadID < cnt) { 26 | uint nodeID = threadID + cnt; 27 | uint x0 = cbt_HeapRead(cbtID, cbt_CreateNode(nodeID << 1u , u_PassID + 1)); 28 | uint x1 = cbt_HeapRead(cbtID, cbt_CreateNode(nodeID << 1u | 1u, u_PassID + 1)); 29 | 30 | cbt_HeapWrite(cbtID, cbt_CreateNode(nodeID, u_PassID), x0 + x1); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/CollidePointResult.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Structure that holds the result of colliding a point against a shape 13 | class CollidePointResult 14 | { 15 | public: 16 | JPH_OVERRIDE_NEW_DELETE 17 | 18 | /// Function required by the CollisionCollector. A smaller fraction is considered to be a 'better hit'. For point queries there is no sensible return value. 19 | inline float GetEarlyOutFraction() const { return 0.0f; } 20 | 21 | BodyID mBodyID; ///< Body that was hit 22 | SubShapeID mSubShapeID2; ///< Sub shape ID of shape that we collided against 23 | }; 24 | 25 | JPH_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /src/three_d.nim: -------------------------------------------------------------------------------- 1 | import api, tnt 2 | 3 | type 4 | DebugVertex* = object 5 | pos*: Vec3 6 | normal*: Vec3 7 | uv*: Vec2 8 | color*: tnt.Color 9 | 10 | DebugMapType* = distinct int32 11 | 12 | DebugGeometry* = object 13 | verts*: ptr UncheckedArray[DebugVertex] 14 | indices*: ptr UncheckedArray[uint16] 15 | numVerts*: int32 16 | numIndices*: int32 17 | 18 | Debug* = object 19 | gridXYPlaneCam*: proc(spacing, spacingBold, dist: float32; cam: ptr Camera; viewProj: ptr Mat4) {.cdecl.} 20 | drawBox*: proc(box: ptr Box; viewProjMat: ptr Mat4; mapType: DebugMapType; tint: Color) {.cdecl.} 21 | drawBoxes*: proc(boxes: ptr Box; numBoxes: int32; viewProjMat: ptr Mat4; mapType: DebugMapType; tints: ptr Color) {.cdecl.} 22 | 23 | ThreeDApi* = object 24 | debug*: Debug 25 | 26 | const 27 | dmtWhite* = DebugMapType(0) 28 | dmtChecker* = DebugMapType(1) 29 | 30 | var threeDApi*: ThreeDApi -------------------------------------------------------------------------------- /src/shaders/terrain_batcher.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #include "cbt.glsl" 4 | 5 | //#pragma optionNV(unroll none) 6 | 7 | layout(std430, binding = 2) 8 | buffer DrawArraysIndirectCommandBuffer { 9 | uint u_DrawArraysIndirectCommand[]; 10 | }; 11 | 12 | layout(std430, binding = 3) 13 | buffer DrawElementsIndirectCommandBuffer { 14 | uint u_DrawElementsIndirectCommand[]; 15 | }; 16 | layout(std430, binding = 4) 17 | buffer DispatchIndirectCommandBuffer { 18 | uint u_DispatchIndirectCommand[]; 19 | }; 20 | 21 | layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 22 | 23 | void main() 24 | { 25 | const int cbtID = 0; 26 | uint nodeCount = cbt_NodeCount(cbtID); 27 | 28 | u_DrawArraysIndirectCommand[0] = nodeCount; 29 | 30 | u_DispatchIndirectCommand[0] = nodeCount / 256u + 1u; 31 | u_DrawElementsIndirectCommand[0] = 3 << (2 * 3); 32 | u_DrawElementsIndirectCommand[1] = nodeCount; 33 | } 34 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleSplitter/TriangleSplitterMean.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Splitter using mean of axis with biggest centroid deviation 12 | class TriangleSplitterMean : public TriangleSplitter 13 | { 14 | public: 15 | /// Constructor 16 | TriangleSplitterMean(const VertexList &inVertices, const IndexedTriangleList &inTriangles); 17 | 18 | // See TriangleSplitter::GetStats 19 | virtual void GetStats(Stats &outStats) const override 20 | { 21 | outStats.mSplitterName = "TriangleSplitterMean"; 22 | } 23 | 24 | // See TriangleSplitter::Split 25 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 26 | }; 27 | 28 | JPH_NAMESPACE_END 29 | -------------------------------------------------------------------------------- /src/shaders/heightmap_terrain.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = POSITION) in vec3 a_position; 4 | layout (location = TEXCOORD0) in vec2 a_texcoord0; 5 | 6 | layout(location = POSITION) out vec3 v_position; 7 | layout (location = TEXCOORD0) out vec2 v_texcoord0; 8 | layout (location = TEXCOORD1) out float height; 9 | 10 | layout (binding = 0) uniform sampler2D s_heightTexture; 11 | 12 | layout (binding=0, std140) uniform uniforms { 13 | mat4 u_modelViewProj; 14 | }; 15 | 16 | void main() 17 | { 18 | v_texcoord0 = a_texcoord0; 19 | v_position = a_position.xyz; 20 | v_position.y = textureLod(s_heightTexture, a_texcoord0, 0).x * 65535.0; 21 | // v_position.y = (round(textureLod(s_heightTexture, a_texcoord0, 0).x * 4369.0) / 4369.0) * 65535.0; 22 | height = v_position.y; 23 | // v_position.z = texture(s_heightTexture, a_texcoord0).x * 255.0; 24 | 25 | gl_Position = u_modelViewProj * vec4(v_position.xyz, 1.0); 26 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/Float4.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Class that holds 4 float values. Convert to Vec4 to perform calculations. 10 | class [[nodiscard]] Float4 11 | { 12 | public: 13 | JPH_OVERRIDE_NEW_DELETE 14 | 15 | Float4() = default; ///< Intentionally not initialized for performance reasons 16 | Float4(const Float4 &inRHS) = default; 17 | Float4(float inX, float inY, float inZ, float inW) : x(inX), y(inY), z(inZ), w(inW) { } 18 | 19 | float operator [] (int inCoordinate) const 20 | { 21 | JPH_ASSERT(inCoordinate < 4); 22 | return *(&x + inCoordinate); 23 | } 24 | 25 | float x; 26 | float y; 27 | float z; 28 | float w; 29 | }; 30 | 31 | static_assert(is_trivial(), "Is supposed to be a trivial type!"); 32 | 33 | JPH_NAMESPACE_END 34 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleSplitter/TriangleSplitterLongestAxis.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Splitter using center of bounding box with longest axis 12 | class TriangleSplitterLongestAxis : public TriangleSplitter 13 | { 14 | public: 15 | /// Constructor 16 | TriangleSplitterLongestAxis(const VertexList &inVertices, const IndexedTriangleList &inTriangles); 17 | 18 | // See TriangleSplitter::GetStats 19 | virtual void GetStats(Stats &outStats) const override 20 | { 21 | outStats.mSplitterName = "TriangleSplitterLongestAxis"; 22 | } 23 | 24 | // See TriangleSplitter::Split 25 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 26 | }; 27 | 28 | JPH_NAMESPACE_END 29 | -------------------------------------------------------------------------------- /src/asm/jump_combined_all_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) 11 | #if defined(__aarch64__) 12 | #include "jump_arm64_aapcs_macho_gas.S" 13 | #else 14 | #include "jump_arm_aapcs_macho_gas.S" 15 | #endif 16 | #else 17 | #if defined(__i386__) 18 | #include "jump_i386_sysv_macho_gas.S" 19 | #elif defined(__x86_64__) 20 | #include "jump_x86_64_sysv_macho_gas.S" 21 | #elif defined(__ppc__) 22 | #include "jump_ppc32_sysv_macho_gas.S" 23 | #elif defined(__ppc64__) 24 | #include "jump_ppc64_sysv_macho_gas.S" 25 | #else 26 | #error "No arch's" 27 | #endif 28 | #endif -------------------------------------------------------------------------------- /src/asm/make_combined_all_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) 11 | #if defined(__aarch64__) 12 | #include "make_arm64_aapcs_macho_gas.S" 13 | #else 14 | #include "make_arm_aapcs_macho_gas.S" 15 | #endif 16 | #else 17 | #if defined(__i386__) 18 | #include "make_i386_sysv_macho_gas.S" 19 | #elif defined(__x86_64__) 20 | #include "make_x86_64_sysv_macho_gas.S" 21 | #elif defined(__ppc__) 22 | #include "make_ppc32_sysv_macho_gas.S" 23 | #elif defined(__ppc64__) 24 | #include "make_ppc64_sysv_macho_gas.S" 25 | #else 26 | #error "No arch's" 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /frag.cap: -------------------------------------------------------------------------------- 1 | { 2 | "rdocCaptureSettings": 1, 3 | "settings": { 4 | "autoStart": false, 5 | "commandLine": "--run=C:\\Users\\Zach\\dev\\shell-shocked\\shell-shocked.dll", 6 | "environment": [ 7 | ], 8 | "executable": "C:\\Users\\Zach\\dev\\frag\\src\\frag.exe", 9 | "inject": false, 10 | "numQueuedFrames": 4, 11 | "options": { 12 | "allowFullscreen": true, 13 | "allowVSync": true, 14 | "apiValidation": true, 15 | "captureAllCmdLists": false, 16 | "captureCallstacks": false, 17 | "captureCallstacksOnlyDraws": false, 18 | "debugOutputMute": true, 19 | "delayForDebugger": 0, 20 | "hookIntoChildren": false, 21 | "refAllResources": false, 22 | "verifyBufferAccess": false 23 | }, 24 | "queuedFrameCap": 25, 25 | "workingDir": "C:/Users/Zach/dev/frag" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/asm/ontop_combined_all_macho_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Sergue E. Leontiev 2013. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | // Stub file for universal binary 9 | 10 | #if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) 11 | #if defined(__aarch64__) 12 | #include "make_arm64_aapcs_macho_gas.S" 13 | #else 14 | #include "make_arm_aapcs_macho_gas.S" 15 | #endif 16 | #else 17 | #if defined(__i386__) 18 | #include "ontop_i386_sysv_macho_gas.S" 19 | #elif defined(__x86_64__) 20 | #include "ontop_x86_64_sysv_macho_gas.S" 21 | #elif defined(__ppc__) 22 | #include "ontop_ppc32_sysv_macho_gas.S" 23 | #elif defined(__ppc64__) 24 | #include "ontop_ppc64_sysv_macho_gas.S" 25 | #else 26 | #error "No arch's" 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/CollisionGroup.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(CollisionGroup) 15 | { 16 | JPH_ADD_ATTRIBUTE(CollisionGroup, mGroupFilter) 17 | JPH_ADD_ATTRIBUTE(CollisionGroup, mGroupID) 18 | JPH_ADD_ATTRIBUTE(CollisionGroup, mSubGroupID) 19 | } 20 | 21 | void CollisionGroup::SaveBinaryState(StreamOut &inStream) const 22 | { 23 | inStream.Write(mGroupID); 24 | inStream.Write(mSubGroupID); 25 | } 26 | 27 | void CollisionGroup::RestoreBinaryState(StreamIn &inStream) 28 | { 29 | inStream.Read(mGroupID); 30 | inStream.Read(mSubGroupID); 31 | } 32 | 33 | JPH_NAMESPACE_END 34 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Vehicle/VehicleAntiRollBar.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(VehicleAntiRollBar) 13 | { 14 | JPH_ADD_ATTRIBUTE(VehicleAntiRollBar, mLeftWheel) 15 | JPH_ADD_ATTRIBUTE(VehicleAntiRollBar, mRightWheel) 16 | JPH_ADD_ATTRIBUTE(VehicleAntiRollBar, mStiffness) 17 | } 18 | 19 | void VehicleAntiRollBar::SaveBinaryState(StreamOut &inStream) const 20 | { 21 | inStream.Write(mLeftWheel); 22 | inStream.Write(mRightWheel); 23 | inStream.Write(mStiffness); 24 | } 25 | 26 | void VehicleAntiRollBar::RestoreBinaryState(StreamIn &inStream) 27 | { 28 | inStream.Read(mLeftWheel); 29 | inStream.Read(mRightWheel); 30 | inStream.Read(mStiffness); 31 | } 32 | 33 | JPH_NAMESPACE_END 34 | -------------------------------------------------------------------------------- /src/shaders/viewer.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #include "tone_mapping.glsl" 4 | 5 | layout (binding = 0, std140) uniform params { 6 | float u_Gamma; 7 | }; 8 | 9 | layout (binding = 0) uniform sampler2D u_FramebufferSampler; 10 | 11 | layout(location = 0) in vec2 i_TexCoord; 12 | layout(location = 0) out vec4 o_FragColor; 13 | 14 | void main(void) 15 | { 16 | vec4 color = vec4(0); 17 | ivec2 P = ivec2(gl_FragCoord.xy); 18 | 19 | color = texelFetch(u_FramebufferSampler, P, 0); 20 | 21 | if (color.a > 0.0) color.rgb/= color.a; 22 | 23 | // make sure fragments store positive values 24 | if (any(lessThan(color.rgb, vec3(0)))) { 25 | o_FragColor = vec4(1, 0, 0, 1); 26 | return; 27 | } 28 | 29 | // tone map 30 | color.rgb = HdrToLdr(color.rgb); 31 | 32 | // final color 33 | o_FragColor = vec4(color.rgb, 1.0); 34 | 35 | // make sure the fragments store real values 36 | if (any(isnan(color.rgb))) 37 | o_FragColor = vec4(1, 0, 0, 1); 38 | 39 | //o_FragColor = vec4(i_TexCoord, 0, 1); 40 | } -------------------------------------------------------------------------------- /src/terrain_plugin.nim: -------------------------------------------------------------------------------- 1 | import std/deques, 2 | sokol/app as sapp, sokol/gfx as sgfx, 3 | api, logging, noise, pool, terrain, tnt 4 | 5 | type 6 | TerrainState = object 7 | splitShader: sgfx.Shader 8 | 9 | var 10 | n {.fragState.}: NoiseState 11 | pluginApi {.fragState.}: ptr PluginApi 12 | 13 | proc init() = 14 | discard 15 | 16 | proc fragPluginEventHandler(e: ptr sapp.Event) {.cdecl, exportc, dynlib.} = 17 | discard 18 | 19 | proc fragPlugin(plugin: ptr Plugin; operation: PluginOperation): int32 {.exportc, 20 | cdecl, dynlib.} = 21 | case operation: 22 | of poStep: 23 | discard 24 | of poInit: 25 | pluginApi = plugin.api 26 | 27 | init() 28 | 29 | pluginApi.injectApi("three_d", 0, addr(terrainApi)) 30 | else: 31 | discard 32 | 33 | proc fragPluginInfo(info: ptr PluginInfo) {.cdecl, exportc, dynlib.} = 34 | info.name[0..31] = toOpenArray("terrain", 0, 31) 35 | info.desc[0..255] = toOpenArray("heightmap generation and terrain rendering related functionality", 0, 255) 36 | 37 | terrainApi = TerrainApi( 38 | ) 39 | -------------------------------------------------------------------------------- /src/config.nims: -------------------------------------------------------------------------------- 1 | import std / [os, strutils] 2 | 3 | switch("gc", "orc") 4 | switch("tlsEmulation", "off") 5 | switch("define", "useMalloc") 6 | switch("define", "host") 7 | # switch("define", "nimArcDebug") 8 | 9 | let 10 | thirdPartyPath = projectDir() / ".." / "thirdparty" 11 | mimallocPath = thirdPartyPath / "mimalloc" 12 | mimallocStatic = "mimallocStatic=\"" & (mimallocPath / "src" / "static.c") & '"' 13 | mimallocIncludePath = "mimallocIncludePath=\"" & (mimallocPath / "include") & '"' 14 | 15 | switch("define", mimallocStatic) 16 | switch("define", mimallocIncludePath) 17 | 18 | switch("define", "host") 19 | switch("define", "debug") 20 | 21 | switch("path", thirdPartyPath) 22 | switch("path", thirdPartyPath / "winim") 23 | switch("path", thirdPartyPath / "sokol-nim" / "src") 24 | switch("path", thirdPartyPath / "laser") 25 | 26 | patchFile("stdlib", "malloc", "alloc") 27 | 28 | when defined Windows: 29 | switch("cc", "vcc") 30 | switch("passC", "/Zi /FS /Od") 31 | switch("passL", "/Zi /FS /Od") 32 | # switch("passC", "/fsanitize=address") 33 | # switch("verbosity", "3") -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/DynMatrix.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2022 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Dynamic resizable matrix class 10 | class [[nodiscard]] DynMatrix 11 | { 12 | public: 13 | /// Constructor 14 | DynMatrix(const DynMatrix &) = default; 15 | DynMatrix(uint inRows, uint inCols) : mRows(inRows), mCols(inCols) { mElements.resize(inRows * inCols); } 16 | 17 | /// Access an element 18 | float operator () (uint inRow, uint inCol) const { JPH_ASSERT(inRow < mRows && inCol < mCols); return mElements[inRow * mCols + inCol]; } 19 | float & operator () (uint inRow, uint inCol) { JPH_ASSERT(inRow < mRows && inCol < mCols); return mElements[inRow * mCols + inCol]; } 20 | 21 | /// Get dimensions 22 | uint GetCols() const { return mCols; } 23 | uint GetRows() const { return mRows; } 24 | 25 | private: 26 | uint mRows; 27 | uint mCols; 28 | Array mElements; 29 | }; 30 | 31 | JPH_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/PhysicsStepListener.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | class PhysicsSystem; 10 | 11 | /// A listener class that receives a callback before every physics simulation step 12 | class PhysicsStepListener 13 | { 14 | public: 15 | /// Ensure virtual destructor 16 | virtual ~PhysicsStepListener() = default; 17 | 18 | /// Called before every simulation step (received inCollisionSteps times for every PhysicsSystem::Update(...) call) 19 | /// This is called while all bodies and constraints are locked for modifications. Multiple listeners can be executed in parallel and it is the responsibility of the listener 20 | /// to avoid race conditions. 21 | /// Note that this function is not called if there aren't any active bodies or when the physics system is updated with 0 delta time. 22 | virtual void OnStep(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0; 23 | }; 24 | 25 | JPH_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleSplitter/TriangleSplitterMorton.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Splitter using Morton codes, see: http://devblogs.nvidia.com/parallelforall/thinking-parallel-part-iii-tree-construction-gpu/ 12 | class TriangleSplitterMorton : public TriangleSplitter 13 | { 14 | public: 15 | /// Constructor 16 | TriangleSplitterMorton(const VertexList &inVertices, const IndexedTriangleList &inTriangles); 17 | 18 | // See TriangleSplitter::GetStats 19 | virtual void GetStats(Stats &outStats) const override 20 | { 21 | outStats.mSplitterName = "TriangleSplitterMorton"; 22 | } 23 | 24 | // See TriangleSplitter::Split 25 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 26 | 27 | private: 28 | // Precalculated Morton codes 29 | Array mMortonCodes; 30 | }; 31 | 32 | JPH_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/Float2.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Class that holds 2 floats, used as a storage class mainly. 10 | class [[nodiscard]] Float2 11 | { 12 | public: 13 | JPH_OVERRIDE_NEW_DELETE 14 | 15 | Float2() = default; ///< Intentionally not initialized for performance reasons 16 | Float2(const Float2 &inRHS) = default; 17 | Float2(float inX, float inY) : x(inX), y(inY) { } 18 | 19 | bool operator == (const Float2 &inRHS) const { return x == inRHS.x && y == inRHS.y; } 20 | bool operator != (const Float2 &inRHS) const { return x != inRHS.x || y != inRHS.y; } 21 | 22 | /// To String 23 | friend ostream & operator << (ostream &inStream, const Float2 &inV) 24 | { 25 | inStream << inV.x << ", " << inV.y; 26 | return inStream; 27 | } 28 | 29 | float x; 30 | float y; 31 | }; 32 | 33 | static_assert(is_trivial(), "Is supposed to be a trivial type!"); 34 | 35 | JPH_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/GroupFilterTable.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(GroupFilterTable) 15 | { 16 | JPH_ADD_BASE_CLASS(GroupFilterTable, GroupFilter) 17 | 18 | JPH_ADD_ATTRIBUTE(GroupFilterTable, mNumSubGroups) 19 | JPH_ADD_ATTRIBUTE(GroupFilterTable, mTable) 20 | } 21 | 22 | void GroupFilterTable::SaveBinaryState(StreamOut &inStream) const 23 | { 24 | GroupFilter::SaveBinaryState(inStream); 25 | 26 | inStream.Write(mNumSubGroups); 27 | inStream.Write(mTable); 28 | } 29 | 30 | void GroupFilterTable::RestoreBinaryState(StreamIn &inStream) 31 | { 32 | GroupFilter::RestoreBinaryState(inStream); 33 | 34 | inStream.Read(mNumSubGroups); 35 | inStream.Read(mTable); 36 | } 37 | 38 | JPH_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleSplitter/TriangleSplitterLongestAxis.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | TriangleSplitterLongestAxis::TriangleSplitterLongestAxis(const VertexList &inVertices, const IndexedTriangleList &inTriangles) : 13 | TriangleSplitter(inVertices, inTriangles) 14 | { 15 | } 16 | 17 | bool TriangleSplitterLongestAxis::Split(const Range &inTriangles, Range &outLeft, Range &outRight) 18 | { 19 | // Calculate bounding box for triangles 20 | AABox bounds; 21 | for (uint t = inTriangles.mBegin; t < inTriangles.mEnd; ++t) 22 | bounds.Encapsulate(mVertices, GetTriangle(t)); 23 | 24 | // Calculate split plane 25 | uint dimension = bounds.GetExtent().GetHighestComponentIndex(); 26 | float split = bounds.GetCenter()[dimension]; 27 | 28 | return SplitInternal(inTriangles, dimension, split, outLeft, outRight); 29 | } 30 | 31 | JPH_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Tail-Wag-Games 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/PhysicsMaterialSimple.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(PhysicsMaterialSimple) 15 | { 16 | JPH_ADD_BASE_CLASS(PhysicsMaterialSimple, PhysicsMaterial) 17 | 18 | JPH_ADD_ATTRIBUTE(PhysicsMaterialSimple, mDebugName) 19 | JPH_ADD_ATTRIBUTE(PhysicsMaterialSimple, mDebugColor) 20 | } 21 | 22 | void PhysicsMaterialSimple::SaveBinaryState(StreamOut &inStream) const 23 | { 24 | PhysicsMaterial::SaveBinaryState(inStream); 25 | 26 | inStream.Write(mDebugName); 27 | inStream.Write(mDebugColor); 28 | } 29 | 30 | void PhysicsMaterialSimple::RestoreBinaryState(StreamIn &inStream) 31 | { 32 | PhysicsMaterial::RestoreBinaryState(inStream); 33 | 34 | inStream.Read(mDebugName); 35 | inStream.Read(mDebugColor); 36 | } 37 | 38 | JPH_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/Real.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2022 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | #ifdef JPH_DOUBLE_PRECISION 13 | 14 | // Define real to double 15 | using Real = double; 16 | using Real3 = Double3; 17 | using RVec3 = DVec3; 18 | using RVec3Arg = DVec3Arg; 19 | using RMat44 = DMat44; 20 | using RMat44Arg = DMat44Arg; 21 | 22 | #define JPH_RVECTOR_ALIGNMENT JPH_DVECTOR_ALIGNMENT 23 | 24 | #else 25 | 26 | // Define real to float 27 | using Real = float; 28 | using Real3 = Float3; 29 | using RVec3 = Vec3; 30 | using RVec3Arg = Vec3Arg; 31 | using RMat44 = Mat44; 32 | using RMat44Arg = Mat44Arg; 33 | 34 | #define JPH_RVECTOR_ALIGNMENT JPH_VECTOR_ALIGNMENT 35 | 36 | #endif // JPH_DOUBLE_PRECISION 37 | 38 | // Put the 'real' operator in a namespace so that users can opt in to use it: 39 | // using namespace JPH::literals; 40 | namespace literals { 41 | constexpr Real operator "" _r (long double inValue) { return Real(inValue); } 42 | }; 43 | 44 | JPH_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/FindRoot.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Find the roots of \f$inA \: x^2 + inB \: x + inC = 0\f$. 10 | /// @return The number of roots, actual roots in outX1 and outX2. 11 | /// If number of roots returned is 1 then outX1 == outX2. 12 | template 13 | inline int FindRoot(const T inA, const T inB, const T inC, T &outX1, T &outX2) 14 | { 15 | // Check if this is a linear equation 16 | if (inA == T(0)) 17 | { 18 | // Check if this is a constant equation 19 | if (inB == T(0)) 20 | return 0; 21 | 22 | // Linear equation with 1 solution 23 | outX1 = outX2 = -inC / inB; 24 | return 1; 25 | } 26 | 27 | // See Numerical Recipes in C, Chapter 5.6 Quadratic and Cubic Equations 28 | T det = Square(inB) - T(4) * inA * inC; 29 | if (det < T(0)) 30 | return 0; 31 | T q = (inB + Sign(inB) * sqrt(det)) / T(-2); 32 | outX1 = q / inA; 33 | if (q == T(0)) 34 | { 35 | outX2 = outX1; 36 | return 1; 37 | } 38 | outX2 = inC / q; 39 | return 2; 40 | } 41 | 42 | JPH_NAMESPACE_END 43 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleGrouper/TriangleGrouper.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// A class that groups triangles in batches of N (according to closeness) 12 | class TriangleGrouper 13 | { 14 | public: 15 | /// Virtual destructor 16 | virtual ~TriangleGrouper() = default; 17 | 18 | /// Group a batch of indexed triangles 19 | /// @param inVertices The list of vertices 20 | /// @param inTriangles The list of indexed triangles (indexes into inVertices) 21 | /// @param inGroupSize How big each group should be 22 | /// @param outGroupedTriangleIndices An ordered list of indices (indexing into inTriangles), contains groups of inGroupSize large worth of indices to triangles that are grouped together. If the triangle count is not an exact multiple of inGroupSize the last batch will be smaller. 23 | virtual void Group(const VertexList &inVertices, const IndexedTriangleList &inTriangles, int inGroupSize, Array &outGroupedTriangleIndices) = 0; 24 | }; 25 | 26 | JPH_NAMESPACE_END 27 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/CastResult.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Structure that holds a ray cast or other object cast hit 13 | class BroadPhaseCastResult 14 | { 15 | public: 16 | JPH_OVERRIDE_NEW_DELETE 17 | 18 | /// Function required by the CollisionCollector. A smaller fraction is considered to be a 'better hit'. For rays/cast shapes we can just use the collision fraction. 19 | inline float GetEarlyOutFraction() const { return mFraction; } 20 | 21 | BodyID mBodyID; ///< Body that was hit 22 | float mFraction = 1.0f + FLT_EPSILON; ///< Hit fraction of the ray/object [0, 1], HitPoint = Start + mFraction * (End - Start) 23 | }; 24 | 25 | /// Specialization of cast result against a shape 26 | class RayCastResult : public BroadPhaseCastResult 27 | { 28 | public: 29 | JPH_OVERRIDE_NEW_DELETE 30 | 31 | SubShapeID mSubShapeID2; ///< Sub shape ID of shape that we collided against 32 | }; 33 | 34 | JPH_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Geometry/Triangle.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// A simple triangle and its material 10 | class Triangle 11 | { 12 | public: 13 | JPH_OVERRIDE_NEW_DELETE 14 | 15 | /// Constructor 16 | Triangle() = default; 17 | Triangle(const Float3 &inV1, const Float3 &inV2, const Float3 &inV3) : mV { inV1, inV2, inV3 } { } 18 | Triangle(const Float3 &inV1, const Float3 &inV2, const Float3 &inV3, uint32 inMaterialIndex) : Triangle(inV1, inV2, inV3) { mMaterialIndex = inMaterialIndex; } 19 | Triangle(Vec3Arg inV1, Vec3Arg inV2, Vec3Arg inV3) { inV1.StoreFloat3(&mV[0]); inV2.StoreFloat3(&mV[1]); inV3.StoreFloat3(&mV[2]); } 20 | 21 | /// Get center of triangle 22 | Vec3 GetCentroid() const 23 | { 24 | return (Vec3::sLoadFloat3Unsafe(mV[0]) + Vec3::sLoadFloat3Unsafe(mV[1]) + Vec3::sLoadFloat3Unsafe(mV[2])) * (1.0f / 3.0f); 25 | } 26 | 27 | /// Vertices 28 | Float3 mV[3]; 29 | uint32 mMaterialIndex = 0; ///< Follows mV[3] so that we can read mV as 4 vectors 30 | }; 31 | 32 | using TriangleList = Array; 33 | 34 | JPH_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/shaders/leb_init.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #define dispatchIndirect( \ 4 | _buffer \ 5 | , _offset \ 6 | , _numX \ 7 | , _numY \ 8 | , _numZ \ 9 | ) \ 10 | _buffer[8] = _numX; \ 11 | _buffer[9] = _numY; \ 12 | _buffer[10] = _numZ; \ 13 | _buffer[11] = 0 14 | 15 | #define drawIndexedIndirect( \ 16 | _buffer \ 17 | , _offset \ 18 | , _numIndices \ 19 | , _numInstances \ 20 | , _startIndex \ 21 | , _startVertex \ 22 | , _startInstance \ 23 | ) \ 24 | _buffer[0] = _numIndices; \ 25 | _buffer[1] = _numInstances; \ 26 | _buffer[2] = _startIndex; \ 27 | _buffer[3] = _startVertex; \ 28 | _buffer[4] = _startInstance; \ 29 | _buffer[5] = 0; \ 30 | _buffer[6] = 0; \ 31 | _buffer[7] = 0 32 | 33 | layout(std430, binding = 0) writeonly buffer indirect { 34 | uint indirectBuffer[]; 35 | }; 36 | 37 | layout (local_size_x = 1, 38 | local_size_y = 1, 39 | local_size_z = 1) in; 40 | void main() 41 | { 42 | drawIndexedIndirect(indirectBuffer, 0u, 0u, 0u, 0u, 0u, 0u); 43 | dispatchIndirect(indirectBuffer, 1u, 2u, 1u, 1u); 44 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Body/BodyActivationListener.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | class BodyID; 10 | 11 | /// A listener class that receives events when a body activates or deactivates. 12 | /// It can be registered with the BodyManager (or PhysicsSystem). 13 | class BodyActivationListener 14 | { 15 | public: 16 | /// Ensure virtual destructor 17 | virtual ~BodyActivationListener() = default; 18 | 19 | /// Called whenever a body activates, note this can be called from any thread so make sure your code is thread safe. 20 | /// At the time of the callback the body inBodyID will be locked and no bodies can be activated/deactivated from the callback. 21 | virtual void OnBodyActivated(const BodyID &inBodyID, uint64 inBodyUserData) = 0; 22 | 23 | /// Called whenever a body deactivates, note this can be called from any thread so make sure your code is thread safe. 24 | /// At the time of the callback the body inBodyID will be locked and no bodies can be activated/deactivated from the callback. 25 | virtual void OnBodyDeactivated(const BodyID &inBodyID, uint64 inBodyUserData) = 0; 26 | }; 27 | 28 | JPH_NAMESPACE_END 29 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Vehicle/VehicleAntiRollBar.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | /// An anti rollbar is a stiff spring that connects two wheels to reduce the amount of roll the vehicle makes in sharp corners 14 | /// See: https://en.wikipedia.org/wiki/Anti-roll_bar 15 | class VehicleAntiRollBar 16 | { 17 | public: 18 | JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(VehicleAntiRollBar) 19 | 20 | /// Saves the contents in binary form to inStream. 21 | void SaveBinaryState(StreamOut &inStream) const; 22 | 23 | /// Restores the contents in binary form to inStream. 24 | void RestoreBinaryState(StreamIn &inStream); 25 | 26 | int mLeftWheel = 0; ///< Index (in mWheels) that represents the left wheel of this anti-rollbar 27 | int mRightWheel = 1; ///< Index (in mWheels) that represents the right wheel of this anti-rollbar 28 | float mStiffness = 1000.0f; ///< Stiffness (spring constant in N/m) of anti rollbar, can be 0 to disable the anti-rollbar 29 | }; 30 | 31 | JPH_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Body/BodyPair.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Structure that holds a body pair 13 | struct alignas(uint64) BodyPair 14 | { 15 | JPH_OVERRIDE_NEW_DELETE 16 | 17 | /// Constructor 18 | BodyPair() = default; 19 | BodyPair(BodyID inA, BodyID inB) : mBodyA(inA), mBodyB(inB) { } 20 | 21 | /// Equals operator 22 | bool operator == (const BodyPair &inRHS) const { return *reinterpret_cast(this) == *reinterpret_cast(&inRHS); } 23 | 24 | /// Smaller than operator, used for consistently ordering body pairs 25 | bool operator < (const BodyPair &inRHS) const { return *reinterpret_cast(this) < *reinterpret_cast(&inRHS); } 26 | 27 | /// Get the hash value of this object 28 | uint64 GetHash() const { return Hash64(*reinterpret_cast(this)); } 29 | 30 | BodyID mBodyA; 31 | BodyID mBodyB; 32 | }; 33 | 34 | static_assert(sizeof(BodyPair) == sizeof(uint64), "Mismatch in class size"); 35 | 36 | JPH_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/FPFlushDenormals.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | #if defined(JPH_USE_SSE) 12 | 13 | /// Helper class that needs to be put on the stack to enable flushing denormals to zero 14 | /// This can make floating point operations much faster when working with very small numbers 15 | class FPFlushDenormals : public FPControlWord<_MM_FLUSH_ZERO_ON, _MM_FLUSH_ZERO_MASK> { }; 16 | 17 | #elif defined(JPH_CPU_ARM) && defined(JPH_COMPILER_MSVC) 18 | 19 | class FPFlushDenormals : public FPControlWord<_DN_FLUSH, _MCW_DN> { }; 20 | 21 | #elif defined(JPH_CPU_ARM) 22 | 23 | /// Flush denormals to zero bit 24 | static constexpr uint64 FP_FZ = 1 << 24; 25 | 26 | /// Helper class that needs to be put on the stack to enable flushing denormals to zero 27 | /// This can make floating point operations much faster when working with very small numbers 28 | class FPFlushDenormals : public FPControlWord { }; 29 | 30 | #elif defined(JPH_CPU_WASM) 31 | 32 | // Not supported 33 | class FPFlushDenormals { }; 34 | 35 | #else 36 | 37 | #error Unsupported CPU architecture 38 | 39 | #endif 40 | 41 | JPH_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/Double3.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Class that holds 3 doubles. Used as a storage class. Convert to DVec3 for calculations. 12 | class [[nodiscard]] Double3 13 | { 14 | public: 15 | JPH_OVERRIDE_NEW_DELETE 16 | 17 | Double3() = default; ///< Intentionally not initialized for performance reasons 18 | Double3(const Double3 &inRHS) = default; 19 | Double3(double inX, double inY, double inZ) : x(inX), y(inY), z(inZ) { } 20 | 21 | double operator [] (int inCoordinate) const 22 | { 23 | JPH_ASSERT(inCoordinate < 3); 24 | return *(&x + inCoordinate); 25 | } 26 | 27 | bool operator == (const Double3 &inRHS) const 28 | { 29 | return x == inRHS.x && y == inRHS.y && z == inRHS.z; 30 | } 31 | 32 | bool operator != (const Double3 &inRHS) const 33 | { 34 | return x != inRHS.x || y != inRHS.y || z != inRHS.z; 35 | } 36 | 37 | double x; 38 | double y; 39 | double z; 40 | }; 41 | 42 | static_assert(is_trivial(), "Is supposed to be a trivial type!"); 43 | 44 | JPH_NAMESPACE_END 45 | 46 | // Create a std::hash for Double3 47 | JPH_MAKE_HASHABLE(JPH::Double3, t.x, t.y, t.z) 48 | -------------------------------------------------------------------------------- /src/shaders/leb_update_merge.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(std430, binding = 0) buffer cbt_Buffer { 4 | uint heap[]; 5 | } u_CbtBuffers[1]; 6 | 7 | layout (binding = 0) uniform sampler2D u_DmapSampler; 8 | 9 | #include "frustum_culling.glsl" 10 | #include "cbt.glsl" 11 | #include "leb.glsl" 12 | #include "terrain_common.glsl" 13 | 14 | layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in; 15 | void main(void) 16 | { 17 | // get threadID 18 | const int cbtID = 0; 19 | uint threadID = gl_GlobalInvocationID.x; 20 | 21 | if (threadID < cbt_NodeCount(cbtID)) { 22 | // and extract triangle vertices 23 | cbt_Node node = cbt_DecodeNode(cbtID, threadID); 24 | vec4 triangleVertices[3] = DecodeTriangleVertices(node); 25 | 26 | // compute target LoD 27 | vec2 targetLod = LevelOfDetail(triangleVertices); 28 | 29 | if (true) { 30 | leb_DiamondParent diamond = leb_DecodeDiamondParent_Square(node); 31 | bool shouldMergeBase = LevelOfDetail(DecodeTriangleVertices(diamond.base)).x < 1.0; 32 | bool shouldMergeTop = LevelOfDetail(DecodeTriangleVertices(diamond.top)).x < 1.0; 33 | 34 | if (shouldMergeBase && shouldMergeTop) { 35 | leb_MergeNode_Square(cbtID, node, diamond); 36 | } 37 | } 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/Float3.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Class that holds 3 floats. Used as a storage class. Convert to Vec3 for calculations. 12 | class [[nodiscard]] Float3 13 | { 14 | public: 15 | JPH_OVERRIDE_NEW_DELETE 16 | 17 | Float3() = default; ///< Intentionally not initialized for performance reasons 18 | Float3(const Float3 &inRHS) = default; 19 | Float3(float inX, float inY, float inZ) : x(inX), y(inY), z(inZ) { } 20 | 21 | float operator [] (int inCoordinate) const 22 | { 23 | JPH_ASSERT(inCoordinate < 3); 24 | return *(&x + inCoordinate); 25 | } 26 | 27 | bool operator == (const Float3 &inRHS) const 28 | { 29 | return x == inRHS.x && y == inRHS.y && z == inRHS.z; 30 | } 31 | 32 | bool operator != (const Float3 &inRHS) const 33 | { 34 | return x != inRHS.x || y != inRHS.y || z != inRHS.z; 35 | } 36 | 37 | float x; 38 | float y; 39 | float z; 40 | }; 41 | 42 | using VertexList = Array; 43 | 44 | static_assert(is_trivial(), "Is supposed to be a trivial type!"); 45 | 46 | JPH_NAMESPACE_END 47 | 48 | // Create a std::hash for Float3 49 | JPH_MAKE_HASHABLE(JPH::Float3, t.x, t.y, t.z) 50 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Geometry/MortonCode.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | class MortonCode 12 | { 13 | public: 14 | /// First converts a floating point value in the range [0, 1] to a 10 bit fixed point integer. 15 | /// Then expands a 10-bit integer into 30 bits by inserting 2 zeros after each bit. 16 | static uint32 sExpandBits(float inV) 17 | { 18 | JPH_ASSERT(inV >= 0.0f && inV <= 1.0f); 19 | uint32 v = uint32(inV * 1023.0f + 0.5f); 20 | JPH_ASSERT(v < 1024); 21 | v = (v * 0x00010001u) & 0xFF0000FFu; 22 | v = (v * 0x00000101u) & 0x0F00F00Fu; 23 | v = (v * 0x00000011u) & 0xC30C30C3u; 24 | v = (v * 0x00000005u) & 0x49249249u; 25 | return v; 26 | } 27 | 28 | /// Calculate the morton code for inVector, given that all vectors lie in inVectorBounds 29 | static uint32 sGetMortonCode(Vec3Arg inVector, const AABox &inVectorBounds) 30 | { 31 | // Convert to 10 bit fixed point 32 | Vec3 scaled = (inVector - inVectorBounds.mMin) / inVectorBounds.GetSize(); 33 | uint x = sExpandBits(scaled.GetX()); 34 | uint y = sExpandBits(scaled.GetY()); 35 | uint z = sExpandBits(scaled.GetZ()); 36 | return (x << 2) + (y << 1) + z; 37 | } 38 | }; 39 | 40 | JPH_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/ShapeFilter.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | class SubShapeID; 13 | 14 | /// Filter class 15 | class ShapeFilter : public NonCopyable 16 | { 17 | public: 18 | /// Destructor 19 | virtual ~ShapeFilter() = default; 20 | 21 | /// Filter function to determine if we should collide with a shape. Returns true if the filter passes. 22 | /// This overload is called when the query doesn't have a source shape (e.g. ray cast / collide point) 23 | virtual bool ShouldCollide(const SubShapeID &inSubShapeID2) const 24 | { 25 | return true; 26 | } 27 | 28 | /// Filter function to determine if two shapes should collide. Returns true if the filter passes. 29 | /// This overload is called when querying a shape vs a shape (e.g. collide object / cast object) 30 | virtual bool ShouldCollide(const SubShapeID &inSubShapeID1, const SubShapeID &inSubShapeID2) const 31 | { 32 | return true; 33 | } 34 | 35 | /// Set by the collision detection functions to the body ID of the body that we're colliding against before calling the ShouldCollide function 36 | mutable BodyID mBodyID2; 37 | }; 38 | 39 | JPH_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleSplitter/TriangleSplitterMean.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | TriangleSplitterMean::TriangleSplitterMean(const VertexList &inVertices, const IndexedTriangleList &inTriangles) : 12 | TriangleSplitter(inVertices, inTriangles) 13 | { 14 | } 15 | 16 | bool TriangleSplitterMean::Split(const Range &inTriangles, Range &outLeft, Range &outRight) 17 | { 18 | // Calculate mean value for these triangles 19 | Vec3 mean = Vec3::sZero(); 20 | for (uint t = inTriangles.mBegin; t < inTriangles.mEnd; ++t) 21 | mean += Vec3(mCentroids[mSortedTriangleIdx[t]]); 22 | mean *= 1.0f / inTriangles.Count(); 23 | 24 | // Calculate deviation 25 | Vec3 deviation = Vec3::sZero(); 26 | for (uint t = inTriangles.mBegin; t < inTriangles.mEnd; ++t) 27 | { 28 | Vec3 delta = Vec3(mCentroids[mSortedTriangleIdx[t]]) - mean; 29 | deviation += delta * delta; 30 | } 31 | deviation *= 1.0f / inTriangles.Count(); 32 | 33 | // Calculate split plane 34 | uint dimension = deviation.GetHighestComponentIndex(); 35 | float split = mean[dimension]; 36 | 37 | return SplitInternal(inTriangles, dimension, split, outLeft, outRight); 38 | } 39 | 40 | JPH_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /src/shaders/terrain.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // layout(set = 0, binding = 0) uniform sampler linearSampler; 4 | layout(binding = 0) uniform sampler2D colorTexture; 5 | 6 | layout(location = POSITION) in vec4 eyePosition; 7 | layout(location = TEXCOORD0) in vec3 normal; 8 | layout(location = TEXCOORD1) in vec2 texCoords; 9 | 10 | layout(location = 0) out vec4 outFragColor; 11 | 12 | void main() 13 | { 14 | // Lighting constants 15 | vec3 lightColor = 2.0 * vec3(0.812, 0.914, 1.0); 16 | vec3 L = normalize(vec3(1.0, 1.0, 1.0)); 17 | 18 | // Determine diffuse lighting contribution 19 | vec3 N = normalize(normal.xyz); 20 | float diffuseFactor = clamp(dot(N, L), 0.0, 1.0); 21 | 22 | float texCoordScale = 4.0; 23 | vec3 baseColor = texture(colorTexture, texCoords * texCoordScale).rgb; 24 | 25 | vec3 litColor = diffuseFactor * lightColor * baseColor; 26 | 27 | // Fog constants 28 | vec3 fogColor = vec3(0.812, 0.914, 1.0); 29 | float fogStart = 3.0; 30 | float fogEnd = 50.0; 31 | 32 | // Calculate fog factor from eye space distance 33 | float fogDist = length(eyePosition.xyz); 34 | float fogFactor = clamp((fogEnd - fogDist) / (fogEnd - fogStart), 0.0, 1.0); 35 | 36 | // Blend lit color and fog color to get fragment color 37 | vec3 finalColor = (fogColor * (1.0 - fogFactor)) + (litColor * fogFactor); 38 | outFragColor = vec4(finalColor, 1.0); 39 | } -------------------------------------------------------------------------------- /src/shaders/leb_update.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #define dispatchIndirect( \ 4 | _buffer \ 5 | , _offset \ 6 | , _numX \ 7 | , _numY \ 8 | , _numZ \ 9 | ) \ 10 | _buffer[8] = _numX; \ 11 | _buffer[9] = _numY; \ 12 | _buffer[10] = _numZ; \ 13 | _buffer[11] = 0 14 | 15 | #define drawIndexedIndirect( \ 16 | _buffer \ 17 | , _offset \ 18 | , _numIndices \ 19 | , _numInstances \ 20 | , _startIndex \ 21 | , _startVertex \ 22 | , _startInstance \ 23 | ) \ 24 | _buffer[0] = _numIndices; \ 25 | _buffer[1] = _numInstances; \ 26 | _buffer[2] = _startIndex; \ 27 | _buffer[3] = _startVertex; \ 28 | _buffer[4] = _startInstance; \ 29 | _buffer[5] = 0; \ 30 | _buffer[6] = 0; \ 31 | _buffer[7] = 0 32 | 33 | layout(std430, binding = 0) readonly buffer cbt_Buffer { 34 | uint heap[]; 35 | } u_CbtBuffers[1]; 36 | 37 | layout(std430, binding = 0) writeonly buffer indirect { 38 | uint indirectBuffer[]; 39 | }; 40 | 41 | #include "cbt_readonly.glsl" 42 | 43 | layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 44 | void main() 45 | { 46 | const int cbtID = 0; 47 | uint nodeCount = cbt_NodeCount(cbtID); 48 | dispatchIndirect(indirectBuffer, 1u, nodeCount / 256u + 1u, 1u, 1u); 49 | } -------------------------------------------------------------------------------- /src/shaders/leb_update_draw.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #define dispatchIndirect( \ 4 | _buffer \ 5 | , _offset \ 6 | , _numX \ 7 | , _numY \ 8 | , _numZ \ 9 | ) \ 10 | _buffer[8] = _numX; \ 11 | _buffer[9] = _numY; \ 12 | _buffer[10] = _numZ; \ 13 | _buffer[11] = 0 14 | 15 | #define drawIndexedIndirect( \ 16 | _buffer \ 17 | , _offset \ 18 | , _numIndices \ 19 | , _numInstances \ 20 | , _startIndex \ 21 | , _startVertex \ 22 | , _startInstance \ 23 | ) \ 24 | _buffer[0] = _numIndices; \ 25 | _buffer[1] = _numInstances; \ 26 | _buffer[2] = _startIndex; \ 27 | _buffer[3] = _startVertex; \ 28 | _buffer[4] = _startInstance; \ 29 | _buffer[5] = 0; \ 30 | _buffer[6] = 0; \ 31 | _buffer[7] = 0 32 | 33 | layout(std430, binding = 0) readonly buffer cbt_Buffer { 34 | uint heap[]; 35 | } u_CbtBuffers[1]; 36 | 37 | layout(std430, binding = 0) writeonly buffer indirect { 38 | uint indirectBuffer[]; 39 | }; 40 | 41 | #include "cbt_readonly.glsl" 42 | 43 | layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 44 | void main() 45 | { 46 | const int cbtID = 0; 47 | uint nodeCount = cbt_NodeCount(cbtID); 48 | drawIndexedIndirect(indirectBuffer, 0u, 3 << (2 * 3), nodeCount, 0u, 0u, 0u); 49 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/GetPrimitiveTypeOfType.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Helper functions to get the underlying RTTI type of a type (so e.g. Array will return sometype) 12 | template 13 | const RTTI *GetPrimitiveTypeOfType(T *) 14 | { 15 | return GetRTTIOfType((T *)nullptr); 16 | } 17 | 18 | template 19 | const RTTI *GetPrimitiveTypeOfType(T **) 20 | { 21 | return GetRTTIOfType((T *)nullptr); 22 | } 23 | 24 | template 25 | const RTTI *GetPrimitiveTypeOfType(Ref *) 26 | { 27 | return GetRTTIOfType((T *)nullptr); 28 | } 29 | 30 | template 31 | const RTTI *GetPrimitiveTypeOfType(RefConst *) 32 | { 33 | return GetRTTIOfType((T *)nullptr); 34 | } 35 | 36 | template 37 | const RTTI *GetPrimitiveTypeOfType(Array *) 38 | { 39 | return GetPrimitiveTypeOfType((T *)nullptr); 40 | } 41 | 42 | template 43 | const RTTI *GetPrimitiveTypeOfType(StaticArray *) 44 | { 45 | return GetPrimitiveTypeOfType((T *)nullptr); 46 | } 47 | 48 | template 49 | const RTTI *GetPrimitiveTypeOfType(T (*)[N]) 50 | { 51 | return GetPrimitiveTypeOfType((T *)nullptr); 52 | } 53 | 54 | JPH_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Constraints/MotorSettings.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(MotorSettings) 15 | { 16 | JPH_ADD_ATTRIBUTE(MotorSettings, mFrequency) 17 | JPH_ADD_ATTRIBUTE(MotorSettings, mDamping) 18 | JPH_ADD_ATTRIBUTE(MotorSettings, mMinForceLimit) 19 | JPH_ADD_ATTRIBUTE(MotorSettings, mMaxForceLimit) 20 | JPH_ADD_ATTRIBUTE(MotorSettings, mMinTorqueLimit) 21 | JPH_ADD_ATTRIBUTE(MotorSettings, mMaxTorqueLimit) 22 | } 23 | 24 | void MotorSettings::SaveBinaryState(StreamOut &inStream) const 25 | { 26 | inStream.Write(mFrequency); 27 | inStream.Write(mDamping); 28 | inStream.Write(mMinForceLimit); 29 | inStream.Write(mMaxForceLimit); 30 | inStream.Write(mMinTorqueLimit); 31 | inStream.Write(mMaxTorqueLimit); 32 | } 33 | 34 | void MotorSettings::RestoreBinaryState(StreamIn &inStream) 35 | { 36 | inStream.Read(mFrequency); 37 | inStream.Read(mDamping); 38 | inStream.Read(mMinForceLimit); 39 | inStream.Read(mMaxForceLimit); 40 | inStream.Read(mMinTorqueLimit); 41 | inStream.Read(mMaxTorqueLimit); 42 | } 43 | 44 | JPH_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/ObjectStream.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | // Define macro to declare functions for a specific primitive type 12 | #define JPH_DECLARE_PRIMITIVE(name) \ 13 | bool OSIsType(name *, int inArrayDepth, EOSDataType inDataType, const char *inClassName) \ 14 | { \ 15 | return inArrayDepth == 0 && inDataType == EOSDataType::T_##name; \ 16 | } \ 17 | bool OSReadData(IObjectStreamIn &ioStream, name &outPrimitive) \ 18 | { \ 19 | return ioStream.ReadPrimitiveData(outPrimitive); \ 20 | } \ 21 | void OSWriteDataType(IObjectStreamOut &ioStream, name *) \ 22 | { \ 23 | ioStream.WriteDataType(EOSDataType::T_##name); \ 24 | } \ 25 | void OSWriteData(IObjectStreamOut &ioStream, const name &inPrimitive) \ 26 | { \ 27 | ioStream.HintNextItem(); \ 28 | ioStream.WritePrimitiveData(inPrimitive); \ 29 | } 30 | 31 | // This file uses the JPH_DECLARE_PRIMITIVE macro to define all types 32 | #include 33 | 34 | JPH_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/LinearCurve.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(LinearCurve::Point) 15 | { 16 | JPH_ADD_ATTRIBUTE(Point, mX) 17 | JPH_ADD_ATTRIBUTE(Point, mY) 18 | } 19 | 20 | JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(LinearCurve) 21 | { 22 | JPH_ADD_ATTRIBUTE(LinearCurve, mPoints) 23 | } 24 | 25 | float LinearCurve::GetValue(float inX) const 26 | { 27 | if (mPoints.empty()) 28 | return 0.0f; 29 | 30 | Points::const_iterator i2 = lower_bound(mPoints.begin(), mPoints.end(), inX, [](const Point &inPoint, float inValue) { return inPoint.mX < inValue; }); 31 | 32 | if (i2 == mPoints.begin()) 33 | return mPoints.front().mY; 34 | else if (i2 == mPoints.end()) 35 | return mPoints.back().mY; 36 | 37 | Points::const_iterator i1 = i2 - 1; 38 | return i1->mY + (inX - i1->mX) * (i2->mY - i1->mY) / (i2->mX - i1->mX); 39 | } 40 | 41 | void LinearCurve::SaveBinaryState(StreamOut &inStream) const 42 | { 43 | inStream.Write(mPoints); 44 | } 45 | 46 | void LinearCurve::RestoreBinaryState(StreamIn &inStream) 47 | { 48 | inStream.Read(mPoints); 49 | } 50 | 51 | JPH_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/PhysicsMaterialSimple.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Sample implementation of PhysicsMaterial that just holds the needed properties directly 12 | class PhysicsMaterialSimple : public PhysicsMaterial 13 | { 14 | public: 15 | JPH_DECLARE_SERIALIZABLE_VIRTUAL(PhysicsMaterialSimple) 16 | 17 | /// Constructor 18 | PhysicsMaterialSimple() = default; 19 | PhysicsMaterialSimple(const string_view &inName, ColorArg inColor) : mDebugName(inName), mDebugColor(inColor) { } 20 | 21 | // Properties 22 | virtual const char * GetDebugName() const override { return mDebugName.c_str(); } 23 | virtual Color GetDebugColor() const override { return mDebugColor; } 24 | 25 | // See: PhysicsMaterial::SaveBinaryState 26 | virtual void SaveBinaryState(StreamOut &inStream) const override; 27 | 28 | protected: 29 | // See: PhysicsMaterial::RestoreBinaryState 30 | virtual void RestoreBinaryState(StreamIn &inStream) override; 31 | 32 | private: 33 | String mDebugName; ///< Name of the material, used for debugging purposes 34 | Color mDebugColor = Color::sGrey; ///< Color of the material, used to render the shapes 35 | }; 36 | 37 | JPH_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/GroupFilter.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | class CollisionGroup; 13 | class StreamIn; 14 | class StreamOut; 15 | 16 | /// Abstract class that checks if two CollisionGroups collide 17 | class GroupFilter : public SerializableObject, public RefTarget 18 | { 19 | public: 20 | JPH_DECLARE_SERIALIZABLE_ABSTRACT(GroupFilter) 21 | 22 | /// Virtual destructor 23 | virtual ~GroupFilter() override = default; 24 | 25 | /// Check if two groups collide 26 | virtual bool CanCollide(const CollisionGroup &inGroup1, const CollisionGroup &inGroup2) const = 0; 27 | 28 | /// Saves the contents of the group filter in binary form to inStream. 29 | virtual void SaveBinaryState(StreamOut &inStream) const; 30 | 31 | using GroupFilterResult = Result>; 32 | 33 | /// Creates a GroupFilter of the correct type and restores its contents from the binary stream inStream. 34 | static GroupFilterResult sRestoreFromBinaryState(StreamIn &inStream); 35 | 36 | protected: 37 | /// This function should not be called directly, it is used by sRestoreFromBinaryState. 38 | virtual void RestoreBinaryState(StreamIn &inStream); 39 | }; 40 | 41 | JPH_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /src/shaders/box.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (location = POSITION) in vec3 a_pos; 4 | layout (location = NORMAL) in vec3 a_normal; 5 | layout (location = TEXCOORD0) in vec2 a_uv; 6 | layout (location = TEXCOORD1) in vec4 a_inst_tx1; 7 | layout (location = TEXCOORD2) in vec4 a_inst_tx2; 8 | layout (location = TEXCOORD3) in vec4 a_inst_tx3; 9 | layout (location = TEXCOORD4) in vec3 a_inst_scale; 10 | layout (location = TEXCOORD5) in vec4 a_inst_color; 11 | 12 | layout (location = TEXCOORD0) out vec2 f_uv; 13 | layout (location = TEXCOORD1) flat out vec4 f_color; 14 | 15 | #define a_inst_pos a_inst_tx1.xyz 16 | #define a_inst_rot mat3(vec3(a_inst_tx1.w, a_inst_tx2.x, a_inst_tx2.y), \ 17 | vec3(a_inst_tx2.z, a_inst_tx2.w, a_inst_tx3.x), \ 18 | vec3(a_inst_tx3.y, a_inst_tx3.z, a_inst_tx3.w)) 19 | 20 | layout (binding = 0, std140) uniform globals { 21 | mat4 vp; 22 | }; 23 | 24 | void main() 25 | { 26 | vec3 pos = a_pos; // * a_inst_scale; 27 | // pos = a_inst_rot * pos; 28 | // pos = pos + a_inst_pos; 29 | gl_Position = vp * vec4(pos, 1.0); 30 | 31 | const float e = 0.00001; 32 | 33 | vec3 normal = abs(a_normal); 34 | vec2 uv = a_uv; 35 | if (normal.x > e) { 36 | uv *= a_inst_scale.yz; 37 | } else if (normal.y > e) { 38 | uv *= a_inst_scale.xz; 39 | } else if (normal.z > e) { 40 | uv *= a_inst_scale.xy; 41 | } 42 | f_uv = uv; 43 | 44 | f_color = a_inst_color; 45 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Body/BodyAccess.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #ifdef JPH_ENABLE_ASSERTS 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | class BodyAccess 12 | { 13 | public: 14 | /// Access rules, used to detect race conditions during simulation 15 | enum class EAccess : uint8 16 | { 17 | None = 0, 18 | Read = 1, 19 | ReadWrite = 3, 20 | }; 21 | 22 | /// Grant a scope specific access rights on the current thread 23 | class Grant 24 | { 25 | public: 26 | inline Grant(EAccess inVelocity, EAccess inPosition) 27 | { 28 | JPH_ASSERT(sVelocityAccess == EAccess::ReadWrite); 29 | JPH_ASSERT(sPositionAccess == EAccess::ReadWrite); 30 | 31 | sVelocityAccess = inVelocity; 32 | sPositionAccess = inPosition; 33 | } 34 | 35 | inline ~Grant() 36 | { 37 | sVelocityAccess = EAccess::ReadWrite; 38 | sPositionAccess = EAccess::ReadWrite; 39 | } 40 | }; 41 | 42 | /// Check if we have permission 43 | static bool sCheckRights(EAccess inRights, EAccess inDesiredRights) 44 | { 45 | return (uint8(inRights) & uint8(inDesiredRights)) == uint8(inDesiredRights); 46 | } 47 | 48 | // Various permissions that can be granted 49 | static thread_local EAccess sVelocityAccess; 50 | static thread_local EAccess sPositionAccess; 51 | }; 52 | 53 | JPH_NAMESPACE_END 54 | 55 | #endif // JPH_ENABLE_ASSERTS 56 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/StateRecorder.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Class that records the state of a physics system. Can be used to check if the simulation is deterministic by putting the recorder in validation mode. 13 | /// Can be used to restore the state to an earlier point in time. 14 | class StateRecorder : public StreamIn, public StreamOut 15 | { 16 | public: 17 | /// Constructor 18 | StateRecorder() = default; 19 | StateRecorder(const StateRecorder &inRHS) : mIsValidating(inRHS.mIsValidating) { } 20 | 21 | /// Sets the stream in validation mode. In this case the physics system ensures that before it calls ReadBytes that it will 22 | /// ensure that those bytes contain the current state. This makes it possible to step and save the state, restore to the previous 23 | /// step and step again and when the recorded state is not the same it can restore the expected state and any byte that changes 24 | /// due to a ReadBytes function can be caught to find out which part of the simulation is not deterministic 25 | void SetValidating(bool inValidating) { mIsValidating = inValidating; } 26 | bool IsValidating() const { return mIsValidating; } 27 | 28 | private: 29 | bool mIsValidating = false; 30 | }; 31 | 32 | JPH_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Character/CharacterBase.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | CharacterBase::CharacterBase(const CharacterBaseSettings *inSettings, PhysicsSystem *inSystem) : 13 | mSystem(inSystem), 14 | mShape(inSettings->mShape), 15 | mUp(inSettings->mUp), 16 | mSupportingVolume(inSettings->mSupportingVolume) 17 | { 18 | // Initialize max slope angle 19 | SetMaxSlopeAngle(inSettings->mMaxSlopeAngle); 20 | } 21 | 22 | void CharacterBase::SaveState(StateRecorder &inStream) const 23 | { 24 | inStream.Write(mGroundState); 25 | inStream.Write(mGroundBodyID); 26 | inStream.Write(mGroundBodySubShapeID); 27 | inStream.Write(mGroundPosition); 28 | inStream.Write(mGroundNormal); 29 | inStream.Write(mGroundVelocity); 30 | // Can't save user data (may be a pointer) and material 31 | } 32 | 33 | void CharacterBase::RestoreState(StateRecorder &inStream) 34 | { 35 | inStream.Read(mGroundState); 36 | inStream.Read(mGroundBodyID); 37 | inStream.Read(mGroundBodySubShapeID); 38 | inStream.Read(mGroundPosition); 39 | inStream.Read(mGroundNormal); 40 | inStream.Read(mGroundVelocity); 41 | mGroundUserData = 0; // Cannot restore user data 42 | mGroundMaterial = PhysicsMaterial::sDefault; // Cannot restore material 43 | } 44 | 45 | JPH_NAMESPACE_END 46 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/Factory.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Factory, to create RTTI objects 13 | class Factory 14 | { 15 | public: 16 | JPH_OVERRIDE_NEW_DELETE 17 | 18 | /// Create an object 19 | void * CreateObject(const char *inName); 20 | 21 | /// Find type info for a specific class by name 22 | const RTTI * Find(const char *inName); 23 | 24 | /// Find type info for a specific class by hash 25 | const RTTI * Find(uint32 inHash); 26 | 27 | /// Register an object with the factory. Returns false on failure. 28 | bool Register(const RTTI *inRTTI); 29 | 30 | /// Register a list of objects with the factory. Returns false on failure. 31 | bool Register(const RTTI **inRTTIs, uint inNumber); 32 | 33 | /// Unregisters all types 34 | void Clear(); 35 | 36 | /// Get all registered classes 37 | Array GetAllClasses() const; 38 | 39 | /// Singleton factory instance 40 | static Factory * sInstance; 41 | 42 | private: 43 | using ClassNameMap = UnorderedMap; 44 | 45 | using ClassHashMap = UnorderedMap; 46 | 47 | /// Map of class names to type info 48 | ClassNameMap mClassNameMap; 49 | 50 | // Map of class hash to type info 51 | ClassHashMap mClassHashMap; 52 | }; 53 | 54 | JPH_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/mimalloc"] 2 | path = thirdparty/mimalloc 3 | url = https://github.com/microsoft/mimalloc.git 4 | [submodule "thirdparty/winim"] 5 | path = thirdparty/winim 6 | url = https://github.com/khchen/winim.git 7 | [submodule "thirdparty/cr"] 8 | path = thirdparty/cr 9 | url = https://github.com/Tail-Wag-Games/cr.git 10 | [submodule "thirdparty/sokol-nim"] 11 | path = thirdparty/sokol-nim 12 | url = https://github.com/Tail-Wag-Games/sokol-nim 13 | [submodule "thirdparty/glslcc"] 14 | path = thirdparty/glslcc 15 | url = git@github.com:Tail-Wag-Games/glslcc.git 16 | [submodule "thirdparty/cglm"] 17 | path = thirdparty/cglm 18 | url = git@github.com:Tail-Wag-Games/cglm.git 19 | [submodule "thirdparty/FastNoiseLite"] 20 | path = thirdparty/FastNoiseLite 21 | url = git@github.com:zacharycarter/FastNoiseLite.git 22 | [submodule "thirdparty/stb"] 23 | path = thirdparty/stb 24 | url = git@github.com:Tail-Wag-Games/stb.git 25 | 26 | [submodule "thirdparty/HandmadeMath"] 27 | path = thirdparty/HandmadeMath 28 | url = git@github.com:HandmadeMath/HandmadeMath.git 29 | [submodule "thirdparty/enet"] 30 | path = thirdparty/enet 31 | url = git@github.com:lsalzman/enet.git 32 | [submodule "thirdparty/Nuklear"] 33 | path = thirdparty/Nuklear 34 | url = git@github.com:Immediate-Mode-UI/Nuklear.git 35 | [submodule "thirdparty/flecs"] 36 | path = thirdparty/flecs 37 | url = git@github.com:Tail-Wag-Games/flecs.git 38 | [submodule "thirdparty/ozz-animation"] 39 | path = thirdparty/ozz-animation 40 | url = git@github.com:guillaumeblanc/ozz-animation.git 41 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/Atomics.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | JPH_SUPPRESS_WARNINGS_STD_END 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | // Things we're using from STL 14 | using std::atomic; 15 | using std::memory_order; 16 | using std::memory_order_relaxed; 17 | using std::memory_order_acquire; 18 | using std::memory_order_release; 19 | using std::memory_order_acq_rel; 20 | using std::memory_order_seq_cst; 21 | 22 | /// Atomically compute the min(ioAtomic, inValue) and store it in ioAtomic, returns true if value was updated 23 | template 24 | bool AtomicMin(atomic &ioAtomic, const T inValue, const memory_order inMemoryOrder = memory_order_seq_cst) 25 | { 26 | T cur_value = ioAtomic.load(memory_order_relaxed); 27 | while (cur_value > inValue) 28 | if (ioAtomic.compare_exchange_weak(cur_value, inValue, inMemoryOrder)) 29 | return true; 30 | return false; 31 | } 32 | 33 | /// Atomically compute the max(ioAtomic, inValue) and store it in ioAtomic, returns true if value was updated 34 | template 35 | bool AtomicMax(atomic &ioAtomic, const T inValue, const memory_order inMemoryOrder = memory_order_seq_cst) 36 | { 37 | T cur_value = ioAtomic.load(memory_order_relaxed); 38 | while (cur_value < inValue) 39 | if (ioAtomic.compare_exchange_weak(cur_value, inValue, inMemoryOrder)) 40 | return true; 41 | return false; 42 | } 43 | 44 | JPH_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/TickCounter.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | // Include for __rdtsc 8 | #if defined(JPH_PLATFORM_WINDOWS) 9 | #include 10 | #elif defined(JPH_CPU_X86) && defined(JPH_COMPILER_GCC) 11 | #include 12 | #endif 13 | 14 | JPH_NAMESPACE_BEGIN 15 | 16 | #if defined(JPH_PLATFORM_WINDOWS_UWP) || (defined(JPH_PLATFORM_WINDOWS) && defined(JPH_CPU_ARM)) 17 | 18 | /// Functionality to get the processors cycle counter 19 | uint64 GetProcessorTickCount(); // Not inline to avoid having to include Windows.h 20 | 21 | #else 22 | 23 | /// Functionality to get the processors cycle counter 24 | JPH_INLINE uint64 GetProcessorTickCount() 25 | { 26 | #if defined(JPH_PLATFORM_BLUE) 27 | return JPH_PLATFORM_BLUE_GET_TICKS(); 28 | #elif defined(JPH_CPU_X86) 29 | return __rdtsc(); 30 | #elif defined(JPH_CPU_ARM) 31 | uint64 val; 32 | asm volatile("mrs %0, cntvct_el0" : "=r" (val)); 33 | return val; 34 | #elif defined(JPH_CPU_WASM) 35 | return 0; // Not supported 36 | #else 37 | #error Undefined 38 | #endif 39 | } 40 | 41 | #endif // JPH_PLATFORM_WINDOWS_UWP || (JPH_PLATFORM_WINDOWS && JPH_CPU_ARM) 42 | 43 | /// Get the amount of ticks per second, note that this number will never be fully accurate as the amound of ticks per second may vary with CPU load, so this number is only to be used to give an indication of time for profiling purposes 44 | uint64 GetProcessorTicksPerSecond(); 45 | 46 | JPH_NAMESPACE_END 47 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Renderer/DebugRendererPlayback.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #ifndef JPH_DEBUG_RENDERER 8 | #error This file should only be included when JPH_DEBUG_RENDERER is defined 9 | #endif // !JPH_DEBUG_RENDERER 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | JPH_NAMESPACE_BEGIN 16 | 17 | /// Class that can read a recorded stream from DebugRendererRecorder and plays it back trough a DebugRenderer 18 | class DebugRendererPlayback 19 | { 20 | public: 21 | /// Constructor 22 | DebugRendererPlayback(DebugRenderer &inRenderer) : mRenderer(inRenderer) { } 23 | 24 | /// Parse a stream of frames 25 | void Parse(StreamIn &inStream); 26 | 27 | /// Get the number of parsed frames 28 | uint GetNumFrames() const { return (uint)mFrames.size(); } 29 | 30 | /// Draw a frame 31 | void DrawFrame(uint inFrameNumber) const; 32 | 33 | private: 34 | /// The debug renderer we're using to do the actual rendering 35 | DebugRenderer & mRenderer; 36 | 37 | /// Mapping of ID to batch 38 | UnorderedMap mBatches; 39 | 40 | /// Mapping of ID to geometry 41 | UnorderedMap mGeometries; 42 | 43 | /// The list of parsed frames 44 | using Frame = DebugRendererRecorder::Frame; 45 | Array mFrames; 46 | }; 47 | 48 | JPH_NAMESPACE_END 49 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ConfigurationString.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2023 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Construct a string that lists the most important configuration settings 10 | inline const char *GetConfigurationString() 11 | { 12 | return JPH_IF_SINGLE_PRECISION_ELSE("Single", "Double") " precision " 13 | #if defined(JPH_CPU_X86) 14 | "x86 " 15 | #elif defined(JPH_CPU_ARM) 16 | "ARM " 17 | #elif defined(JPH_PLATFORM_WASM) 18 | "WASM " 19 | #endif 20 | #if JPH_CPU_ADDRESS_BITS == 64 21 | "64-bit " 22 | #elif JPH_CPU_ADDRESS_BITS == 32 23 | "32-bit " 24 | #endif 25 | "with instructions: " 26 | #ifdef JPH_USE_NEON 27 | "NEON " 28 | #endif 29 | #ifdef JPH_USE_SSE 30 | "SSE2 " 31 | #endif 32 | #ifdef JPH_USE_SSE4_1 33 | "SSE4.1 " 34 | #endif 35 | #ifdef JPH_USE_SSE4_2 36 | "SSE4.2 " 37 | #endif 38 | #ifdef JPH_USE_AVX 39 | "AVX " 40 | #endif 41 | #ifdef JPH_USE_AVX2 42 | "AVX2 " 43 | #endif 44 | #ifdef JPH_USE_AVX512 45 | "AVX512 " 46 | #endif 47 | #ifdef JPH_USE_F16C 48 | "F16C " 49 | #endif 50 | #ifdef JPH_USE_LZCNT 51 | "LZCNT " 52 | #endif 53 | #ifdef JPH_USE_TZCNT 54 | "TZCNT " 55 | #endif 56 | #ifdef JPH_USE_FMADD 57 | "FMADD " 58 | #endif 59 | #ifdef JPH_CROSS_PLATFORM_DETERMINISTIC 60 | "(Cross Platform Deterministic) " 61 | #endif 62 | #ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED 63 | "(FP Exceptions) " 64 | #endif 65 | #ifdef _DEBUG 66 | "(Debug) " 67 | #endif 68 | ; 69 | } 70 | 71 | JPH_NAMESPACE_END 72 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Geometry/OrientedBox.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | class AABox; 15 | 16 | /// Oriented box 17 | class [[nodiscard]] OrientedBox 18 | { 19 | public: 20 | JPH_OVERRIDE_NEW_DELETE 21 | 22 | /// Constructor 23 | OrientedBox() = default; 24 | OrientedBox(Mat44Arg inOrientation, Vec3Arg inHalfExtents) : mOrientation(inOrientation), mHalfExtents(inHalfExtents) { } 25 | 26 | /// Construct from axis aligned box and transform. Only works for rotation/translation matrix (no scaling / shearing). 27 | OrientedBox(Mat44Arg inOrientation, const AABox &inBox) : OrientedBox(inOrientation.PreTranslated(inBox.GetCenter()), inBox.GetExtent()) { } 28 | 29 | /// Test if oriented boxe overlaps with axis aligned box eachother 30 | bool Overlaps(const AABox &inBox, float inEpsilon = 1.0e-6f) const; 31 | 32 | /// Test if two oriented boxes overlap eachother 33 | bool Overlaps(const OrientedBox &inBox, float inEpsilon = 1.0e-6f) const; 34 | 35 | Mat44 mOrientation; ///< Transform that positions and rotates the local space axis aligned box into world space 36 | Vec3 mHalfExtents; ///< Half extents (half the size of the edge) of the local space axis aligned box 37 | }; 38 | 39 | JPH_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/StateRecorderImpl.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Implementation of the StateRecorder class that uses a stringstream as underlying store and that implements checking if the state doesn't change upon reading 12 | class StateRecorderImpl final : public StateRecorder 13 | { 14 | public: 15 | /// Constructor 16 | StateRecorderImpl() = default; 17 | StateRecorderImpl(StateRecorderImpl &&inRHS) : StateRecorder(inRHS), mStream(std::move(inRHS.mStream)) { } 18 | 19 | /// Write a string of bytes to the binary stream 20 | virtual void WriteBytes(const void *inData, size_t inNumBytes) override; 21 | 22 | /// Rewind the stream for reading 23 | void Rewind(); 24 | 25 | /// Read a string of bytes from the binary stream 26 | virtual void ReadBytes(void *outData, size_t inNumBytes) override; 27 | 28 | // See StreamIn 29 | virtual bool IsEOF() const override { return mStream.eof(); } 30 | 31 | // See StreamIn / StreamOut 32 | virtual bool IsFailed() const override { return mStream.fail(); } 33 | 34 | /// Compare this state with a reference state and ensure they are the same 35 | bool IsEqual(StateRecorderImpl &inReference); 36 | 37 | /// Convert the binary data to a string 38 | string GetData() const { return mStream.str(); } 39 | 40 | private: 41 | std::stringstream mStream; 42 | }; 43 | 44 | JPH_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /src/shaders/terrain_render.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(std430, binding = 1) readonly buffer cbt_Buffer { 4 | uint heap[]; 5 | } u_CbtBuffers[1]; 6 | 7 | layout (binding = 0) uniform sampler2D u_DmapSampler; 8 | layout (binding = 1) uniform sampler2D u_SmapSampler; 9 | 10 | // #include "bruneton_atmosphere.glsl" 11 | #include "frustum_culling.glsl" 12 | #include "cbt_readonly.glsl" 13 | #include "leb.glsl" 14 | #include "terrain_common.glsl" 15 | 16 | layout(location = TEXCOORD0) in vec2 i_TexCoord; 17 | layout(location = TEXCOORD1) in vec3 i_WorldPos; 18 | layout (location = TEXCOORD2) in float height; 19 | layout (location = TEXCOORD3) in vec4 i_Color; 20 | 21 | layout(location = SV_Target0) out vec4 o_FragColor; 22 | 23 | 24 | void main() 25 | { 26 | float filterSize = 1.0f / float(textureSize(u_DmapSampler, 0).x);// sqrt(dot(dFdx(i_TexCoord), dFdy(i_TexCoord))); 27 | float sx0 = textureLod(u_DmapSampler, i_TexCoord - vec2(filterSize, 0.0), 0.0).r * 255.0; 28 | float sx1 = textureLod(u_DmapSampler, i_TexCoord + vec2(filterSize, 0.0), 0.0).r * 255.0; 29 | float sy0 = textureLod(u_DmapSampler, i_TexCoord - vec2(0.0, filterSize), 0.0).r * 255.0; 30 | float sy1 = textureLod(u_DmapSampler, i_TexCoord + vec2(0.0, filterSize), 0.0).r * 255.0; 31 | float sx = sx1 - sx0; 32 | float sy = sy1 - sy0; 33 | 34 | vec3 n = normalize(vec3(u_DmapFactor * 0.03 / filterSize * 0.5f * vec2(-sx, -sy), 1)); 35 | 36 | vec3 wi = normalize(vec3(1, 1, 1)); 37 | float d = dot(wi, n) * 0.5 + 0.5; 38 | vec3 albedo = vec3(252, 197, 150) / 255.0f; 39 | 40 | vec3 shading = (d / 3.14159) * albedo; 41 | 42 | o_FragColor = vec4(shading, 1); 43 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Vehicle/VehicleTrack.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(VehicleTrackSettings) 13 | { 14 | JPH_ADD_ATTRIBUTE(VehicleTrackSettings, mDrivenWheel) 15 | JPH_ADD_ATTRIBUTE(VehicleTrackSettings, mWheels) 16 | JPH_ADD_ATTRIBUTE(VehicleTrackSettings, mInertia) 17 | JPH_ADD_ATTRIBUTE(VehicleTrackSettings, mAngularDamping) 18 | JPH_ADD_ATTRIBUTE(VehicleTrackSettings, mMaxBrakeTorque) 19 | JPH_ADD_ATTRIBUTE(VehicleTrackSettings, mDifferentialRatio) 20 | } 21 | 22 | void VehicleTrackSettings::SaveBinaryState(StreamOut &inStream) const 23 | { 24 | inStream.Write(mDrivenWheel); 25 | inStream.Write(mWheels); 26 | inStream.Write(mInertia); 27 | inStream.Write(mAngularDamping); 28 | inStream.Write(mMaxBrakeTorque); 29 | inStream.Write(mDifferentialRatio); 30 | } 31 | 32 | void VehicleTrackSettings::RestoreBinaryState(StreamIn &inStream) 33 | { 34 | inStream.Read(mDrivenWheel); 35 | inStream.Read(mWheels); 36 | inStream.Read(mInertia); 37 | inStream.Read(mAngularDamping); 38 | inStream.Read(mMaxBrakeTorque); 39 | inStream.Read(mDifferentialRatio); 40 | } 41 | 42 | void VehicleTrack::SaveState(StateRecorder &inStream) const 43 | { 44 | inStream.Write(mAngularVelocity); 45 | } 46 | 47 | void VehicleTrack::RestoreState(StateRecorder &inStream) 48 | { 49 | inStream.Read(mAngularVelocity); 50 | } 51 | 52 | JPH_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/TypeDeclarations.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | JPH_NAMESPACE_BEGIN 14 | 15 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(uint8); 16 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(uint16); 17 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(int); 18 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(uint32); 19 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(uint64); 20 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(float); 21 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(double); 22 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(bool); 23 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(String); 24 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Float3); 25 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Double3); 26 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Vec3); 27 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(DVec3); 28 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Vec4); 29 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Quat); 30 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(Mat44); 31 | JPH_DECLARE_RTTI_OUTSIDE_CLASS(DMat44); 32 | JPH_DECLARE_SERIALIZABLE_OUTSIDE_CLASS(Color); 33 | JPH_DECLARE_SERIALIZABLE_OUTSIDE_CLASS(AABox); 34 | JPH_DECLARE_SERIALIZABLE_OUTSIDE_CLASS(Triangle); 35 | JPH_DECLARE_SERIALIZABLE_OUTSIDE_CLASS(IndexedTriangle); 36 | 37 | JPH_NAMESPACE_END 38 | 39 | // These need to be added after all types have been registered or else clang under linux will not find GetRTTIOfType for the type 40 | #include 41 | #include 42 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/STLAlignedAllocator.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// STL allocator that takes care that memory is aligned to N bytes 10 | template 11 | class STLAlignedAllocator 12 | { 13 | public: 14 | using value_type = T; 15 | 16 | /// Pointer to type 17 | using pointer = T *; 18 | using const_pointer = const T *; 19 | 20 | /// Reference to type. 21 | /// Can be removed in C++20. 22 | using reference = T &; 23 | using const_reference = const T &; 24 | 25 | using size_type = size_t; 26 | using difference_type = ptrdiff_t; 27 | 28 | /// Constructor 29 | inline STLAlignedAllocator() = default; 30 | 31 | /// Constructor from other allocator 32 | template 33 | inline explicit STLAlignedAllocator(const STLAlignedAllocator &) { } 34 | 35 | /// Allocate memory 36 | inline pointer allocate(size_type inN) 37 | { 38 | return (pointer)AlignedAllocate(inN * sizeof(value_type), N); 39 | } 40 | 41 | /// Free memory 42 | inline void deallocate(pointer inPointer, size_type) 43 | { 44 | AlignedFree(inPointer); 45 | } 46 | 47 | /// Allocators are stateless so assumed to be equal 48 | inline bool operator == (const STLAlignedAllocator &) const 49 | { 50 | return true; 51 | } 52 | 53 | inline bool operator != (const STLAlignedAllocator &) const 54 | { 55 | return false; 56 | } 57 | 58 | /// Converting to allocator for other type 59 | template 60 | struct rebind 61 | { 62 | using other = STLAlignedAllocator; 63 | }; 64 | }; 65 | 66 | JPH_NAMESPACE_END 67 | -------------------------------------------------------------------------------- /thirdparty/noise.nim: -------------------------------------------------------------------------------- 1 | {.compile: "C:\\Users\\Zach\\dev\\frag\\thirdparty\\FastNoiseLite\\C\\FastNoiseLite.c".} 2 | 3 | type 4 | NoiseKind* = distinct int32 5 | RotationKind3d* = distinct int32 6 | FractalKind* = distinct int32 7 | CellularDistanceFunc* = distinct int32 8 | CellularReturnKind* = distinct int32 9 | DomainWarpKind* = distinct int32 10 | 11 | NoiseGenerator* = object 12 | seed*: int32 13 | frequency*: float32 14 | kind*: NoiseKind 15 | rotationKind3d*: RotationKind3d 16 | fractalKind*: FractalKind 17 | octaves*: int32 18 | lacunarity*: float32 19 | gain*: float32 20 | weightedStrength*: float32 21 | pingPongStrength*: float32 22 | cellularDistanceFunc*: CellularDistanceFunc 23 | cellularReturnKind*: CellularReturnKind 24 | cellularJitterMod*: float32 25 | domainWarpKind*: DomainWarpKind 26 | domainWarpAmp*: float32 27 | 28 | const 29 | nkOpenSimplex2* = NoiseKind(0) 30 | nkOpenSimplex2s* = NoiseKind(1) 31 | nkCellular* = NoiseKind(2) 32 | nkPerlin* = NoiseKind(3) 33 | nkValueCubic* = NoiseKind(4) 34 | nkValue* = NoiseKind(5) 35 | 36 | rk3dNone* = RotationKind3d(0) 37 | rk3dImproveXYPlanes* = RotationKind3d(1) 38 | rk3dImproveXZPlanes* = RotationKind3d(2) 39 | 40 | fkNone* = FractalKind(0) 41 | fkFBM* = FractalKind(0) 42 | fkRidged* = FractalKind(0) 43 | fkPingPong* = FractalKind(0) 44 | fkDomainWarpProgressive* = FractalKind(0) 45 | fkDomainWarpIndependent* = FractalKind(0) 46 | 47 | proc create*(): NoiseGenerator {.importc: "fnlCreateState", cdecl.} 48 | proc noise2d*(s: ptr NoiseGenerator; x, y: float32): float32 {.importc: "fnlGetNoise2D", cdecl.} 49 | proc noise3d*(s: ptr NoiseGenerator; x, y, z: float32): float32 {.importc: "fnlGetNoise3D", cdecl.} -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/StreamWrapper.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 11 | #include 12 | JPH_SUPPRESS_WARNINGS_STD_END 13 | 14 | JPH_NAMESPACE_BEGIN 15 | 16 | /// Wrapper around std::ostream 17 | class StreamOutWrapper : public StreamOut 18 | { 19 | public: 20 | /// Constructor 21 | StreamOutWrapper(ostream &ioWrapped) : mWrapped(ioWrapped) { } 22 | 23 | /// Write a string of bytes to the binary stream 24 | virtual void WriteBytes(const void *inData, size_t inNumBytes) override { mWrapped.write((const char *)inData, inNumBytes); } 25 | 26 | /// Returns true if there was an IO failure 27 | virtual bool IsFailed() const override { return mWrapped.fail(); } 28 | 29 | private: 30 | ostream & mWrapped; 31 | }; 32 | 33 | /// Wrapper around std::istream 34 | class StreamInWrapper : public StreamIn 35 | { 36 | public: 37 | /// Constructor 38 | StreamInWrapper(istream &ioWrapped) : mWrapped(ioWrapped) { } 39 | 40 | /// Write a string of bytes to the binary stream 41 | virtual void ReadBytes(void *outData, size_t inNumBytes) override { mWrapped.read((char *)outData, inNumBytes); } 42 | 43 | /// Returns true when an attempt has been made to read past the end of the file 44 | virtual bool IsEOF() const override { return mWrapped.eof(); } 45 | 46 | /// Returns true if there was an IO failure 47 | virtual bool IsFailed() const override { return mWrapped.fail(); } 48 | 49 | private: 50 | istream & mWrapped; 51 | }; 52 | 53 | JPH_NAMESPACE_END 54 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleSplitter/TriangleSplitterBinning.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Binning splitter approach taken from: Realtime Ray Tracing on GPU with BVH-based Packet Traversal by Johannes Gunther et al. 13 | class TriangleSplitterBinning : public TriangleSplitter 14 | { 15 | public: 16 | /// Constructor 17 | TriangleSplitterBinning(const VertexList &inVertices, const IndexedTriangleList &inTriangles, uint inMinNumBins = 8, uint inMaxNumBins = 128, uint inNumTrianglesPerBin = 6); 18 | 19 | // See TriangleSplitter::GetStats 20 | virtual void GetStats(Stats &outStats) const override 21 | { 22 | outStats.mSplitterName = "TriangleSplitterBinning"; 23 | } 24 | 25 | // See TriangleSplitter::Split 26 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 27 | 28 | private: 29 | // Configuration 30 | const uint mMinNumBins; 31 | const uint mMaxNumBins; 32 | const uint mNumTrianglesPerBin; 33 | 34 | struct Bin 35 | { 36 | // Properties of this bin 37 | AABox mBounds; 38 | float mMinCentroid; 39 | uint mNumTriangles; 40 | 41 | // Accumulated data from left most / right most bin to current (including this bin) 42 | AABox mBoundsAccumulatedLeft; 43 | AABox mBoundsAccumulatedRight; 44 | uint mNumTrianglesAccumulatedLeft; 45 | uint mNumTrianglesAccumulatedRight; 46 | }; 47 | 48 | // Scratch area to store the bins 49 | Array mBins; 50 | }; 51 | 52 | JPH_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/InsertionSort.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2022 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Implementation of the insertion sort algorithm. 10 | template 11 | inline void InsertionSort(Iterator inBegin, Iterator inEnd, Compare inCompare) 12 | { 13 | // Empty arrays don't need to be sorted 14 | if (inBegin != inEnd) 15 | { 16 | // Start at the second element 17 | for (Iterator i = inBegin + 1; i != inEnd; ++i) 18 | { 19 | // Move this element to a temporary value 20 | auto x = std::move(*i); 21 | 22 | // Check if the element goes before inBegin (we can't decrement the iterator before inBegin so this needs to be a separate branch) 23 | if (inCompare(x, *inBegin)) 24 | { 25 | // Move all elements to the right to make space for x 26 | Iterator prev; 27 | for (Iterator j = i; j != inBegin; j = prev) 28 | { 29 | prev = j - 1; 30 | *j = *prev; 31 | } 32 | 33 | // Move x to the first place 34 | *inBegin = std::move(x); 35 | } 36 | else 37 | { 38 | // Move elements to the right as long as they are bigger than x 39 | Iterator j = i; 40 | for (Iterator prev = j - 1; inCompare(x, *prev); j = prev, --prev) 41 | *j = std::move(*prev); 42 | 43 | // Move x into place 44 | *j = std::move(x); 45 | } 46 | } 47 | } 48 | } 49 | 50 | /// Implementation of insertion sort algorithm without comparator. 51 | template 52 | inline void InsertionSort(Iterator inBegin, Iterator inEnd) 53 | { 54 | std::less<> compare; 55 | InsertionSort(inBegin, inEnd, compare); 56 | } 57 | 58 | JPH_NAMESPACE_END 59 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Body/MotionProperties.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | void MotionProperties::SaveState(StateRecorder &inStream) const 13 | { 14 | // Only write properties that can change at runtime 15 | inStream.Write(mLinearVelocity); 16 | inStream.Write(mAngularVelocity); 17 | inStream.Write(mForce); 18 | inStream.Write(mTorque); 19 | inStream.Write(mLinearDamping); 20 | inStream.Write(mAngularDamping); 21 | inStream.Write(mMaxLinearVelocity); 22 | inStream.Write(mMaxAngularVelocity); 23 | inStream.Write(mGravityFactor); 24 | #ifdef JPH_DOUBLE_PRECISION 25 | inStream.Write(mSleepTestOffset); 26 | #endif // JPH_DOUBLE_PRECISION 27 | inStream.Write(mSleepTestSpheres); 28 | inStream.Write(mSleepTestTimer); 29 | inStream.Write(mMotionQuality); 30 | inStream.Write(mAllowSleeping); 31 | } 32 | 33 | void MotionProperties::RestoreState(StateRecorder &inStream) 34 | { 35 | inStream.Read(mLinearVelocity); 36 | inStream.Read(mAngularVelocity); 37 | inStream.Read(mForce); 38 | inStream.Read(mTorque); 39 | inStream.Read(mLinearDamping); 40 | inStream.Read(mAngularDamping); 41 | inStream.Read(mMaxLinearVelocity); 42 | inStream.Read(mMaxAngularVelocity); 43 | inStream.Read(mGravityFactor); 44 | #ifdef JPH_DOUBLE_PRECISION 45 | inStream.Read(mSleepTestOffset); 46 | #endif // JPH_DOUBLE_PRECISION 47 | inStream.Read(mSleepTestSpheres); 48 | inStream.Read(mSleepTestTimer); 49 | inStream.Read(mMotionQuality); 50 | inStream.Read(mAllowSleeping); 51 | } 52 | 53 | JPH_NAMESPACE_END 54 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleGrouper/TriangleGrouperMorton.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | void TriangleGrouperMorton::Group(const VertexList &inVertices, const IndexedTriangleList &inTriangles, int inGroupSize, Array &outGroupedTriangleIndices) 14 | { 15 | const uint triangle_count = (uint)inTriangles.size(); 16 | 17 | Array centroids; 18 | centroids.resize(triangle_count); 19 | 20 | outGroupedTriangleIndices.resize(triangle_count); 21 | 22 | for (uint t = 0; t < triangle_count; ++t) 23 | { 24 | // Store centroid 25 | centroids[t] = inTriangles[t].GetCentroid(inVertices); 26 | 27 | // Initialize sort table 28 | outGroupedTriangleIndices[t] = t; 29 | } 30 | 31 | // Get bounding box of all centroids 32 | AABox centroid_bounds; 33 | for (uint t = 0; t < triangle_count; ++t) 34 | centroid_bounds.Encapsulate(centroids[t]); 35 | 36 | // Make sure box is not degenerate 37 | centroid_bounds.EnsureMinimalEdgeLength(1.0e-5f); 38 | 39 | // Calculate morton code for each centroid 40 | Array morton_codes; 41 | morton_codes.resize(triangle_count); 42 | for (uint t = 0; t < triangle_count; ++t) 43 | morton_codes[t] = MortonCode::sGetMortonCode(centroids[t], centroid_bounds); 44 | 45 | // Sort triangles based on morton code 46 | QuickSort(outGroupedTriangleIndices.begin(), outGroupedTriangleIndices.end(), [&morton_codes](uint inLHS, uint inRHS) { return morton_codes[inLHS] < morton_codes[inRHS]; }); 47 | } 48 | 49 | JPH_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/SerializableAttributeTyped.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | ////////////////////////////////////////////////////////////////////////////////////////// 14 | // Macros to add properties to be serialized 15 | ////////////////////////////////////////////////////////////////////////////////////////// 16 | 17 | template 18 | inline void AddSerializableAttributeTyped(RTTI &inRTTI, uint inOffset, const char *inName) 19 | { 20 | inRTTI.AddAttribute(SerializableAttribute(inName, inOffset, 21 | []() 22 | { 23 | return GetPrimitiveTypeOfType((MemberType *)nullptr); 24 | }, 25 | [](int inArrayDepth, EOSDataType inDataType, const char *inClassName) 26 | { 27 | return OSIsType((MemberType *)nullptr, inArrayDepth, inDataType, inClassName); 28 | }, 29 | [](IObjectStreamIn &ioStream, void *inObject) 30 | { 31 | return OSReadData(ioStream, *reinterpret_cast(inObject)); 32 | }, 33 | [](IObjectStreamOut &ioStream, const void *inObject) 34 | { 35 | OSWriteData(ioStream, *reinterpret_cast(inObject)); 36 | }, 37 | [](IObjectStreamOut &ioStream) 38 | { 39 | OSWriteDataType(ioStream, (MemberType *)nullptr); 40 | })); 41 | } 42 | 43 | // JPH_ADD_ATTRIBUTE 44 | #define JPH_ADD_ATTRIBUTE(class_name, member_name) \ 45 | AddSerializableAttributeTyped(inRTTI, offsetof(class_name, member_name), #member_name); 46 | 47 | JPH_NAMESPACE_END 48 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Geometry/RayCapsule.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Tests a ray starting at inRayOrigin and extending infinitely in inRayDirection 13 | /// against a capsule centered around the origin with its axis along the Y axis and half height specified. 14 | /// @return FLT_MAX if there is no intersection, otherwise the fraction along the ray. 15 | /// @param inRayDirection Ray direction. Does not need to be normalized. 16 | /// @param inRayOrigin Origin of the ray. If the ray starts inside the capsule, the returned fraction will be 0. 17 | /// @param inCapsuleHalfHeight Distance from the origin to the center of the top sphere (or that of the bottom) 18 | /// @param inCapsuleRadius Radius of the top/bottom sphere 19 | JPH_INLINE float RayCapsule(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, float inCapsuleHalfHeight, float inCapsuleRadius) 20 | { 21 | // Test infinite cylinder 22 | float cylinder = RayCylinder(inRayOrigin, inRayDirection, inCapsuleRadius); 23 | if (cylinder == FLT_MAX) 24 | return FLT_MAX; 25 | 26 | // If this hit is in the finite cylinder we have our fraction 27 | if (abs(inRayOrigin.GetY() + cylinder * inRayDirection.GetY()) <= inCapsuleHalfHeight) 28 | return cylinder; 29 | 30 | // Test upper and lower sphere 31 | Vec3 sphere_center(0, inCapsuleHalfHeight, 0); 32 | float upper = RaySphere(inRayOrigin, inRayDirection, sphere_center, inCapsuleRadius); 33 | float lower = RaySphere(inRayOrigin, inRayDirection, -sphere_center, inCapsuleRadius); 34 | return min(upper, lower); 35 | } 36 | 37 | JPH_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Body/MotionQuality.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Motion quality, or how well it detects collisions when it has a high velocity 10 | enum class EMotionQuality : uint8 11 | { 12 | /// Update the body in discrete steps. Body will tunnel throuh thin objects if its velocity is high enough. 13 | /// This is the cheapest way of simulating a body. 14 | Discrete, 15 | 16 | /// Update the body using linear casting. When stepping the body, its collision shape is cast from 17 | /// start to destination using the starting rotation. The body will not be able to tunnel through thin 18 | /// objects at high velocity, but tunneling is still possible if the body is long and thin and has high 19 | /// angular velocity. Time is stolen from the object (which means it will move up to the first collision 20 | /// and will not bounce off the surface until the next integration step). This will make the body appear 21 | /// to go slower when it collides with high velocity. In order to not get stuck, the body is always 22 | /// allowed to move by a fraction of it's inner radius, which may eventually lead it to pass through geometry. 23 | /// 24 | /// Note that if you're using a collision listener, you can receive contact added/persisted notifications of contacts 25 | /// that may in the end not happen. This happens between bodies that are using casting: If bodies A and B collide at t1 26 | /// and B and C collide at t2 where t2 < t1 and A and C don't collide. In this case you may receive an incorrect contact 27 | /// point added callback between A and B (which will be removed the next frame). 28 | LinearCast, 29 | }; 30 | 31 | JPH_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/Semaphore.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2023 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | #include 10 | #include 11 | JPH_SUPPRESS_WARNINGS_STD_END 12 | 13 | JPH_NAMESPACE_BEGIN 14 | 15 | // Things we're using from STL 16 | using std::atomic; 17 | using std::mutex; 18 | using std::condition_variable; 19 | 20 | /// Implements a semaphore 21 | /// When we switch to C++20 we can use counting_semaphore to unify this 22 | class Semaphore 23 | { 24 | public: 25 | /// Constructor 26 | Semaphore(); 27 | ~Semaphore(); 28 | 29 | /// Release the semaphore, signalling the thread waiting on the barrier that there may be work 30 | void Release(uint inNumber = 1); 31 | 32 | /// Acquire the semaphore inNumber times 33 | void Acquire(uint inNumber = 1); 34 | 35 | /// Get the current value of the semaphore 36 | inline int GetValue() const { return mCount; } 37 | 38 | private: 39 | #ifdef JPH_PLATFORM_WINDOWS 40 | // On windows we use a semaphore object since it is more efficient than a lock and a condition variable 41 | alignas(JPH_CACHE_LINE_SIZE) atomic mCount { 0 }; ///< We increment mCount for every release, to acquire we decrement the count. If the count is negative we know that we are waiting on the actual semaphore. 42 | void * mSemaphore; ///< The semaphore is an expensive construct so we only acquire/release it if we know that we need to wait/have waiting threads 43 | #else 44 | // Other platforms: Emulate a semaphore using a mutex, condition variable and count 45 | mutex mLock; 46 | condition_variable mWaitVariable; 47 | int mCount = 0; 48 | #endif 49 | }; 50 | 51 | JPH_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/TypeDeclarations.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(uint8) { } 12 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(uint16) { } 13 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(int) { } 14 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(uint32) { } 15 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(uint64) { } 16 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(float) { } 17 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(double) { } 18 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(bool) { } 19 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(String) { } 20 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(Float3) { } 21 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(Double3) { } 22 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(Vec3) { } 23 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(DVec3) { } 24 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(Vec4) { } 25 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(Quat) { } 26 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(Mat44) { } 27 | JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(DMat44) { } 28 | 29 | JPH_IMPLEMENT_SERIALIZABLE_OUTSIDE_CLASS(Color) 30 | { 31 | JPH_ADD_ATTRIBUTE(Color, r) 32 | JPH_ADD_ATTRIBUTE(Color, g) 33 | JPH_ADD_ATTRIBUTE(Color, b) 34 | JPH_ADD_ATTRIBUTE(Color, a) 35 | } 36 | 37 | JPH_IMPLEMENT_SERIALIZABLE_OUTSIDE_CLASS(AABox) 38 | { 39 | JPH_ADD_ATTRIBUTE(AABox, mMin) 40 | JPH_ADD_ATTRIBUTE(AABox, mMax) 41 | } 42 | 43 | JPH_IMPLEMENT_SERIALIZABLE_OUTSIDE_CLASS(Triangle) 44 | { 45 | JPH_ADD_ATTRIBUTE(Triangle, mV) 46 | JPH_ADD_ATTRIBUTE(Triangle, mMaterialIndex) 47 | } 48 | 49 | JPH_IMPLEMENT_SERIALIZABLE_OUTSIDE_CLASS(IndexedTriangle) 50 | { 51 | JPH_ADD_ATTRIBUTE(IndexedTriangle, mIdx) 52 | JPH_ADD_ATTRIBUTE(IndexedTriangle, mMaterialIndex) 53 | } 54 | 55 | JPH_NAMESPACE_END 56 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/IssueReporting.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Trace function, needs to be overridden by application. This should output a line of text to the log / TTY. 10 | using TraceFunction = void (*)(const char *inFMT, ...); 11 | extern TraceFunction Trace; 12 | 13 | // Always turn on asserts in Debug mode 14 | #if defined(_DEBUG) && !defined(JPH_ENABLE_ASSERTS) 15 | #define JPH_ENABLE_ASSERTS 16 | #endif 17 | 18 | #ifdef JPH_ENABLE_ASSERTS 19 | /// Function called when an assertion fails. This function should return true if a breakpoint needs to be triggered 20 | using AssertFailedFunction = bool(*)(const char *inExpression, const char *inMessage, const char *inFile, uint inLine); 21 | extern AssertFailedFunction AssertFailed; 22 | 23 | // Helper functions to pass message on to failed function 24 | struct AssertLastParam { }; 25 | inline bool AssertFailedParamHelper(const char *inExpression, const char *inFile, uint inLine, AssertLastParam) { return AssertFailed(inExpression, nullptr, inFile, inLine); } 26 | inline bool AssertFailedParamHelper(const char *inExpression, const char *inFile, uint inLine, const char *inMessage, AssertLastParam) { return AssertFailed(inExpression, inMessage, inFile, inLine); } 27 | 28 | /// Main assert macro, usage: JPH_ASSERT(condition, message) or JPH_ASSERT(condition) 29 | #define JPH_ASSERT(inExpression, ...) do { if (!(inExpression) && AssertFailedParamHelper(#inExpression, __FILE__, uint(__LINE__), ##__VA_ARGS__, AssertLastParam())) JPH_BREAKPOINT; } while (false) 30 | 31 | #define JPH_IF_ENABLE_ASSERTS(...) __VA_ARGS__ 32 | #else 33 | #define JPH_ASSERT(...) ((void)0) 34 | 35 | #define JPH_IF_ENABLE_ASSERTS(...) 36 | #endif // JPH_ENABLE_ASSERTS 37 | 38 | JPH_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/Trigonometry.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | // Note that this file exists because std::sin etc. are not platform independent and will lead to non-deterministic simulation 10 | 11 | /// Sine of x (input in radians) 12 | JPH_INLINE float Sin(float inX) 13 | { 14 | Vec4 s, c; 15 | Vec4::sReplicate(inX).SinCos(s, c); 16 | return s.GetX(); 17 | } 18 | 19 | /// Cosine of x (input in radians) 20 | JPH_INLINE float Cos(float inX) 21 | { 22 | Vec4 s, c; 23 | Vec4::sReplicate(inX).SinCos(s, c); 24 | return c.GetX(); 25 | } 26 | 27 | /// Tangent of x (input in radians) 28 | JPH_INLINE float Tan(float inX) 29 | { 30 | return Vec4::sReplicate(inX).Tan().GetX(); 31 | } 32 | 33 | /// Arc sine of x (returns value in the range [-PI / 2, PI / 2]) 34 | /// Note that all input values will be clamped to the range [-1, 1] and this function will not return NaNs like std::asin 35 | JPH_INLINE float ASin(float inX) 36 | { 37 | return Vec4::sReplicate(inX).ASin().GetX(); 38 | } 39 | 40 | /// Arc cosine of x (returns value in the range [0, PI]) 41 | /// Note that all input values will be clamped to the range [-1, 1] and this function will not return NaNs like std::acos 42 | JPH_INLINE float ACos(float inX) 43 | { 44 | return Vec4::sReplicate(inX).ACos().GetX(); 45 | } 46 | 47 | /// Arc tangent of x (returns value in the range [-PI / 2, PI / 2]) 48 | JPH_INLINE float ATan(float inX) 49 | { 50 | return Vec4::sReplicate(inX).ATan().GetX(); 51 | } 52 | 53 | /// Arc tangent of y / x using the signs of the arguments to determine the correct quadrant (returns value in the range [-PI, PI]) 54 | JPH_INLINE float ATan2(float inY, float inX) 55 | { 56 | return Vec4::sATan2(Vec4::sReplicate(inY), Vec4::sReplicate(inX)).GetX(); 57 | } 58 | 59 | JPH_NAMESPACE_END 60 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/StringTools.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Create a formatted text string for debugging purposes. 10 | /// Note that this function has an internal buffer of 1024 characters, so long strings will be trimmed. 11 | String StringFormat(const char *inFMT, ...); 12 | 13 | /// Convert type to string 14 | template 15 | String ConvertToString(const T &inValue) 16 | { 17 | using OStringStream = std::basic_ostringstream, STLAllocator>; 18 | OStringStream oss; 19 | oss << inValue; 20 | return oss.str(); 21 | } 22 | 23 | /// Calculate the FNV-1a hash of inString. 24 | /// @see https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function 25 | constexpr uint64 HashString(const char *inString) 26 | { 27 | uint64 hash = 14695981039346656037UL; 28 | for (const char *c = inString; *c != 0; ++c) 29 | { 30 | hash ^= *c; 31 | hash = hash * 1099511628211UL; 32 | } 33 | return hash; 34 | } 35 | 36 | /// Replace substring with other string 37 | void StringReplace(String &ioString, const string_view &inSearch, const string_view &inReplace); 38 | 39 | /// Convert a delimited string to an array of strings 40 | void StringToVector(const string_view &inString, Array &outVector, const string_view &inDelimiter = ",", bool inClearVector = true); 41 | 42 | /// Convert an array strings to a delimited string 43 | void VectorToString(const Array &inVector, String &outString, const string_view &inDelimiter = ","); 44 | 45 | /// Convert a string to lower case 46 | String ToLower(const string_view &inString); 47 | 48 | /// Converts the lower 4 bits of inNibble to a string that represents the number in binary format 49 | const char *NibbleToBinary(uint32 inNibble); 50 | 51 | JPH_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /src/asm/make_ppc64_sysv_xcoff_gas.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Oliver Kowalke 2009. 3 | Distributed under the Boost Software License, Version 1.0. 4 | (See accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | .globl make_fcontext[DS] 8 | .globl .make_fcontext[PR] 9 | .align 2 10 | .csect .make_fcontext[PR], 3 11 | .globl _make_fcontext 12 | #._make_fcontext: 13 | # save return address into R6 14 | mflr 6 15 | 16 | # first arg of make_fcontext() == top address of context-function 17 | # shift address in R3 to lower 16 byte boundary 18 | clrrwi 3, 3, 4 19 | 20 | # reserve space for context-data on context-stack 21 | # including 64 byte of linkage + parameter area (R1 % 16 == 0) 22 | subi 3, 3, 248 23 | 24 | # third arg of make_fcontext() == address of context-function 25 | stw 5, 176(3) 26 | 27 | # set back-chain to zero 28 | li 0, 0 29 | std 0, 184(3) 30 | 31 | # compute address of returned transfer_t 32 | addi 0, 3, 232 33 | mr 4, 0 34 | std 4, 152(3) 35 | 36 | # load LR 37 | mflr 0 38 | # jump to label 1 39 | bl .Label 40 | .Label: 41 | # load LR into R4 42 | mflr 4 43 | # compute abs address of label .L_finish 44 | addi 4, 4, .L_finish - .Label 45 | # restore LR 46 | mtlr 0 47 | # save address of finish as return-address for context-function 48 | # will be entered after context-function returns 49 | stw 4, 168(3) 50 | 51 | # restore return address from R6 52 | mtlr 6 53 | 54 | blr # return pointer to context-data 55 | 56 | .L_finish: 57 | # save return address into R0 58 | mflr 0 59 | # save return address on stack, set up stack frame 60 | stw 0, 8(1) 61 | # allocate stack space, R1 % 16 == 0 62 | stwu 1, -32(1) 63 | 64 | # exit code is zero 65 | li 3, 0 66 | # exit application 67 | bl ._exit 68 | nop 69 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/SerializableAttributeEnum.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | ////////////////////////////////////////////////////////////////////////////////////////// 13 | // Macros to add properties to be serialized 14 | ////////////////////////////////////////////////////////////////////////////////////////// 15 | 16 | template 17 | inline void AddSerializableAttributeEnum(RTTI &inRTTI, uint inOffset, const char *inName) 18 | { 19 | inRTTI.AddAttribute(SerializableAttribute(inName, inOffset, 20 | []() -> const RTTI * 21 | { 22 | return nullptr; 23 | }, 24 | [](int inArrayDepth, EOSDataType inDataType, [[maybe_unused]] const char *inClassName) 25 | { 26 | return inArrayDepth == 0 && inDataType == EOSDataType::T_uint32; 27 | }, 28 | [](IObjectStreamIn &ioStream, void *inObject) 29 | { 30 | uint32 temporary; 31 | if (OSReadData(ioStream, temporary)) 32 | { 33 | *reinterpret_cast(inObject) = static_cast(temporary); 34 | return true; 35 | } 36 | return false; 37 | }, 38 | [](IObjectStreamOut &ioStream, const void *inObject) 39 | { 40 | static_assert(sizeof(MemberType) <= sizeof(uint32)); 41 | uint32 temporary = uint32(*reinterpret_cast(inObject)); 42 | OSWriteData(ioStream, temporary); 43 | }, 44 | [](IObjectStreamOut &ioStream) 45 | { 46 | ioStream.WriteDataType(EOSDataType::T_uint32); 47 | })); 48 | } 49 | 50 | // JPH_ADD_ENUM_ATTRIBUTE 51 | #define JPH_ADD_ENUM_ATTRIBUTE(class_name, member_name) \ 52 | AddSerializableAttributeEnum(inRTTI, offsetof(class_name, member_name), #member_name); 53 | 54 | JPH_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/PhysicsMaterial.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | JPH_NAMESPACE_BEGIN 14 | 15 | RefConst PhysicsMaterial::sDefault; 16 | 17 | JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(PhysicsMaterial) 18 | { 19 | JPH_ADD_BASE_CLASS(PhysicsMaterial, SerializableObject) 20 | } 21 | 22 | void PhysicsMaterial::SaveBinaryState(StreamOut &inStream) const 23 | { 24 | inStream.Write(GetRTTI()->GetHash()); 25 | } 26 | 27 | void PhysicsMaterial::RestoreBinaryState(StreamIn &inStream) 28 | { 29 | // RTTI hash is read in sRestoreFromBinaryState 30 | } 31 | 32 | PhysicsMaterial::PhysicsMaterialResult PhysicsMaterial::sRestoreFromBinaryState(StreamIn &inStream) 33 | { 34 | PhysicsMaterialResult result; 35 | 36 | // Read the type of the material 37 | uint32 hash; 38 | inStream.Read(hash); 39 | if (inStream.IsEOF() || inStream.IsFailed()) 40 | { 41 | result.SetError("Failed to read type hash"); 42 | return result; 43 | } 44 | 45 | // Get the RTTI for the material 46 | const RTTI *rtti = Factory::sInstance->Find(hash); 47 | if (rtti == nullptr) 48 | { 49 | result.SetError("Failed to create instance of material"); 50 | return result; 51 | } 52 | 53 | // Construct and read the data of the material 54 | Ref material = reinterpret_cast(rtti->CreateObject()); 55 | material->RestoreBinaryState(inStream); 56 | if (inStream.IsEOF() || inStream.IsFailed()) 57 | { 58 | result.SetError("Failed to restore material"); 59 | return result; 60 | } 61 | 62 | result.Set(material); 63 | return result; 64 | } 65 | 66 | JPH_NAMESPACE_END 67 | -------------------------------------------------------------------------------- /src/shaders/leb_update_split.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #define dispatchIndirect( \ 4 | _buffer \ 5 | , _offset \ 6 | , _numX \ 7 | , _numY \ 8 | , _numZ \ 9 | ) \ 10 | _buffer[8] = _numX; \ 11 | _buffer[9] = _numY; \ 12 | _buffer[10] = _numZ; \ 13 | _buffer[11] = 0 14 | 15 | #define drawIndexedIndirect( \ 16 | _buffer \ 17 | , _offset \ 18 | , _numIndices \ 19 | , _numInstances \ 20 | , _startIndex \ 21 | , _startVertex \ 22 | , _startInstance \ 23 | ) \ 24 | _buffer[0] = _numIndices; \ 25 | _buffer[1] = _numInstances; \ 26 | _buffer[2] = _startIndex; \ 27 | _buffer[3] = _startVertex; \ 28 | _buffer[4] = _startInstance; \ 29 | _buffer[5] = 0; \ 30 | _buffer[6] = 0; \ 31 | _buffer[7] = 0 32 | 33 | layout(std430, binding = 0) buffer cbt_Buffer { 34 | uint heap[]; 35 | } u_CbtBuffers[1]; 36 | 37 | layout (binding = 0) uniform sampler2D u_DmapSampler; 38 | 39 | #include "frustum_culling.glsl" 40 | #include "cbt.glsl" 41 | #include "leb.glsl" 42 | #include "terrain_common.glsl" 43 | 44 | layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in; 45 | 46 | void main(void) 47 | { 48 | // get threadID 49 | const int cbtID = 0; 50 | uint threadID = gl_GlobalInvocationID.x; 51 | 52 | if (threadID < cbt_NodeCount(cbtID)) { 53 | // and extract triangle vertices 54 | cbt_Node node = cbt_DecodeNode(cbtID, threadID); 55 | vec4 triangleVertices[3] = DecodeTriangleVertices(node); 56 | 57 | // compute target LoD 58 | vec2 targetLod = LevelOfDetail(triangleVertices); 59 | 60 | // splitting update 61 | if (targetLod.x > 1.0) { 62 | //leb_SplitNodeConforming_Quad(lebID, node); 63 | leb_SplitNode_Square(cbtID, node); 64 | } 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/Memory.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | JPH_SUPPRESS_WARNINGS_STD_BEGIN 8 | #include 9 | JPH_SUPPRESS_WARNINGS_STD_END 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | #ifdef JPH_DISABLE_CUSTOM_ALLOCATOR 15 | #define JPH_ALLOC_FN(x) x 16 | #define JPH_ALLOC_SCOPE 17 | #else 18 | #define JPH_ALLOC_FN(x) x##Impl 19 | #define JPH_ALLOC_SCOPE static 20 | #endif 21 | 22 | JPH_ALLOC_SCOPE void *JPH_ALLOC_FN(Allocate)(size_t inSize) 23 | { 24 | return malloc(inSize); 25 | } 26 | 27 | JPH_ALLOC_SCOPE void JPH_ALLOC_FN(Free)(void *inBlock) 28 | { 29 | free(inBlock); 30 | } 31 | 32 | JPH_ALLOC_SCOPE void *JPH_ALLOC_FN(AlignedAllocate)(size_t inSize, size_t inAlignment) 33 | { 34 | #if defined(JPH_PLATFORM_WINDOWS) 35 | // Microsoft doesn't implement C++17 std::aligned_alloc 36 | return _aligned_malloc(inSize, inAlignment); 37 | #elif defined(JPH_PLATFORM_ANDROID) 38 | return memalign(inAlignment, AlignUp(inSize, inAlignment)); 39 | #else 40 | return std::aligned_alloc(inAlignment, AlignUp(inSize, inAlignment)); 41 | #endif 42 | } 43 | 44 | JPH_ALLOC_SCOPE void JPH_ALLOC_FN(AlignedFree)(void *inBlock) 45 | { 46 | #if defined(JPH_PLATFORM_WINDOWS) 47 | _aligned_free(inBlock); 48 | #elif defined(JPH_PLATFORM_ANDROID) 49 | free(inBlock); 50 | #else 51 | std::free(inBlock); 52 | #endif 53 | } 54 | 55 | #ifndef JPH_DISABLE_CUSTOM_ALLOCATOR 56 | 57 | AllocateFunction Allocate = nullptr; 58 | FreeFunction Free = nullptr; 59 | AlignedAllocateFunction AlignedAllocate = nullptr; 60 | AlignedFreeFunction AlignedFree = nullptr; 61 | 62 | void RegisterDefaultAllocator() 63 | { 64 | Allocate = AllocateImpl; 65 | Free = FreeImpl; 66 | AlignedAllocate = AlignedAllocateImpl; 67 | AlignedFree = AlignedFreeImpl; 68 | } 69 | 70 | #endif // JPH_DISABLE_CUSTOM_ALLOCATOR 71 | 72 | JPH_NAMESPACE_END 73 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/GroupFilter.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | JPH_IMPLEMENT_SERIALIZABLE_ABSTRACT_BASE(GroupFilter) 15 | { 16 | JPH_ADD_BASE_CLASS(GroupFilter, SerializableObject) 17 | } 18 | 19 | void GroupFilter::SaveBinaryState(StreamOut &inStream) const 20 | { 21 | inStream.Write(GetRTTI()->GetHash()); 22 | } 23 | 24 | void GroupFilter::RestoreBinaryState(StreamIn &inStream) 25 | { 26 | // RTTI hash is read in sRestoreFromBinaryState 27 | } 28 | 29 | GroupFilter::GroupFilterResult GroupFilter::sRestoreFromBinaryState(StreamIn &inStream) 30 | { 31 | GroupFilterResult result; 32 | 33 | // Read the type of the group filter 34 | uint32 hash; 35 | inStream.Read(hash); 36 | if (inStream.IsEOF() || inStream.IsFailed()) 37 | { 38 | result.SetError("Failed to read type hash"); 39 | return result; 40 | } 41 | 42 | // Get the RTTI for the group filter 43 | const RTTI *rtti = Factory::sInstance->Find(hash); 44 | if (rtti == nullptr) 45 | { 46 | result.SetError("Failed to create instance of group filter"); 47 | return result; 48 | } 49 | 50 | // Construct and read the data of the group filter 51 | Ref group_filter = reinterpret_cast(rtti->CreateObject()); 52 | if (group_filter == nullptr) 53 | { 54 | result.SetError("Failed to create instance of group filter"); 55 | return result; 56 | } 57 | group_filter->RestoreBinaryState(inStream); 58 | if (inStream.IsEOF() || inStream.IsFailed()) 59 | { 60 | result.SetError("Failed to restore group filter"); 61 | return result; 62 | } 63 | 64 | result.Set(group_filter); 65 | return result; 66 | } 67 | 68 | JPH_NAMESPACE_END 69 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleSplitter/TriangleSplitterFixedLeafSize.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | /// Same as TriangleSplitterBinning, but ensuring that leaves have a fixed amount of triangles 13 | /// The resulting tree should be suitable for processing on GPU where we want all threads to process an equal amount of triangles 14 | class TriangleSplitterFixedLeafSize : public TriangleSplitter 15 | { 16 | public: 17 | /// Constructor 18 | TriangleSplitterFixedLeafSize(const VertexList &inVertices, const IndexedTriangleList &inTriangles, uint inLeafSize, uint inMinNumBins = 8, uint inMaxNumBins = 128, uint inNumTrianglesPerBin = 6); 19 | 20 | // See TriangleSplitter::GetStats 21 | virtual void GetStats(Stats &outStats) const override 22 | { 23 | outStats.mSplitterName = "TriangleSplitterFixedLeafSize"; 24 | outStats.mLeafSize = mLeafSize; 25 | } 26 | 27 | // See TriangleSplitter::Split 28 | virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) override; 29 | 30 | private: 31 | /// Get centroid for group 32 | Vec3 GetCentroidForGroup(uint inFirstTriangleInGroup); 33 | 34 | // Configuration 35 | const uint mLeafSize; 36 | const uint mMinNumBins; 37 | const uint mMaxNumBins; 38 | const uint mNumTrianglesPerBin; 39 | 40 | struct Bin 41 | { 42 | // Properties of this bin 43 | AABox mBounds; 44 | float mMinCentroid; 45 | uint mNumTriangles; 46 | 47 | // Accumulated data from left most / right most bin to current (including this bin) 48 | AABox mBoundsAccumulatedLeft; 49 | AABox mBoundsAccumulatedRight; 50 | uint mNumTrianglesAccumulatedLeft; 51 | uint mNumTrianglesAccumulatedRight; 52 | }; 53 | }; 54 | 55 | JPH_NAMESPACE_END 56 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/STLTempAllocator.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// STL allocator that wraps around TempAllocator 12 | template 13 | class STLTempAllocator 14 | { 15 | public: 16 | using value_type = T; 17 | 18 | /// Pointer to type 19 | using pointer = T *; 20 | using const_pointer = const T *; 21 | 22 | /// Reference to type. 23 | /// Can be removed in C++20. 24 | using reference = T &; 25 | using const_reference = const T &; 26 | 27 | using size_type = size_t; 28 | using difference_type = ptrdiff_t; 29 | 30 | /// Constructor 31 | inline STLTempAllocator(TempAllocator &inAllocator) : mAllocator(inAllocator) { } 32 | 33 | /// Constructor from other allocator 34 | template 35 | inline explicit STLTempAllocator(const STLTempAllocator &inRHS) : mAllocator(inRHS.GetAllocator()) { } 36 | 37 | /// Allocate memory 38 | inline pointer allocate(size_type inN) 39 | { 40 | return (pointer)mAllocator.Allocate(uint(inN * sizeof(value_type))); 41 | } 42 | 43 | /// Free memory 44 | inline void deallocate(pointer inPointer, size_type inN) 45 | { 46 | mAllocator.Free(inPointer, uint(inN * sizeof(value_type))); 47 | } 48 | 49 | /// Allocators are stateless so assumed to be equal 50 | inline bool operator == (const STLTempAllocator &) const 51 | { 52 | return true; 53 | } 54 | 55 | inline bool operator != (const STLTempAllocator &) const 56 | { 57 | return false; 58 | } 59 | 60 | /// Converting to allocator for other type 61 | template 62 | struct rebind 63 | { 64 | using other = STLTempAllocator; 65 | }; 66 | 67 | /// Get our temp allocator 68 | TempAllocator & GetAllocator() const 69 | { 70 | return mAllocator; 71 | } 72 | 73 | private: 74 | TempAllocator & mAllocator; 75 | }; 76 | 77 | JPH_NAMESPACE_END 78 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/Color.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | // Predefined colors 12 | const Color Color::sBlack(0, 0, 0); 13 | const Color Color::sDarkRed(128, 0, 0); 14 | const Color Color::sRed(255, 0, 0); 15 | const Color Color::sDarkGreen(0, 128, 0); 16 | const Color Color::sGreen(0, 255, 0); 17 | const Color Color::sDarkBlue(0, 0, 128); 18 | const Color Color::sBlue(0, 0, 255); 19 | const Color Color::sYellow(255, 255, 0); 20 | const Color Color::sPurple(255, 0, 255); 21 | const Color Color::sCyan(0, 255, 255); 22 | const Color Color::sOrange(255, 128, 0); 23 | const Color Color::sDarkOrange(128, 64, 0); 24 | const Color Color::sGrey(128, 128, 128); 25 | const Color Color::sLightGrey(192, 192, 192); 26 | const Color Color::sWhite(255, 255, 255); 27 | 28 | // Generated by: http://phrogz.net/css/distinct-colors.html (this algo: https://en.wikipedia.org/wiki/Color_difference#CMC_l:c_.281984.29) 29 | static constexpr Color sColors[] = { Color(255, 0, 0), Color(204, 143, 102), Color(226, 242, 0), Color(41, 166, 124), Color(0, 170, 255), Color(69, 38, 153), Color(153, 38, 130), Color(229, 57, 80), Color(204, 0, 0), Color(255, 170, 0), Color(85, 128, 0), Color(64, 255, 217), Color(0, 75, 140), Color(161, 115, 230), Color(242, 61, 157), Color(178, 101, 89), Color(140, 94, 0), Color(181, 217, 108), Color(64, 242, 255), Color(77, 117, 153), Color(157, 61, 242), Color(140, 0, 56), Color(127, 57, 32), Color(204, 173, 51), Color(64, 255, 64), Color(38, 145, 153), Color(0, 102, 255), Color(242, 0, 226), Color(153, 77, 107), Color(229, 92, 0), Color(140, 126, 70), Color(0, 179, 71), Color(0, 194, 242), Color(27, 0, 204), Color(230, 115, 222), Color(127, 0, 17) }; 30 | 31 | Color Color::sGetDistinctColor(int inIndex) 32 | { 33 | JPH_ASSERT(inIndex >= 0); 34 | 35 | return sColors[inIndex % (sizeof(sColors) / sizeof(uint32))]; 36 | } 37 | 38 | JPH_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /thirdparty/ozz-util/ozz_util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | A quick'n'dirty C-API wrapper for some ozz-animation features. 4 | */ 5 | #include 6 | #include 7 | 8 | #if defined(__cplusplus) 9 | extern "C" { 10 | #endif 11 | 12 | typedef void* ozz_t; 13 | typedef void* ozz_instance_t; 14 | 15 | typedef struct { 16 | float position[3]; 17 | uint32_t normal; 18 | uint32_t joint_indices; 19 | uint32_t joint_weights; 20 | } ozz_vertex_t; 21 | 22 | typedef struct { 23 | int max_palette_joints; 24 | int max_instances; 25 | } ozz_desc_t; 26 | 27 | typedef void (*create_vbuf_callback_t)(ozz_vertex_t* verts, size_t num_verts); 28 | typedef void (*create_ibuf_callback_t)(uint16_t* indices, size_t num_indices); 29 | 30 | void ozz_setup(const ozz_desc_t* desc); 31 | void ozz_shutdown(void); 32 | // sg_image ozz_joint_texture(void); 33 | float* ozz_joint_upload_buffer(void); 34 | int ozz_joint_texture_pitch(void); 35 | int ozz_joint_texture_width(void); 36 | int ozz_joint_texture_height(void); 37 | ozz_instance_t* ozz_create_instance(int index); 38 | void ozz_destroy_instance(ozz_instance_t* ozz); 39 | // sg_buffer ozz_vertex_buffer(ozz_instance_t* ozz); 40 | // sg_buffer ozz_index_buffer(ozz_instance_t* ozz); 41 | bool ozz_all_loaded(ozz_instance_t* ozz); 42 | bool ozz_load_failed(ozz_instance_t* ozz); 43 | void ozz_load_skeleton(ozz_instance_t* ozz, const void* data, size_t num_bytes); 44 | void ozz_load_animation(ozz_instance_t* ozz, const void* data, size_t num_bytes); 45 | void ozz_load_mesh(ozz_instance_t* ozz, const void* data, size_t num_bytes, create_vbuf_callback_t create_vbuf_cb, create_ibuf_callback_t create_ibuf_cb); 46 | void ozz_set_load_failed(ozz_instance_t* ozz); 47 | void ozz_update_instance(ozz_instance_t* ozz, double seconds); 48 | void ozz_update_joint_texture(void); 49 | float ozz_joint_texture_pixel_width(void); 50 | float ozz_joint_texture_u(ozz_instance_t* ozz); 51 | float ozz_joint_texture_v(ozz_instance_t* ozz); 52 | int ozz_num_triangle_indices(ozz_instance_t* ozz); 53 | 54 | #if defined(__cplusplus) 55 | } // extern "C" 56 | #endif -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/SortReverseAndStore.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// This function will sort values from high to low and only keep the ones that are less than inMaxValue 10 | /// @param inValues Values to be sorted 11 | /// @param inMaxValue Values need to be less than this to keep them 12 | /// @param ioIdentifiers 4 identifiers that will be sorted in the same way as the values 13 | /// @param outValues The values are stored here from high to low 14 | /// @return The number of values that were kept 15 | JPH_INLINE int SortReverseAndStore(Vec4Arg inValues, float inMaxValue, UVec4 &ioIdentifiers, float *outValues) 16 | { 17 | // Sort so that highest values are first (we want to first process closer hits and we process stack top to bottom) 18 | Vec4::sSort4Reverse(inValues, ioIdentifiers); 19 | 20 | // Count how many results are less than the max value 21 | UVec4 closer = Vec4::sLess(inValues, Vec4::sReplicate(inMaxValue)); 22 | int num_results = closer.CountTrues(); 23 | 24 | // Shift the values so that only the ones that are less than max are kept 25 | inValues = inValues.ReinterpretAsInt().ShiftComponents4Minus(num_results).ReinterpretAsFloat(); 26 | ioIdentifiers = ioIdentifiers.ShiftComponents4Minus(num_results); 27 | 28 | // Store the values 29 | inValues.StoreFloat4((Float4 *)outValues); 30 | 31 | return num_results; 32 | } 33 | 34 | /// Shift the elements so that the identifiers that correspond with the trues in inValue come first 35 | /// @param inValue Values to test for true or false 36 | /// @param ioIdentifiers the identifiers that are shifted, on return they are shifted 37 | /// @return The number of trues 38 | JPH_INLINE int CountAndSortTrues(UVec4Arg inValue, UVec4 &ioIdentifiers) 39 | { 40 | // Sort the hits 41 | ioIdentifiers = UVec4::sSort4True(inValue, ioIdentifiers); 42 | 43 | // Return the amount of hits 44 | return inValue.CountTrues(); 45 | } 46 | 47 | JPH_NAMESPACE_END 48 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/ByteBuffer.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Underlying data type for ByteBuffer 12 | using ByteBufferVector = std::vector>; 13 | 14 | /// Simple byte buffer, aligned to a cache line 15 | class ByteBuffer : public ByteBufferVector 16 | { 17 | public: 18 | /// Align the size to a multiple of inSize, returns the length after alignment 19 | size_t Align(size_t inSize) 20 | { 21 | // Assert power of 2 22 | JPH_ASSERT(IsPowerOf2(inSize)); 23 | 24 | // Calculate new size and resize buffer 25 | size_t s = AlignUp(size(), inSize); 26 | resize(s); 27 | 28 | return s; 29 | } 30 | 31 | /// Allocate block of data of inSize elements and return the pointer 32 | template 33 | Type * Allocate(size_t inSize = 1) 34 | { 35 | // Reserve space 36 | size_t s = size(); 37 | resize(s + inSize * sizeof(Type)); 38 | 39 | // Get data pointer 40 | Type *data = reinterpret_cast(&at(s)); 41 | 42 | // Construct elements 43 | for (Type *d = data, *d_end = data + inSize; d < d_end; ++d) 44 | ::new (d) Type; 45 | 46 | // Return pointer 47 | return data; 48 | } 49 | 50 | /// Append inData to the buffer 51 | template 52 | void AppendVector(const Array &inData) 53 | { 54 | size_t size = inData.size() * sizeof(Type); 55 | uint8 *data = Allocate(size); 56 | memcpy(data, &inData[0], size); 57 | } 58 | 59 | /// Get object at inPosition (an offset in bytes) 60 | template 61 | const Type * Get(size_t inPosition) const 62 | { 63 | return reinterpret_cast(&at(inPosition)); 64 | } 65 | 66 | /// Get object at inPosition (an offset in bytes) 67 | template 68 | Type * Get(size_t inPosition) 69 | { 70 | return reinterpret_cast(&at(inPosition)); 71 | } 72 | }; 73 | 74 | JPH_NAMESPACE_END 75 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/PhysicsMaterial.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | class StreamIn; 15 | class StreamOut; 16 | 17 | /// This structure describes the surface of (part of) a shape. You should inherit from it to define additional 18 | /// information that is interesting for the simulation. The 2 materials involved in a contact could be used 19 | /// to decide which sound or particle effects to play. 20 | /// 21 | /// If you inherit from this material, don't forget to create a suitable default material in sDefault 22 | class PhysicsMaterial : public SerializableObject, public RefTarget 23 | { 24 | public: 25 | JPH_DECLARE_SERIALIZABLE_VIRTUAL(PhysicsMaterial) 26 | 27 | /// Virtual destructor 28 | virtual ~PhysicsMaterial() override = default; 29 | 30 | /// Default material that is used when a shape has no materials defined 31 | static RefConst sDefault; 32 | 33 | // Properties 34 | virtual const char * GetDebugName() const { return "Unknown"; } 35 | virtual Color GetDebugColor() const { return Color::sGrey; } 36 | 37 | /// Saves the contents of the material in binary form to inStream. 38 | virtual void SaveBinaryState(StreamOut &inStream) const; 39 | 40 | using PhysicsMaterialResult = Result>; 41 | 42 | /// Creates a PhysicsMaterial of the correct type and restores its contents from the binary stream inStream. 43 | static PhysicsMaterialResult sRestoreFromBinaryState(StreamIn &inStream); 44 | 45 | protected: 46 | /// This function should not be called directly, it is used by sRestoreFromBinaryState. 47 | virtual void RestoreBinaryState(StreamIn &inStream); 48 | }; 49 | 50 | using PhysicsMaterialList = Array>; 51 | 52 | JPH_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Constraints/TwoBodyConstraint.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef JPH_DEBUG_RENDERER 13 | #include 14 | #endif // JPH_DEBUG_RENDERER 15 | 16 | JPH_NAMESPACE_BEGIN 17 | 18 | JPH_IMPLEMENT_SERIALIZABLE_ABSTRACT(TwoBodyConstraintSettings) 19 | { 20 | JPH_ADD_BASE_CLASS(TwoBodyConstraintSettings, ConstraintSettings) 21 | } 22 | 23 | void TwoBodyConstraint::BuildIslands(uint32 inConstraintIndex, IslandBuilder &ioBuilder, BodyManager &inBodyManager) 24 | { 25 | // Activate bodies 26 | BodyID body_ids[2]; 27 | int num_bodies = 0; 28 | if (mBody1->IsDynamic() && !mBody1->IsActive()) 29 | body_ids[num_bodies++] = mBody1->GetID(); 30 | if (mBody2->IsDynamic() && !mBody2->IsActive()) 31 | body_ids[num_bodies++] = mBody2->GetID(); 32 | if (num_bodies > 0) 33 | inBodyManager.ActivateBodies(body_ids, num_bodies); 34 | 35 | // Link the bodies into the same island 36 | ioBuilder.LinkConstraint(inConstraintIndex, mBody1->GetIndexInActiveBodiesInternal(), mBody2->GetIndexInActiveBodiesInternal()); 37 | } 38 | 39 | uint TwoBodyConstraint::BuildIslandSplits(LargeIslandSplitter &ioSplitter) const 40 | { 41 | return ioSplitter.AssignSplit(mBody1, mBody2); 42 | } 43 | 44 | #ifdef JPH_DEBUG_RENDERER 45 | 46 | void TwoBodyConstraint::DrawConstraintReferenceFrame(DebugRenderer *inRenderer) const 47 | { 48 | RMat44 transform1 = mBody1->GetCenterOfMassTransform() * GetConstraintToBody1Matrix(); 49 | RMat44 transform2 = mBody2->GetCenterOfMassTransform() * GetConstraintToBody2Matrix(); 50 | inRenderer->DrawCoordinateSystem(transform1, 1.1f * mDrawConstraintSize); 51 | inRenderer->DrawCoordinateSystem(transform2, mDrawConstraintSize); 52 | } 53 | 54 | #endif // JPH_DEBUG_RENDERER 55 | 56 | JPH_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /src/shaders/terrain.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #define NUM_INSTANCES 9 4 | 5 | layout(location = POSITION) in vec4 position; 6 | layout(location = TEXCOORD0) in vec2 inTexCoords; 7 | 8 | // layout(set = 0, binding = 0) uniform sampler linearSampler; 9 | // layout(set = 0, binding = 1) uniform texture2D colorTexture; 10 | layout(binding = 0) uniform sampler2D heightmap; 11 | 12 | struct Instance { 13 | mat4 modelViewMatrix; 14 | mat4 modelViewProjectionMatrix; 15 | }; 16 | 17 | layout(std140, binding = 0) uniform Uniforms { 18 | Instance instances[NUM_INSTANCES]; 19 | } uniforms; 20 | 21 | layout(location = POSITION) out vec4 eyePosition; 22 | layout(location = TEXCOORD0) out vec3 normal; 23 | layout(location = TEXCOORD1) out vec2 outTexCoords; 24 | 25 | void main() { 26 | // Displacement mapping constants 27 | float patchSize = 50.0; 28 | float heightScale = 8.0; 29 | vec3 d = vec3(1.0 / 150.0, 1.0 / 150.0, 0.0); 30 | float dydy = heightScale / patchSize; 31 | 32 | // Calculate displacement and differentials (for normal calculation) 33 | // float height = texture(sampler2D(heightmap, linearSampler), inTexCoords).r; 34 | float height = texture(heightmap, inTexCoords).r; 35 | float dydx = height - texture(heightmap, inTexCoords + d.xz).r; 36 | float dydz = height - texture(heightmap, inTexCoords + d.zy).r; 37 | 38 | // Calculate model-space vertex position and normal 39 | vec4 modelPosition = vec4(position.x, position.y + height * heightScale, position.z, 1.0); 40 | vec4 modelNormal = vec4(normalize(vec3(dydx, dydy, dydz)), 0.0); 41 | 42 | // Retrieve MV and MVP matrices from instance data 43 | mat4 modelViewMatrix = uniforms.instances[gl_InstanceIndex].modelViewMatrix; 44 | mat4 modelViewProjectionMatrix = uniforms.instances[gl_InstanceIndex].modelViewProjectionMatrix; 45 | 46 | gl_Position = modelViewProjectionMatrix * modelPosition; // clip space position 47 | eyePosition = modelViewMatrix * modelPosition; // eye space position 48 | normal = (modelViewMatrix * modelNormal).xyz; // eye space normal 49 | outTexCoords = inTexCoords; 50 | } -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Collision/NarrowPhaseStats.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | #ifdef JPH_TRACK_NARROWPHASE_STATS 10 | 11 | JPH_NAMESPACE_BEGIN 12 | 13 | NarrowPhaseStat NarrowPhaseStat::sCollideShape[NumSubShapeTypes][NumSubShapeTypes]; 14 | NarrowPhaseStat NarrowPhaseStat::sCastShape[NumSubShapeTypes][NumSubShapeTypes]; 15 | 16 | thread_local TrackNarrowPhaseStat *TrackNarrowPhaseStat::sRoot = nullptr; 17 | 18 | void NarrowPhaseStat::ReportStats(const char *inName, EShapeSubType inType1, EShapeSubType inType2) const 19 | { 20 | uint64 ticks_per_sec = GetProcessorTicksPerSecond(); 21 | 22 | double total_time = 1000.0 * double(mTotalTicks) / double(ticks_per_sec); 23 | double total_time_excl_children = 1000.0 * double(mTotalTicks - mChildTicks) / double(ticks_per_sec); 24 | 25 | stringstream str; 26 | str << inName << ", " << sSubShapeTypeNames[(int)inType1] << ", " << sSubShapeTypeNames[(int)inType2] << ", " << mNumQueries << ", " << total_time << ", " << total_time_excl_children << ", " << total_time_excl_children / mNumQueries << ", " << mHitsReported; 27 | Trace(str.str().c_str()); 28 | } 29 | 30 | void NarrowPhaseStat::sReportStats() 31 | { 32 | Trace("Query Type, Shape Type 1, Shape Type 2, Num Queries, Total Time (ms), Total Time Excl Children (ms), Total Time Excl. Children / Query (ms), Hits Reported"); 33 | 34 | for (EShapeSubType t1 : sAllSubShapeTypes) 35 | for (EShapeSubType t2 : sAllSubShapeTypes) 36 | { 37 | const NarrowPhaseStat &stat = sCollideShape[(int)t1][(int)t2]; 38 | if (stat.mNumQueries > 0) 39 | stat.ReportStats("CollideShape", t1, t2); 40 | } 41 | 42 | for (EShapeSubType t1 : sAllSubShapeTypes) 43 | for (EShapeSubType t2 : sAllSubShapeTypes) 44 | { 45 | const NarrowPhaseStat &stat = sCastShape[(int)t1][(int)t2]; 46 | if (stat.mNumQueries > 0) 47 | stat.ReportStats("CastShape", t1, t2); 48 | } 49 | } 50 | 51 | JPH_NAMESPACE_END 52 | 53 | #endif // JPH_TRACK_NARROWPHASE_STATS 54 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/ObjectStreamTextIn.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Implementation of ObjectStream text input stream. 12 | class ObjectStreamTextIn : public ObjectStreamIn 13 | { 14 | public: 15 | JPH_OVERRIDE_NEW_DELETE 16 | 17 | /// Constructor 18 | explicit ObjectStreamTextIn(istream &inStream); 19 | 20 | ///@name Input type specific operations 21 | virtual bool ReadDataType(EOSDataType &outType) override; 22 | virtual bool ReadName(String &outName) override; 23 | virtual bool ReadIdentifier(Identifier &outIdentifier) override; 24 | virtual bool ReadCount(uint32 &outCount) override; 25 | 26 | virtual bool ReadPrimitiveData(uint8 &outPrimitive) override; 27 | virtual bool ReadPrimitiveData(uint16 &outPrimitive) override; 28 | virtual bool ReadPrimitiveData(int &outPrimitive) override; 29 | virtual bool ReadPrimitiveData(uint32 &outPrimitive) override; 30 | virtual bool ReadPrimitiveData(uint64 &outPrimitive) override; 31 | virtual bool ReadPrimitiveData(float &outPrimitive) override; 32 | virtual bool ReadPrimitiveData(double &outPrimitive) override; 33 | virtual bool ReadPrimitiveData(bool &outPrimitive) override; 34 | virtual bool ReadPrimitiveData(String &outPrimitive) override; 35 | virtual bool ReadPrimitiveData(Float3 &outPrimitive) override; 36 | virtual bool ReadPrimitiveData(Double3 &outPrimitive) override; 37 | virtual bool ReadPrimitiveData(Vec3 &outPrimitive) override; 38 | virtual bool ReadPrimitiveData(DVec3 &outPrimitive) override; 39 | virtual bool ReadPrimitiveData(Vec4 &outPrimitive) override; 40 | virtual bool ReadPrimitiveData(Quat &outPrimitive) override; 41 | virtual bool ReadPrimitiveData(Mat44 &outPrimitive) override; 42 | virtual bool ReadPrimitiveData(DMat44 &outPrimitive) override; 43 | 44 | private: 45 | bool ReadChar(char &outChar); 46 | bool ReadWord(String &outWord); 47 | }; 48 | 49 | JPH_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/StreamOut.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | JPH_NAMESPACE_BEGIN 8 | 9 | /// Simple binary output stream 10 | class StreamOut 11 | { 12 | public: 13 | /// Virtual destructor 14 | virtual ~StreamOut() = default; 15 | 16 | /// Write a string of bytes to the binary stream 17 | virtual void WriteBytes(const void *inData, size_t inNumBytes) = 0; 18 | 19 | /// Returns true if there was an IO failure 20 | virtual bool IsFailed() const = 0; 21 | 22 | /// Write a primitive (e.g. float, int, etc.) to the binary stream 23 | template 24 | void Write(const T &inT) 25 | { 26 | WriteBytes(&inT, sizeof(inT)); 27 | } 28 | 29 | /// Write a vector of primitives from the binary stream 30 | template 31 | void Write(const std::vector &inT) 32 | { 33 | typename Array::size_type len = inT.size(); 34 | Write(len); 35 | if (!IsFailed()) 36 | for (typename Array::size_type i = 0; i < len; ++i) 37 | Write(inT[i]); 38 | } 39 | 40 | /// Write a string to the binary stream (writes the number of characters and then the characters) 41 | template 42 | void Write(const std::basic_string &inString) 43 | { 44 | typename std::basic_string::size_type len = inString.size(); 45 | Write(len); 46 | if (!IsFailed()) 47 | WriteBytes(inString.data(), len * sizeof(Type)); 48 | } 49 | 50 | /// Write a Vec3 (don't write W) 51 | void Write(const Vec3 &inVec) 52 | { 53 | WriteBytes(&inVec, 3 * sizeof(float)); 54 | } 55 | 56 | /// Write a DVec3 (don't write W) 57 | void Write(const DVec3 &inVec) 58 | { 59 | WriteBytes(&inVec, 3 * sizeof(double)); 60 | } 61 | 62 | /// Write a DMat44 (don't write W component of translation) 63 | void Write(const DMat44 &inVec) 64 | { 65 | Write(inVec.GetColumn4(0)); 66 | Write(inVec.GetColumn4(1)); 67 | Write(inVec.GetColumn4(2)); 68 | 69 | Write(inVec.GetTranslation()); 70 | } 71 | }; 72 | 73 | JPH_NAMESPACE_END 74 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Skeleton/Skeleton.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | JPH_NAMESPACE_BEGIN 13 | 14 | JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(Skeleton::Joint) 15 | { 16 | JPH_ADD_ATTRIBUTE(Joint, mName) 17 | JPH_ADD_ATTRIBUTE(Joint, mParentName) 18 | } 19 | 20 | JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(Skeleton) 21 | { 22 | JPH_ADD_ATTRIBUTE(Skeleton, mJoints) 23 | } 24 | 25 | int Skeleton::GetJointIndex(const string_view &inName) const 26 | { 27 | for (int i = 0; i < (int)mJoints.size(); ++i) 28 | if (mJoints[i].mName == inName) 29 | return i; 30 | 31 | return -1; 32 | } 33 | 34 | void Skeleton::CalculateParentJointIndices() 35 | { 36 | for (Joint &j : mJoints) 37 | j.mParentJointIndex = GetJointIndex(j.mParentName); 38 | } 39 | 40 | bool Skeleton::AreJointsCorrectlyOrdered() const 41 | { 42 | for (int i = 0; i < (int)mJoints.size(); ++i) 43 | if (mJoints[i].mParentJointIndex >= i) 44 | return false; 45 | 46 | return true; 47 | } 48 | 49 | void Skeleton::SaveBinaryState(StreamOut &inStream) const 50 | { 51 | inStream.Write((uint32)mJoints.size()); 52 | for (const Joint &j : mJoints) 53 | { 54 | inStream.Write(j.mName); 55 | inStream.Write(j.mParentJointIndex); 56 | inStream.Write(j.mParentName); 57 | } 58 | } 59 | 60 | Skeleton::SkeletonResult Skeleton::sRestoreFromBinaryState(StreamIn &inStream) 61 | { 62 | Ref skeleton = new Skeleton; 63 | 64 | uint32 len = 0; 65 | inStream.Read(len); 66 | skeleton->mJoints.resize(len); 67 | for (Joint &j : skeleton->mJoints) 68 | { 69 | inStream.Read(j.mName); 70 | inStream.Read(j.mParentJointIndex); 71 | inStream.Read(j.mParentName); 72 | } 73 | 74 | SkeletonResult result; 75 | if (inStream.IsEOF() || inStream.IsFailed()) 76 | result.SetError("Failed to read skeleton from stream"); 77 | else 78 | result.Set(skeleton); 79 | return result; 80 | } 81 | 82 | JPH_NAMESPACE_END 83 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Vehicle/VehicleTrack.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | JPH_NAMESPACE_BEGIN 14 | 15 | /// On which side of the vehicle the track is located (for steering) 16 | enum class ETrackSide : uint 17 | { 18 | Left = 0, 19 | Right = 1, 20 | Num = 2 21 | }; 22 | 23 | /// Generic properties for tank tracks 24 | class VehicleTrackSettings 25 | { 26 | public: 27 | JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(VehicleTrackSettings) 28 | 29 | /// Saves the contents in binary form to inStream. 30 | void SaveBinaryState(StreamOut &inStream) const; 31 | 32 | /// Restores the contents in binary form to inStream. 33 | void RestoreBinaryState(StreamIn &inStream); 34 | 35 | uint mDrivenWheel; ///< Which wheel on the track is connected to the engine 36 | Array mWheels; ///< Indices of wheels that are inside this track, should include the driven wheel too 37 | float mInertia = 10.0f; ///< Moment of inertia (kg m^2) of the track and its wheels as seen on the driven wheel 38 | float mAngularDamping = 0.5f; ///< Damping factor of track and its wheels: dw/dt = -c * w as seen on the driven wheel 39 | float mMaxBrakeTorque = 15000.0f; ///< How much torque (Nm) the brakes can apply on the driven wheel 40 | float mDifferentialRatio = 6.0f; ///< Ratio between rotation speed of gear box and driven wheel of track 41 | }; 42 | 43 | /// Runtime data for tank tracks 44 | class VehicleTrack : public VehicleTrackSettings 45 | { 46 | public: 47 | /// Saving state for replay 48 | void SaveState(StateRecorder &inStream) const; 49 | void RestoreState(StateRecorder &inStream); 50 | 51 | float mAngularVelocity = 0.0f; ///< Angular velocity of the driven wheel, will determine the speed of the entire track 52 | }; 53 | 54 | using VehicleTracks = VehicleTrack[(int)ETrackSide::Num]; 55 | 56 | JPH_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/LinearCurve.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | class StreamOut; 13 | class StreamIn; 14 | 15 | // A set of points (x, y) that form a linear curve 16 | class LinearCurve 17 | { 18 | public: 19 | JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(LinearCurve) 20 | 21 | /// A point on the curve 22 | class Point 23 | { 24 | public: 25 | JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(Point) 26 | 27 | float mX = 0.0f; 28 | float mY = 0.0f; 29 | }; 30 | 31 | /// Remove all points 32 | void Clear() { mPoints.clear(); } 33 | 34 | /// Reserve memory for inNumPoints points 35 | void Reserve(uint inNumPoints) { mPoints.reserve(inNumPoints); } 36 | 37 | /// Add a point to the curve. Points must be inserted in ascending X or Sort() needs to be called when all points have been added. 38 | /// @param inX X value 39 | /// @param inY Y value 40 | void AddPoint(float inX, float inY) { mPoints.push_back({ inX, inY }); } 41 | 42 | /// Sort the points on X ascending 43 | void Sort() { QuickSort(mPoints.begin(), mPoints.end(), [](const Point &inLHS, const Point &inRHS) { return inLHS.mX < inRHS.mX; }); } 44 | 45 | /// Get the lowest X value 46 | float GetMinX() const { return mPoints.empty()? 0.0f : mPoints.front().mX; } 47 | 48 | /// Get the highest X value 49 | float GetMaxX() const { return mPoints.empty()? 0.0f : mPoints.back().mX; } 50 | 51 | /// Sample value on the curve 52 | /// @param inX X value to sample at 53 | /// @return Interpolated Y value 54 | float GetValue(float inX) const; 55 | 56 | /// Saves the state of this object in binary form to inStream. 57 | void SaveBinaryState(StreamOut &inStream) const; 58 | 59 | /// Restore the state of this object from inStream. 60 | void RestoreBinaryState(StreamIn &inStream); 61 | 62 | /// The points on the curve, should be sorted ascending by x 63 | using Points = Array; 64 | Points mPoints; 65 | }; 66 | 67 | JPH_NAMESPACE_END 68 | -------------------------------------------------------------------------------- /thirdparty/Jolt/ObjectStream/ObjectStreamBinaryIn.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// Implementation of ObjectStream binary input stream. 12 | class ObjectStreamBinaryIn : public ObjectStreamIn 13 | { 14 | public: 15 | JPH_OVERRIDE_NEW_DELETE 16 | 17 | /// Constructor 18 | explicit ObjectStreamBinaryIn(istream &inStream); 19 | 20 | ///@name Input type specific operations 21 | virtual bool ReadDataType(EOSDataType &outType) override; 22 | virtual bool ReadName(String &outName) override; 23 | virtual bool ReadIdentifier(Identifier &outIdentifier) override; 24 | virtual bool ReadCount(uint32 &outCount) override; 25 | 26 | virtual bool ReadPrimitiveData(uint8 &outPrimitive) override; 27 | virtual bool ReadPrimitiveData(uint16 &outPrimitive) override; 28 | virtual bool ReadPrimitiveData(int &outPrimitive) override; 29 | virtual bool ReadPrimitiveData(uint32 &outPrimitive) override; 30 | virtual bool ReadPrimitiveData(uint64 &outPrimitive) override; 31 | virtual bool ReadPrimitiveData(float &outPrimitive) override; 32 | virtual bool ReadPrimitiveData(double &outPrimitive) override; 33 | virtual bool ReadPrimitiveData(bool &outPrimitive) override; 34 | virtual bool ReadPrimitiveData(String &outPrimitive) override; 35 | virtual bool ReadPrimitiveData(Float3 &outPrimitive) override; 36 | virtual bool ReadPrimitiveData(Double3 &outPrimitive) override; 37 | virtual bool ReadPrimitiveData(Vec3 &outPrimitive) override; 38 | virtual bool ReadPrimitiveData(DVec3 &outPrimitive) override; 39 | virtual bool ReadPrimitiveData(Vec4 &outPrimitive) override; 40 | virtual bool ReadPrimitiveData(Quat &outPrimitive) override; 41 | virtual bool ReadPrimitiveData(Mat44 &outPrimitive) override; 42 | virtual bool ReadPrimitiveData(DMat44 &outPrimitive) override; 43 | 44 | private: 45 | using StringTable = UnorderedMap; 46 | 47 | StringTable mStringTable; 48 | uint32 mNextStringID = 0x80000000; 49 | }; 50 | 51 | JPH_NAMESPACE_END 52 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/Semaphore.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2023 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | #ifdef JPH_PLATFORM_WINDOWS 10 | JPH_SUPPRESS_WARNING_PUSH 11 | JPH_MSVC_SUPPRESS_WARNING(5039) // winbase.h(13179): warning C5039: 'TpSetCallbackCleanupGroup': pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc. Undefined behavior may occur if this function throws an exception. 12 | #define WIN32_LEAN_AND_MEAN 13 | #ifndef JPH_COMPILER_MINGW 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | JPH_SUPPRESS_WARNING_POP 20 | #endif 21 | 22 | JPH_NAMESPACE_BEGIN 23 | 24 | Semaphore::Semaphore() 25 | { 26 | #ifdef JPH_PLATFORM_WINDOWS 27 | mSemaphore = CreateSemaphore(nullptr, 0, INT_MAX, nullptr); 28 | #endif 29 | } 30 | 31 | Semaphore::~Semaphore() 32 | { 33 | #ifdef JPH_PLATFORM_WINDOWS 34 | CloseHandle(mSemaphore); 35 | #endif 36 | } 37 | 38 | void Semaphore::Release(uint inNumber) 39 | { 40 | JPH_ASSERT(inNumber > 0); 41 | 42 | #ifdef JPH_PLATFORM_WINDOWS 43 | int old_value = mCount.fetch_add(inNumber); 44 | if (old_value < 0) 45 | { 46 | int new_value = old_value + (int)inNumber; 47 | int num_to_release = min(new_value, 0) - old_value; 48 | ::ReleaseSemaphore(mSemaphore, num_to_release, nullptr); 49 | } 50 | #else 51 | std::lock_guard lock(mLock); 52 | mCount += (int)inNumber; 53 | if (inNumber > 1) 54 | mWaitVariable.notify_all(); 55 | else 56 | mWaitVariable.notify_one(); 57 | #endif 58 | } 59 | 60 | void Semaphore::Acquire(uint inNumber) 61 | { 62 | JPH_ASSERT(inNumber > 0); 63 | 64 | #ifdef JPH_PLATFORM_WINDOWS 65 | int old_value = mCount.fetch_sub(inNumber); 66 | int new_value = old_value - (int)inNumber; 67 | if (new_value < 0) 68 | { 69 | int num_to_acquire = min(old_value, 0) - new_value; 70 | for (int i = 0; i < num_to_acquire; ++i) 71 | WaitForSingleObject(mSemaphore, INFINITE); 72 | } 73 | #else 74 | std::unique_lock lock(mLock); 75 | mCount -= (int)inNumber; 76 | mWaitVariable.wait(lock, [this]() { return mCount >= 0; }); 77 | #endif 78 | } 79 | 80 | JPH_NAMESPACE_END 81 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Math/Vec3.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | static void sCreateVertices(std::unordered_set &ioVertices, Vec3Arg inDir1, Vec3Arg inDir2, Vec3Arg inDir3, int inLevel) 13 | { 14 | Vec3 center1 = (inDir1 + inDir2).Normalized(); 15 | Vec3 center2 = (inDir2 + inDir3).Normalized(); 16 | Vec3 center3 = (inDir3 + inDir1).Normalized(); 17 | 18 | ioVertices.insert(center1); 19 | ioVertices.insert(center2); 20 | ioVertices.insert(center3); 21 | 22 | if (inLevel > 0) 23 | { 24 | int new_level = inLevel - 1; 25 | sCreateVertices(ioVertices, inDir1, center1, center3, new_level); 26 | sCreateVertices(ioVertices, center1, center2, center3, new_level); 27 | sCreateVertices(ioVertices, center1, inDir2, center2, new_level); 28 | sCreateVertices(ioVertices, center3, center2, inDir3, new_level); 29 | } 30 | } 31 | 32 | const std::vector Vec3::sUnitSphere = []() { 33 | 34 | const int level = 3; 35 | 36 | std::unordered_set verts; 37 | 38 | // Add unit axis 39 | verts.insert(Vec3::sAxisX()); 40 | verts.insert(-Vec3::sAxisX()); 41 | verts.insert(Vec3::sAxisY()); 42 | verts.insert(-Vec3::sAxisY()); 43 | verts.insert(Vec3::sAxisZ()); 44 | verts.insert(-Vec3::sAxisZ()); 45 | 46 | // Subdivide 47 | sCreateVertices(verts, Vec3::sAxisX(), Vec3::sAxisY(), Vec3::sAxisZ(), level); 48 | sCreateVertices(verts, -Vec3::sAxisX(), Vec3::sAxisY(), Vec3::sAxisZ(), level); 49 | sCreateVertices(verts, Vec3::sAxisX(), -Vec3::sAxisY(), Vec3::sAxisZ(), level); 50 | sCreateVertices(verts, -Vec3::sAxisX(), -Vec3::sAxisY(), Vec3::sAxisZ(), level); 51 | sCreateVertices(verts, Vec3::sAxisX(), Vec3::sAxisY(), -Vec3::sAxisZ(), level); 52 | sCreateVertices(verts, -Vec3::sAxisX(), Vec3::sAxisY(), -Vec3::sAxisZ(), level); 53 | sCreateVertices(verts, Vec3::sAxisX(), -Vec3::sAxisY(), -Vec3::sAxisZ(), level); 54 | sCreateVertices(verts, -Vec3::sAxisX(), -Vec3::sAxisY(), -Vec3::sAxisZ(), level); 55 | 56 | return std::vector(verts.begin(), verts.end()); 57 | }(); 58 | 59 | JPH_NAMESPACE_END 60 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Geometry/Indexify.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | JPH_NAMESPACE_BEGIN 11 | 12 | void Indexify(const TriangleList &inTriangles, VertexList &outVertices, IndexedTriangleList &outTriangles, float inVertexWeldDistance) 13 | { 14 | float weld_dist_sq = Square(inVertexWeldDistance); 15 | 16 | // Ensure that output vertices are empty before we begin 17 | outVertices.clear(); 18 | 19 | // Find unique vertices 20 | UnorderedMap vertex_map; 21 | for (const Triangle &t : inTriangles) 22 | for (const Float3 &v : t.mV) 23 | { 24 | // Try to insert element 25 | auto insert = vertex_map.insert(pair(v, 0)); 26 | if (insert.second) 27 | { 28 | // Newly inserted, see if we can share 29 | bool found = false; 30 | for (size_t i = 0; i < outVertices.size(); ++i) 31 | { 32 | const Float3 &other = outVertices[i]; 33 | if (Square(other.x - v.x) + Square(other.y - v.y) + Square(other.z - v.z) <= weld_dist_sq) 34 | { 35 | insert.first->second = (uint32)i; 36 | found = true; 37 | break; 38 | } 39 | } 40 | 41 | if (!found) 42 | { 43 | // Can't share, add vertex 44 | insert.first->second = (uint32)outVertices.size(); 45 | outVertices.push_back(v); 46 | } 47 | } 48 | } 49 | 50 | // Create indexed triangles 51 | outTriangles.clear(); 52 | outTriangles.reserve(inTriangles.size()); 53 | for (const Triangle &t : inTriangles) 54 | { 55 | IndexedTriangle it; 56 | it.mMaterialIndex = t.mMaterialIndex; 57 | for (int j = 0; j < 3; ++j) 58 | it.mIdx[j] = vertex_map[t.mV[j]]; 59 | if (!it.IsDegenerate()) 60 | outTriangles.push_back(it); 61 | } 62 | } 63 | 64 | void Deindexify(const VertexList &inVertices, const IndexedTriangleList &inTriangles, TriangleList &outTriangles) 65 | { 66 | outTriangles.resize(inTriangles.size()); 67 | for (size_t t = 0; t < inTriangles.size(); ++t) 68 | for (int v = 0; v < 3; ++v) 69 | outTriangles[t].mV[v] = inVertices[inTriangles[t].mIdx[v]]; 70 | } 71 | 72 | JPH_NAMESPACE_END 73 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Constraints/PathConstraintPathHermite.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | /// A path that follows a Hermite spline 12 | class PathConstraintPathHermite final : public PathConstraintPath 13 | { 14 | public: 15 | JPH_DECLARE_SERIALIZABLE_VIRTUAL(PathConstraintPathHermite) 16 | 17 | // See PathConstraintPath::GetPathMaxFraction 18 | virtual float GetPathMaxFraction() const override { return float(IsLooping()? mPoints.size() : mPoints.size() - 1); } 19 | 20 | // See PathConstraintPath::GetClosestPoint 21 | virtual float GetClosestPoint(Vec3Arg inPosition) const override; 22 | 23 | // See PathConstraintPath::GetPointOnPath 24 | virtual void GetPointOnPath(float inFraction, Vec3 &outPathPosition, Vec3 &outPathTangent, Vec3 &outPathNormal, Vec3 &outPathBinormal) const override; 25 | 26 | /// Adds a point to the path 27 | void AddPoint(Vec3Arg inPosition, Vec3Arg inTangent, Vec3Arg inNormal) { mPoints.push_back({ inPosition, inTangent, inNormal}); } 28 | 29 | // See: PathConstraintPath::SaveBinaryState 30 | virtual void SaveBinaryState(StreamOut &inStream) const override; 31 | 32 | struct Point 33 | { 34 | JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(Point) 35 | 36 | Vec3 mPosition; ///< Position on the path 37 | Vec3 mTangent; ///< Tangent of the path, does not need to be normalized (in the direction of the path) 38 | Vec3 mNormal; ///< Normal of the path (together with the tangent along the curve this forms a basis for the constraint) 39 | }; 40 | 41 | protected: 42 | // See: PathConstraintPath::RestoreBinaryState 43 | virtual void RestoreBinaryState(StreamIn &inStream) override; 44 | 45 | private: 46 | /// Helper function that returns the index of the path segment and the fraction t on the path segment based on the full path fraction 47 | inline void GetIndexAndT(float inFraction, int &outIndex, float &outT) const; 48 | 49 | using Points = Array; 50 | 51 | Points mPoints; ///< Points on the Hermite spline 52 | }; 53 | 54 | JPH_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /src/asm/ontop_ppc64_sysv_xcoff_gas.S: -------------------------------------------------------------------------------- 1 | .align 2 2 | .globl .ontop_fcontext 3 | .ontop_fcontext: 4 | # reserve space on stack 5 | subi 1, 1, 184 6 | 7 | std 13, 0(1) # save R13 8 | std 14, 8(1) # save R14 9 | std 15, 16(1) # save R15 10 | std 16, 24(1) # save R16 11 | std 17, 32(1) # save R17 12 | std 18, 40(1) # save R18 13 | std 19, 48(1) # save R19 14 | std 20, 56(1) # save R20 15 | std 21, 64(1) # save R21 16 | std 22, 72(1) # save R22 17 | std 23, 80(1) # save R23 18 | std 24, 88(1) # save R24 19 | std 25, 96(1) # save R25 20 | std 26, 104(1) # save R26 21 | std 27, 112(1) # save R27 22 | std 29, 120(1) # save R28 23 | std 29, 128(1) # save R29 24 | std 30, 136(1) # save R30 25 | std 31, 144(1) # save R31 26 | std 3, 152(1) # save hidden 27 | 28 | # save CR 29 | mfcr 0 30 | std 0, 160(1) 31 | # save LR 32 | mflr 0 33 | std 0, 168(1) 34 | # save LR as PC 35 | std 0, 176(1) 36 | 37 | # store RSP (pointing to context-data) in R7 38 | mr 7, 1 39 | 40 | # restore RSP (pointing to context-data) from R4 41 | mr 1, 4 42 | 43 | ld 13, 0(1) # restore R13 44 | ld 14, 8(1) # restore R14 45 | ld 15, 16(1) # restore R15 46 | ld 16, 24(1) # restore R16 47 | ld 17, 32(1) # restore R17 48 | ld 18, 40(1) # restore R18 49 | ld 19, 48(1) # restore R19 50 | ld 20, 56(1) # restore R20 51 | ld 21, 64(1) # restore R21 52 | ld 22, 72(1) # restore R22 53 | ld 23, 80(1) # restore R23 54 | ld 24, 88(1) # restore R24 55 | ld 25, 96(1) # restore R25 56 | ld 26, 104(1) # restore R26 57 | ld 27, 112(1) # restore R27 58 | ld 28, 120(1) # restore R28 59 | ld 29, 128(1) # restore R29 60 | ld 30, 136(1) # restore R30 61 | ld 31, 144(1) # restore R31 62 | ld 4, 152(1) # restore hidden 63 | 64 | # restore CR 65 | ld 0, 160(1) 66 | mtcr 0 67 | # restore LR 68 | ld 0, 168(1) 69 | mtlr 0 70 | # ignore PC 71 | 72 | # adjust stack 73 | addi 1, 1, 184 74 | 75 | # return transfer_t 76 | std 7, 0(4) 77 | std 5, 8(4) 78 | 79 | # restore CTR 80 | mtctr 6 81 | 82 | # jump to context 83 | bctr 84 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Core/JobSystem.inl: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | JPH_NAMESPACE_BEGIN 6 | 7 | void JobSystem::Job::AddDependency(int inCount) 8 | { 9 | JPH_IF_ENABLE_ASSERTS(uint32 old_value =) mNumDependencies.fetch_add(inCount, memory_order_relaxed); 10 | JPH_ASSERT(old_value > 0 && old_value != cExecutingState && old_value != cDoneState, "Job is queued, running or done, it is not allowed to add a dependency to a running job"); 11 | } 12 | 13 | bool JobSystem::Job::RemoveDependency(int inCount) 14 | { 15 | uint32 old_value = mNumDependencies.fetch_sub(inCount, memory_order_release); 16 | JPH_ASSERT(old_value != cExecutingState && old_value != cDoneState, "Job is running or done, it is not allowed to add a dependency to a running job"); 17 | uint32 new_value = old_value - inCount; 18 | JPH_ASSERT(old_value > new_value, "Test wrap around, this is a logic error"); 19 | return new_value == 0; 20 | } 21 | 22 | void JobSystem::Job::RemoveDependencyAndQueue(int inCount) 23 | { 24 | if (RemoveDependency(inCount)) 25 | mJobSystem->QueueJob(this); 26 | } 27 | 28 | void JobSystem::JobHandle::sRemoveDependencies(JobHandle *inHandles, uint inNumHandles, int inCount) 29 | { 30 | JPH_PROFILE_FUNCTION(); 31 | 32 | JPH_ASSERT(inNumHandles > 0); 33 | 34 | // Get the job system, all jobs should be part of the same job system 35 | JobSystem *job_system = inHandles->GetPtr()->GetJobSystem(); 36 | 37 | // Allocate a buffer to store the jobs that need to be queued 38 | Job **jobs_to_queue = (Job **)JPH_STACK_ALLOC(inNumHandles * sizeof(Job *)); 39 | Job **next_job = jobs_to_queue; 40 | 41 | // Remove the dependencies on all jobs 42 | for (const JobHandle *handle = inHandles, *handle_end = inHandles + inNumHandles; handle < handle_end; ++handle) 43 | { 44 | Job *job = handle->GetPtr(); 45 | JPH_ASSERT(job->GetJobSystem() == job_system); // All jobs should belong to the same job system 46 | if (job->RemoveDependency(inCount)) 47 | *(next_job++) = job; 48 | } 49 | 50 | // If any jobs need to be scheduled, schedule them as a batch 51 | uint num_jobs_to_queue = uint(next_job - jobs_to_queue); 52 | if (num_jobs_to_queue != 0) 53 | job_system->QueueJobs(jobs_to_queue, num_jobs_to_queue); 54 | } 55 | 56 | JPH_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /thirdparty/Jolt/TriangleSplitter/TriangleSplitter.cpp: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #include 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | TriangleSplitter::TriangleSplitter(const VertexList &inVertices, const IndexedTriangleList &inTriangles) : 12 | mVertices(inVertices), 13 | mTriangles(inTriangles) 14 | { 15 | mSortedTriangleIdx.resize(inTriangles.size()); 16 | mCentroids.resize(inTriangles.size()); 17 | 18 | for (uint t = 0; t < inTriangles.size(); ++t) 19 | { 20 | // Initially triangles start unsorted 21 | mSortedTriangleIdx[t] = t; 22 | 23 | // Calculate centroid 24 | inTriangles[t].GetCentroid(inVertices).StoreFloat3(&mCentroids[t]); 25 | } 26 | } 27 | 28 | bool TriangleSplitter::SplitInternal(const Range &inTriangles, uint inDimension, float inSplit, Range &outLeft, Range &outRight) 29 | { 30 | // Divide triangles 31 | uint start = inTriangles.mBegin, end = inTriangles.mEnd; 32 | while (start < end) 33 | { 34 | // Search for first element that is on the right hand side of the split plane 35 | while (start < end && mCentroids[mSortedTriangleIdx[start]][inDimension] < inSplit) 36 | ++start; 37 | 38 | // Search for the first element that is on the left hand side of the split plane 39 | while (start < end && mCentroids[mSortedTriangleIdx[end - 1]][inDimension] >= inSplit) 40 | --end; 41 | 42 | if (start < end) 43 | { 44 | // Swap the two elements 45 | swap(mSortedTriangleIdx[start], mSortedTriangleIdx[end - 1]); 46 | ++start; 47 | --end; 48 | } 49 | } 50 | JPH_ASSERT(start == end); 51 | 52 | #ifdef JPH_ENABLE_ASSERTS 53 | // Validate division algorithm 54 | JPH_ASSERT(inTriangles.mBegin <= start); 55 | JPH_ASSERT(start <= inTriangles.mEnd); 56 | for (uint i = inTriangles.mBegin; i < start; ++i) 57 | JPH_ASSERT(mCentroids[mSortedTriangleIdx[i]][inDimension] < inSplit); 58 | for (uint i = start; i < inTriangles.mEnd; ++i) 59 | JPH_ASSERT(mCentroids[mSortedTriangleIdx[i]][inDimension] >= inSplit); 60 | #endif 61 | 62 | outLeft = Range(inTriangles.mBegin, start); 63 | outRight = Range(start, inTriangles.mEnd); 64 | return outLeft.Count() > 0 && outRight.Count() > 0; 65 | } 66 | 67 | JPH_NAMESPACE_END 68 | -------------------------------------------------------------------------------- /thirdparty/Jolt/Physics/Body/MassProperties.h: -------------------------------------------------------------------------------- 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe 3 | // SPDX-License-Identifier: MIT 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | JPH_NAMESPACE_BEGIN 10 | 11 | class StreamIn; 12 | class StreamOut; 13 | 14 | /// Describes the mass and inertia properties of a body. Used during body construction only. 15 | class MassProperties 16 | { 17 | public: 18 | JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(MassProperties) 19 | 20 | /// Using eigendecomposition, decompose the inertia tensor into a diagonal matrix D and a right-handed rotation matrix R so that the inertia tensor is \f$R \: D \: R^{-1}\f$. 21 | /// @see https://en.wikipedia.org/wiki/Moment_of_inertia section 'Principal axes' 22 | /// @param outRotation The rotation matrix R 23 | /// @param outDiagonal The diagonal of the diagonal matrix D 24 | /// @return True if successful, false if failed 25 | bool DecomposePrincipalMomentsOfInertia(Mat44 &outRotation, Vec3 &outDiagonal) const; 26 | 27 | /// Set the mass and inertia of a box with edge size inBoxSize and density inDensity 28 | void SetMassAndInertiaOfSolidBox(Vec3Arg inBoxSize, float inDensity); 29 | 30 | /// Set the mass and scale the inertia tensor to match the mass 31 | void ScaleToMass(float inMass); 32 | 33 | /// Calculates the size of the solid box that has an inertia tensor diagonal inInertiaDiagonal 34 | static Vec3 sGetEquivalentSolidBoxSize(float inMass, Vec3Arg inInertiaDiagonal); 35 | 36 | /// Rotate the inertia by 3x3 matrix inRotation 37 | void Rotate(Mat44Arg inRotation); 38 | 39 | /// Translate the inertia by a vector inTranslation 40 | void Translate(Vec3Arg inTranslation); 41 | 42 | /// Scale the mass and inertia by inScale, note that elements can be < 0 to flip the shape 43 | void Scale(Vec3Arg inScale); 44 | 45 | /// Saves the state of this object in binary form to inStream. 46 | void SaveBinaryState(StreamOut &inStream) const; 47 | 48 | /// Restore the state of this object from inStream. 49 | void RestoreBinaryState(StreamIn &inStream); 50 | 51 | /// Mass of the shape (kg) 52 | float mMass = 0.0f; 53 | 54 | /// Inertia tensor of the shape (kg m^2) 55 | Mat44 mInertia = Mat44::sZero(); 56 | }; 57 | 58 | JPH_NAMESPACE_END 59 | --------------------------------------------------------------------------------