Skip to content

Commit

Permalink
v0.25 Arbitrary core and core cell size in shader
Browse files Browse the repository at this point in the history
Shader will now draw a core with arbitrary grid size and x and y dimensions
  • Loading branch information
fatherdougalmaguire committed Feb 2, 2025
1 parent d870926 commit e85fc9e
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 91 deletions.
4 changes: 2 additions & 2 deletions LifeOnMars.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 0.241;
MARKETING_VERSION = 0.25;
PRODUCT_BUNDLE_IDENTIFIER = com.fatherdougalmaguire.LifeOnMars;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -333,7 +333,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 0.241;
MARKETING_VERSION = 0.25;
PRODUCT_BUNDLE_IDENTIFIER = com.fatherdougalmaguire.LifeOnMars;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "322"
endingLineNumber = "322"
startingLineNumber = "341"
endingLineNumber = "341"
landmarkName = "LoadCore()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -30,8 +30,8 @@
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "945"
endingLineNumber = "945"
startingLineNumber = "964"
endingLineNumber = "964"
landmarkName = "CoreStepExecute()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -46,8 +46,8 @@
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "942"
endingLineNumber = "942"
startingLineNumber = "961"
endingLineNumber = "961"
landmarkName = "CoreStepExecute()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -62,8 +62,8 @@
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "402"
endingLineNumber = "402"
startingLineNumber = "421"
endingLineNumber = "421"
landmarkName = "LoadCore()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -78,8 +78,8 @@
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "403"
endingLineNumber = "403"
startingLineNumber = "422"
endingLineNumber = "422"
landmarkName = "LoadCore()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -94,8 +94,8 @@
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "363"
endingLineNumber = "363"
startingLineNumber = "382"
endingLineNumber = "382"
landmarkName = "LoadCore()"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -126,8 +126,8 @@
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "212"
endingLineNumber = "212"
startingLineNumber = "231"
endingLineNumber = "231"
landmarkName = "FormatCoreOutput(_:)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -142,105 +142,89 @@
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "533"
endingLineNumber = "533"
startingLineNumber = "552"
endingLineNumber = "552"
landmarkName = "CoreStepExecute()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "0CD35390-9300-42C7-8651-82B714591A9B"
uuid = "C56C2280-CDD3-4608-B7F9-A79559479BBD"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "137"
endingLineNumber = "137"
landmarkName = "init()"
startingLineNumber = "370"
endingLineNumber = "370"
landmarkName = "LoadCore()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "944CBB1B-ADE2-44F0-8E28-76A5CEFFD01E"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LifeOnMars/buffer.metal"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "18"
endingLineNumber = "18"
landmarkName = "DrawCore(float2 position, half4 color, device const float *CoreBuffer1, int CoreSize1)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "C56C2280-CDD3-4608-B7F9-A79559479BBD"
uuid = "2943799C-7CA3-49D2-BF11-3EAA96AB7888"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "351"
endingLineNumber = "351"
startingLineNumber = "399"
endingLineNumber = "399"
landmarkName = "LoadCore()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "2943799C-7CA3-49D2-BF11-3EAA96AB7888"
uuid = "C5BFB520-02A5-4697-9DCC-DB8EC70D78DA"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "380"
endingLineNumber = "380"
startingLineNumber = "362"
endingLineNumber = "362"
landmarkName = "LoadCore()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "C5BFB520-02A5-4697-9DCC-DB8EC70D78DA"
uuid = "2D535B60-7EC2-443E-B6D6-E7C0B690F5C9"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "343"
endingLineNumber = "343"
landmarkName = "LoadCore()"
startingLineNumber = "986"
endingLineNumber = "986"
landmarkName = "CoreExecute()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "2D535B60-7EC2-443E-B6D6-E7C0B690F5C9"
uuid = "551B925A-C7CF-469A-ABB1-34A7DF42693D"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LifeOnMars/EmulatorCore.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "967"
endingLineNumber = "967"
landmarkName = "CoreExecute()"
startingLineNumber = "139"
endingLineNumber = "139"
landmarkName = "init()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down
72 changes: 50 additions & 22 deletions LifeOnMars/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
import SwiftUI

