From cceb00dfe023d09f59f478b0700fb89e69f60100 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 6 Aug 2017 11:39:18 -0700 Subject: [PATCH] [MetaballsKit] Add Memory file --- Metaballs.xcodeproj/project.pbxproj | 4 ++++ MetaballsKit/Memory.swift | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 MetaballsKit/Memory.swift diff --git a/Metaballs.xcodeproj/project.pbxproj b/Metaballs.xcodeproj/project.pbxproj index 74e0046..e8f8f45 100644 --- a/Metaballs.xcodeproj/project.pbxproj +++ b/Metaballs.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ C0BBE3AC1F2E941200E68524 /* Renderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0BBE3AB1F2E941200E68524 /* Renderer.swift */; }; C0BBE3AD1F30CD7E00E68524 /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0BBE3A71F2E893A00E68524 /* MetalKit.framework */; }; C0CE7C001F362C3F001516B6 /* Geometry.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0CE7BFF1F362C3F001516B6 /* Geometry.swift */; }; + C0DF1D791F3789DC0038B0A0 /* Memory.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DF1D781F3789DC0038B0A0 /* Memory.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -62,6 +63,7 @@ C0BBE3A91F2E91D900E68524 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; C0BBE3AB1F2E941200E68524 /* Renderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Renderer.swift; sourceTree = ""; }; C0CE7BFF1F362C3F001516B6 /* Geometry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Geometry.swift; sourceTree = ""; }; + C0DF1D781F3789DC0038B0A0 /* Memory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Memory.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -153,6 +155,7 @@ C0BBE38F1F2E81B600E68524 /* Info.plist */, C0BBE3A31F2E81C700E68524 /* Metaballs.swift */, C0CE7BFF1F362C3F001516B6 /* Geometry.swift */, + C0DF1D781F3789DC0038B0A0 /* Memory.swift */, ); path = MetaballsKit; sourceTree = ""; @@ -371,6 +374,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C0DF1D791F3789DC0038B0A0 /* Memory.swift in Sources */, C0BBE3A41F2E81C700E68524 /* Metaballs.swift in Sources */, C0CE7C001F362C3F001516B6 /* Geometry.swift in Sources */, ); diff --git a/MetaballsKit/Memory.swift b/MetaballsKit/Memory.swift new file mode 100644 index 0000000..20add0b --- /dev/null +++ b/MetaballsKit/Memory.swift @@ -0,0 +1,17 @@ +// +// Memory.swift +// Metaballs +// +// Created by Eryn Wells on 8/6/17. +// Copyright © 2017 Eryn Wells. All rights reserved. +// + +import Foundation + +extension UnsafeMutableRawPointer { + func writeAndAdvance(value: inout T) -> UnsafeMutableRawPointer { + let stride = MemoryLayout.stride(ofValue: value) + copyBytes(from: &value, count: stride) + return advanced(by: stride) + } +}