diff --git a/Sources/Voxelotl/CMakeLists.txt b/Sources/Voxelotl/CMakeLists.txt index 3b762de..435ac7c 100644 --- a/Sources/Voxelotl/CMakeLists.txt +++ b/Sources/Voxelotl/CMakeLists.txt @@ -1,33 +1,40 @@ add_executable(Voxelotl MACOSX_BUNDLE + # Resources Assets.xcassets - test.png + # Shaders shadertypes.h shader.metal - FloatExtensions.swift - Matrix4x4.swift - Rectangle.swift - AABB.swift - Color.swift + # Maths library + Math/FloatExtensions.swift + Math/VectorExtensions.swift + Math/Matrix4x4.swift + Math/Rectangle.swift + Math/AABB.swift + # Random number generator subsystem Random/RandomProvider.swift Random/RandomRange.swift Random/Arc4Random.swift Random/DarwinRandom.swift + # Resource classes NSImageLoader.swift + + # Core utility classes + Color.swift + Camera.swift Renderer.swift GameController.swift FPSCalculator.swift - - Chunk.swift - Camera.swift - Player.swift GameDelegate.swift Application.swift + # Game logic classes + Chunk.swift + Player.swift Game.swift main.swift) @@ -64,6 +71,8 @@ set_source_files_properties(Assets.xcassets PROPERTIES MACOSX_PACKAGE_LOCATION R set_source_files_properties(module.modulemap PROPERTIES MACOSX_PACKAGE_LOCATION Modules) set_source_files_properties(test.png PROPERTIES MACOSX_PACKAGE_LOCATION Resources) +#TODO: should use TREE mode as documented in https://cmake.org/cmake/help/latest/command/source_group.html source_group("Resources" FILES Assets.xcassets test.png) source_group("Source Files" REGULAR_EXPRESSION "\\.(swift|metal)$") source_group("Source Files\\Random" REGULAR_EXPRESSION "Random/") +source_group("Source Files\\Math" REGULAR_EXPRESSION "Math/") diff --git a/Sources/Voxelotl/AABB.swift b/Sources/Voxelotl/Math/AABB.swift similarity index 100% rename from Sources/Voxelotl/AABB.swift rename to Sources/Voxelotl/Math/AABB.swift diff --git a/Sources/Voxelotl/Math/FloatExtensions.swift b/Sources/Voxelotl/Math/FloatExtensions.swift new file mode 100644 index 0000000..25d9e82 --- /dev/null +++ b/Sources/Voxelotl/Math/FloatExtensions.swift @@ -0,0 +1,10 @@ +public extension FloatingPoint { + @inline(__always) var degrees: Self { self * (180 / Self.pi) } + @inline(__always) var radians: Self { self * (Self.pi / 180) } + + @inline(__always) func lerp(_ a: Self, _ b: Self) -> Self { b * self + a * (1 - self) } + @inline(__always) func mlerp(_ a: Self, _ b: Self) -> Self { a + (b - a) * self } + + @inline(__always) func clamp(_ a: Self, _ b: Self) -> Self { min(max(self, a), b) } + @inline(__always) var saturated: Self { self.clamp(0, 1) } +} diff --git a/Sources/Voxelotl/Matrix4x4.swift b/Sources/Voxelotl/Math/Matrix4x4.swift similarity index 100% rename from Sources/Voxelotl/Matrix4x4.swift rename to Sources/Voxelotl/Math/Matrix4x4.swift diff --git a/Sources/Voxelotl/Rectangle.swift b/Sources/Voxelotl/Math/Rectangle.swift similarity index 100% rename from Sources/Voxelotl/Rectangle.swift rename to Sources/Voxelotl/Math/Rectangle.swift diff --git a/Sources/Voxelotl/FloatExtensions.swift b/Sources/Voxelotl/Math/VectorExtensions.swift similarity index 52% rename from Sources/Voxelotl/FloatExtensions.swift rename to Sources/Voxelotl/Math/VectorExtensions.swift index b8f41b9..e361ba6 100644 --- a/Sources/Voxelotl/FloatExtensions.swift +++ b/Sources/Voxelotl/Math/VectorExtensions.swift @@ -1,14 +1,3 @@ -public extension FloatingPoint { - @inline(__always) var degrees: Self { self * (180 / Self.pi) } - @inline(__always) var radians: Self { self * (Self.pi / 180) } - - @inline(__always) func lerp(_ a: Self, _ b: Self) -> Self { b * self + a * (1 - self) } - @inline(__always) func mlerp(_ a: Self, _ b: Self) -> Self { a + (b - a) * self } - - @inline(__always) func clamp(_ a: Self, _ b: Self) -> Self { min(max(self, a), b) } - @inline(__always) var saturated: Self { self.clamp(0, 1) } -} - extension SIMD3 where Scalar: FloatingPoint { @inline(__always) static var X: Self { Self(1, 0, 0) } @inline(__always) static var Y: Self { Self(0, 1, 0) }