mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 02:59:37 +00:00 
			
		
		
		
	make chunkid id field private
This commit is contained in:
		@ -1,35 +1,35 @@
 | 
			
		||||
import simd
 | 
			
		||||
 | 
			
		||||
public struct ChunkID: Hashable {
 | 
			
		||||
  public let id: SIMD3<Int>
 | 
			
		||||
  private let _id: SIMD3<Int>
 | 
			
		||||
 | 
			
		||||
  init(id: SIMD3<Int>) {
 | 
			
		||||
    self.id = id
 | 
			
		||||
    self._id = id
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension ChunkID {
 | 
			
		||||
  @inline(__always) init(_ x: Int, _ y: Int, _ z: Int) { self.id = SIMD3(x, y, z) }
 | 
			
		||||
  @inline(__always) init(_ x: Int, _ y: Int, _ z: Int) { self._id = SIMD3(x, y, z) }
 | 
			
		||||
 | 
			
		||||
  @inline(__always) init<F: BinaryFloatingPoint>(fromPosition position: SIMD3<F>) {
 | 
			
		||||
    self.init(fromPosition: SIMD3(Int(floor(position.x)), Int(floor(position.y)), Int(floor(position.z))))
 | 
			
		||||
  }
 | 
			
		||||
  @inline(__always) init(fromPosition position: SIMD3<Int>) { self.id = position &>> Chunk.shift }
 | 
			
		||||
  @inline(__always) init(fromPosition position: SIMD3<Int>) { self._id = position &>> Chunk.shift }
 | 
			
		||||
 | 
			
		||||
  @inline(__always) func getPosition() -> SIMD3<Int> { self.id &<< Chunk.shift }
 | 
			
		||||
  @inline(__always) func getPosition(offset: SIMD3<Int>) -> SIMD3<Int> { self.id &<< Chunk.shift &+ offset }
 | 
			
		||||
  @inline(__always) func getFloatPosition() -> SIMD3<Float> { SIMD3<Float>(self.id) * Float(Chunk.size) }
 | 
			
		||||
  @inline(__always) func getPosition() -> SIMD3<Int> { self._id &<< Chunk.shift }
 | 
			
		||||
  @inline(__always) func getPosition(offset: SIMD3<Int>) -> SIMD3<Int> { self._id &<< Chunk.shift &+ offset }
 | 
			
		||||
  @inline(__always) func getFloatPosition() -> SIMD3<Float> { SIMD3<Float>(self._id) * Float(Chunk.size) }
 | 
			
		||||
  @inline(__always) func getFloatPosition(offset: SIMD3<Float>) -> SIMD3<Float> {
 | 
			
		||||
    SIMD3<Float>(self.id) * Float(Chunk.size) + offset
 | 
			
		||||
    SIMD3<Float>(self._id) * Float(Chunk.size) + offset
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @inline(__always) static func &+ (lhs: Self, rhs: Self) -> Self { .init(id: lhs.id &+ rhs.id) }
 | 
			
		||||
  @inline(__always) static func &- (lhs: Self, rhs: Self) -> Self { .init(id: lhs.id &- rhs.id) }
 | 
			
		||||
  @inline(__always) static func &+ (lhs: Self, rhs: Self) -> Self { .init(id: lhs._id &+ rhs._id) }
 | 
			
		||||
  @inline(__always) static func &- (lhs: Self, rhs: Self) -> Self { .init(id: lhs._id &- rhs._id) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension ChunkID {
 | 
			
		||||
  @inlinable func distance(_ other: Self) -> Float {
 | 
			
		||||
    simd_distance(SIMD3<Float>(self.id), SIMD3<Float>(other.id))
 | 
			
		||||
    simd_distance(SIMD3<Float>(SIMD3(self)), SIMD3<Float>(SIMD3(other)))
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -39,6 +39,10 @@ public extension ChunkID {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fileprivate extension ChunkID {
 | 
			
		||||
  @inline(__always) var id: SIMD3<Int> { self._id }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension SIMD3 where Scalar == Int {
 | 
			
		||||
  init(_ chunkID: ChunkID) { self = chunkID.id }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user