struct CoreDisplayView: View {

@EnvironmentObject var ThisEmulatorCore : EmulatorCore

var body: some View {

VStack
{ TimelineView(.animation)
{ context in
Rectangle()
.fill(.red)
.frame(width: 100.0, height: 80.0)
.colorEffect(ShaderLibrary.DrawCore(.floatArray(ThisEmulatorCore.CoreBuffer)))
.scaleEffect(x: 7.0, y:7.0)
.frame(width: CGFloat(ThisEmulatorCore.CoreSizeInCols*(ThisEmulatorCore.CoreCellSize+1)), height: CGFloat(ThisEmulatorCore.CoreSizeInRows*(ThisEmulatorCore.CoreCellSize+1)))
.colorEffect(ShaderLibrary.DrawCore1(.floatArray(ThisEmulatorCore.CoreBuffer),.float(Float(ThisEmulatorCore.CoreSizeInCols)),.float(Float(ThisEmulatorCore.CoreSizeInRows)),.float(Float(ThisEmulatorCore.CoreCellSize))))
// .frame(width: 100.0, height: 80.0)
// .colorEffect(ShaderLibrary.DrawCore(.floatArray(ThisEmulatorCore.CoreBuffer)))
// .scaleEffect(x: 7.0, y:7.0)
.onChange(of: context.date)
{
ThisEmulatorCore.CoreExecute()
Expand All @@ -31,6 +32,31 @@ struct CoreDisplayView: View {
} //End body
} // End CoreDisplayView

struct oldthing: View {

@EnvironmentObject var ThisEmulatorCore : EmulatorCore

var body: some View {

HStack {
Grid(horizontalSpacing: 1.0, verticalSpacing: 1.0) {
ForEach(0..<10) { MyIndexRow in
GridRow {
ForEach(0..<10) { MyIndexCol in
Rectangle().fill(ThisEmulatorCore.Core[(MyIndexRow*10)+MyIndexCol].InstructionColour)
} // End ForEach
} // End GridRow
.frame(width: 10.0, height: 10.0)
} // End ForEach
} // End Grid
Rectangle()
.frame(width: CGFloat(ThisEmulatorCore.CoreSizeInCols*(ThisEmulatorCore.CoreCellSize+1)), height: CGFloat(ThisEmulatorCore.CoreSizeInRows*(ThisEmulatorCore.CoreCellSize+1)))
.colorEffect(ShaderLibrary.DrawCore1(.floatArray(ThisEmulatorCore.CoreBuffer),.float(Float(ThisEmulatorCore.CoreSizeInCols)),.float(Float(ThisEmulatorCore.CoreSizeInRows)),.float(Float(ThisEmulatorCore.CoreCellSize))))
} // End VStack
//.background(.blue)
} //End body
} // End CoreDisplayView

#Preview {
CoreDisplayView()
} // End Preview
Expand Down Expand Up @@ -129,21 +155,23 @@ struct ContentView: View {
@StateObject var ThisEmulatorCore = EmulatorCore()

var body: some View {
// ZStack
// {
// Color.white.ignoresSafeArea()
CoreDisplayView().environmentObject(ThisEmulatorCore).frame(width:1000,height:560,alignment: .top)
// Divider()
// HStack
// {
CoreMemoryView().environmentObject(ThisEmulatorCore).frame(width:1000,height:120)
// Divider()
WarriorDisplayView().environmentObject(ThisEmulatorCore).frame(width:1000,height:80)
// Divider()
// } // End HStack
// Spacer()
WarriorControlView().environmentObject(ThisEmulatorCore).frame(width:1000,height:50,alignment: .bottom)
// } // End ZStack

//oldthing().environmentObject(ThisEmulatorCore).frame(width:1000,height:560,alignment: .top)
// ZStack
// {
// Color.white.ignoresSafeArea()
CoreDisplayView().environmentObject(ThisEmulatorCore).frame(width:1000,height:560,alignment: .top)
// Divider()
// HStack
// {
CoreMemoryView().environmentObject(ThisEmulatorCore).frame(width:1000,height:120)
// Divider()
WarriorDisplayView().environmentObject(ThisEmulatorCore).frame(width:1000,height:80)
// Divider()
// } // End HStack
// Spacer()
WarriorControlView().environmentObject(ThisEmulatorCore).frame(width:1000,height:50,alignment: .bottom)
// } // End ZStack
} // End body
} // End ContentView

Expand Down
31 changes: 25 additions & 6 deletions LifeOnMars/EmulatorCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class EmulatorCore : ObservableObject {
var CoreSize: Int = 8000
var CoreSizeInRows: Int
var CoreSizeInCols: Int
var CoreCellSize: Double
var CoreCellSize: Int
var CoreDrawSize : Int
var CoreUpdateFreq : Double = 0.1

Expand All @@ -117,22 +117,41 @@ class EmulatorCore : ObservableObject {
else if self.CoreSize <= 1000
{
self.CoreSizeInRows = 20
self.CoreSizeInCols = 50
self.CoreCellSize = 10
self.CoreSizeInCols = 50
// self.CoreSizeInRows = 20
// self.CoreSizeInCols = 20
self.CoreCellSize = 15
CoreDrawSize = self.CoreSizeInRows*self.CoreSizeInCols
}
else
{
self.CoreSizeInRows = 70
self.CoreSizeInCols = 120
self.CoreCellSize = 10
self.CoreSizeInRows = 64
self.CoreSizeInCols = 125
self.CoreCellSize = 7
CoreDrawSize = self.CoreSizeInRows*self.CoreSizeInCols
}
self.Core = Array<RedCodeInstruction>(repeating: RedCodeInstruction(),count:CoreSize)
self.CoreBuffer = Array<Float>(repeating: 0.0,count:CoreSize)
for MyIndex in 0..<CoreSize {
self.Core[MyIndex].InstructionColour = .black
self.CoreBuffer[MyIndex] = 0
}
// self.Core[1].InstructionColour = .green
// self.CoreBuffer[1] = 2
// self.Core[2].InstructionColour = .green
// self.CoreBuffer[2] = 2
// self.Core[3].InstructionColour = .green
// self.CoreBuffer[3] = 2
// self.Core[4].InstructionColour = .green
// self.CoreBuffer[4] = 2
// self.Core[30].InstructionColour = .red
// self.CoreBuffer[30] = 1
// self.Core[31].InstructionColour = .red
// self.CoreBuffer[31] = 1
// self.Core[32].InstructionColour = .red
// self.CoreBuffer[32] = 1
// self.Core[33].InstructionColour = .red
// self.CoreBuffer[33] = 1

self.CoreUpdateFreq = 0.1
}
Expand Down
Loading

0 comments on commit e85fc9e

Please sign in to comment.