ios2 attempt 2 #5
No files matched your search
@@ -20,48 +20,3 @@ ChkgfxContext:
|
||||
fields:
|
||||
didLaunch: Bool
|
||||
didSetup: Bool
|
||||
|
||||
RenderContext:
|
||||
type: context
|
||||
fields:
|
||||
backingPixelSize: [Int32]
|
||||
didLaunch: Bool
|
||||
didPrepareGL: Bool
|
||||
didSetup: Bool
|
||||
pixelSize: [Int32]
|
||||
reshapePixelSize: [Int32]
|
||||
willDeinit: Bool
|
||||
|
||||
RenderComponent:
|
||||
type: component
|
||||
oneliners:
|
||||
- didPrepareGL: renderInit(RenderVM.shared!)
|
||||
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
|
||||
- didPrepareGL: renderStartTimer(RenderVM.shared!)
|
||||
- didPrepareGL: renderLoadCubeModel(RenderVM.shared!)
|
||||
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
||||
- willDeinit: renderDeinit(RenderVM.shared!)
|
||||
shoulds:
|
||||
didLaunch:
|
||||
1. Only once during the first setup:
|
||||
if:
|
||||
c.recentField == F.didSetup &&
|
||||
c.didLaunch == false
|
||||
then:
|
||||
c.didLaunch = true
|
||||
pixelSize:
|
||||
1. Upon launch:
|
||||
if:
|
||||
c.recentField == F.didLaunch
|
||||
then:
|
||||
c.pixelSize = [1, 1]
|
||||
2. Upon resize:
|
||||
if:
|
||||
c.recentField == F.reshapePixelSize
|
||||
then:
|
||||
c.pixelSize = c.reshapePixelSize
|
||||
3. Upon DPI change:
|
||||
if:
|
||||
c.recentField == F.backingPixelSize
|
||||
then:
|
||||
c.pixelSize = c.backingPixelSize
|
||||
@@ -119,13 +119,8 @@ func registerOneliners<T>(
|
||||
|
||||
// Context field names for static type check
|
||||
public struct F {
|
||||
public static let backingPixelSize = "backingPixelSize"
|
||||
public static let didLaunch = "didLaunch"
|
||||
public static let didPrepareGL = "didPrepareGL"
|
||||
public static let didSetup = "didSetup"
|
||||
public static let pixelSize = "pixelSize"
|
||||
public static let reshapePixelSize = "reshapePixelSize"
|
||||
public static let willDeinit = "willDeinit"
|
||||
|
||||
}
|
||||
public struct ChkgfxContext: DialectContext {
|
||||
@@ -159,72 +154,6 @@ public struct ChkgfxContext: DialectContext {
|
||||
}
|
||||
}
|
||||
|
||||
public struct RenderContext: DialectContext {
|
||||
public var backingPixelSize = [Int32]()
|
||||
public var didLaunch = Bool()
|
||||
public var didPrepareGL = Bool()
|
||||
public var didSetup = Bool()
|
||||
public var pixelSize = [Int32]()
|
||||
public var reshapePixelSize = [Int32]()
|
||||
public var willDeinit = Bool()
|
||||
|
||||
public var recentField = ""
|
||||
|
||||
public func field<T>(_ name: String) -> T {
|
||||
if (name == "backingPixelSize") {
|
||||
return backingPixelSize as! T
|
||||
}
|
||||
else if (name == "didLaunch") {
|
||||
return didLaunch as! T
|
||||
}
|
||||
else if (name == "didPrepareGL") {
|
||||
return didPrepareGL as! T
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
return didSetup as! T
|
||||
}
|
||||
else if (name == "pixelSize") {
|
||||
return pixelSize as! T
|
||||
}
|
||||
else if (name == "reshapePixelSize") {
|
||||
return reshapePixelSize as! T
|
||||
}
|
||||
else if (name == "willDeinit") {
|
||||
return willDeinit as! T
|
||||
}
|
||||
|
||||
return "unknown-field-name" as! T
|
||||
}
|
||||
|
||||
public mutating func setField(
|
||||
_ name: String,
|
||||
_ value: Any
|
||||
) {
|
||||
if (name == "backingPixelSize") {
|
||||
backingPixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "didLaunch") {
|
||||
didLaunch = value as! Bool
|
||||
}
|
||||
else if (name == "didPrepareGL") {
|
||||
didPrepareGL = value as! Bool
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
didSetup = value as! Bool
|
||||
}
|
||||
else if (name == "pixelSize") {
|
||||
pixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "reshapePixelSize") {
|
||||
reshapePixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "willDeinit") {
|
||||
willDeinit = value as! Bool
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public func chkgfxSet(
|
||||
_ key: String,
|
||||
_ value: Any
|
||||
@@ -232,13 +161,6 @@ public func chkgfxSet(
|
||||
ChkgfxComponent.singleton!.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
public func renderSet(
|
||||
_ key: String,
|
||||
_ value: Any
|
||||
) {
|
||||
RenderComponent.singleton!.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext {
|
||||
var c = c
|
||||
|
||||
@@ -257,59 +179,6 @@ func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext {
|
||||
return c
|
||||
}
|
||||
|
||||
func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext {
|
||||
var c = c
|
||||
|
||||
/* 1. Only once during the first setup */
|
||||
if
|
||||
c.recentField == F.didSetup &&
|
||||
c.didLaunch == false
|
||||
{
|
||||
c.didLaunch = true
|
||||
c.recentField = F.didLaunch
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
func renderShouldResetPixelSize(_ c: RenderContext) -> RenderContext {
|
||||
var c = c
|
||||
|
||||
/* 1. Upon launch */
|
||||
if
|
||||
c.recentField == F.didLaunch
|
||||
{
|
||||
c.pixelSize = [1, 1]
|
||||
c.recentField = F.pixelSize
|
||||
return c
|
||||
}
|
||||
|
||||
/* 2. Upon resize */
|
||||
if
|
||||
c.recentField == F.reshapePixelSize
|
||||
{
|
||||
c.pixelSize = c.reshapePixelSize
|
||||
c.recentField = F.pixelSize
|
||||
return c
|
||||
}
|
||||
|
||||
/* 3. Upon DPI change */
|
||||
if
|
||||
c.recentField == F.backingPixelSize
|
||||
{
|
||||
c.pixelSize = c.backingPixelSize
|
||||
c.recentField = F.pixelSize
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
func chkgfxRegisterShoulds(_ ctrl: DialectController) {
|
||||
[
|
||||
chkgfxShouldResetDidLaunch,
|
||||
@@ -318,25 +187,3 @@ func chkgfxRegisterShoulds(_ ctrl: DialectController) {
|
||||
ctrl.registerFunction { c in f(c as! ChkgfxContext) }
|
||||
}
|
||||
}
|
||||
|
||||
func renderRegisterShoulds(_ ctrl: DialectController) {
|
||||
[
|
||||
renderShouldResetDidLaunch,
|
||||
renderShouldResetPixelSize,
|
||||
|
||||
].forEach { f in
|
||||
ctrl.registerFunction { c in f(c as! RenderContext) }
|
||||
}
|
||||
}
|
||||
|
||||
func renderRegisterEffects(_ ctrl: DialectController) {
|
||||
let _: RenderContext? = registerOneliners(ctrl, [
|
||||
F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) },
|
||||
F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true },
|
||||
F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
|
||||
F.didPrepareGL, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) },
|
||||
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
||||
F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) },
|
||||
|
||||
])
|
||||
}
|
||||
Reference in new issue
Block a user