render ctx

This commit is contained in:
Михаил Капелько committed 2026-10-19 06:56:04 +03:00
1 parent fbea0673c1
commit fbb02855ee
10 files changed
+167 -15

No files matched your search

+4 -13
View File
@@ -11,20 +11,11 @@ final class RenderGLView: NSOpenGLView {
private var startTime: CFTimeInterval = 0
override init(frame frameRect: NSRect) {
let attributes: [NSOpenGLPixelFormatAttribute] = [
UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core),
UInt32(NSOpenGLPFAColorSize), 24,
UInt32(NSOpenGLPFAAlphaSize), 8,
UInt32(NSOpenGLPFADepthSize), 24,
UInt32(NSOpenGLPFADoubleBuffer),
UInt32(NSOpenGLPFAAccelerated),
0
]
guard let format = NSOpenGLPixelFormat(attributes: attributes) else {
fatalError("Unable to create an OpenGL 3.2 core pixel format")
guard
let format = NSOpenGLPixelFormat(attributes: RENDER_OPENGL_ATTRS)
else {
fatalError("ERROR Could not create required OpenGL pixel format")
}
super.init(frame: frameRect, pixelFormat: format)!
wantsBestResolutionOpenGLSurface = true
}
+14
View File
@@ -0,0 +1,14 @@
class RenderComponent {
let ctrl = DialectController(RenderContext())
static private(set) weak var singleton: RenderComponent?
init() {
Self.singleton = self
renderRegisterEffects(ctrl)
renderRegisterShoulds(ctrl)
}
func setup() {
renderSet(F.didSetup, true)
}
}
+12
View File
@@ -0,0 +1,12 @@
import AppKit
let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [
UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core),
UInt32(NSOpenGLPFAColorSize), 24,
UInt32(NSOpenGLPFAAlphaSize), 8,
UInt32(NSOpenGLPFADepthSize), 24,
UInt32(NSOpenGLPFADoubleBuffer),
UInt32(NSOpenGLPFAAccelerated),
0
]
+12
View File
@@ -0,0 +1,12 @@
import Combine
import Foundation
final class RenderVM: ObservableObject {
var timer: Timer?
static private(set) weak var shared: RenderVM?
init() {
Self.shared = self
}
}
+22 -1
View File
@@ -4,10 +4,31 @@ output:
game/ver-mac/src/dialect.swift:
type: swift
RenderContext:
type: context
fields:
didLaunch: Bool
didSetup: Bool
isReadyToRender: Bool
pixelHeight: Int
pixelWidth: Int
RenderComponent:
type: component
oneliners:
- isReadyToRender: print("ИГР isRTR: '\(c.isReadyToRender)'")
shoulds:
didLaunch:
1. Only once during the first setup:
if:
c.recentField == F.didSetup &&
c.didLaunch == false
then:
c.didLaunch = true
RootComponent:
type: component
oneliners:
- countText: print(c.countText)
- countText: RootVM.shared!.countText = c.countText
shoulds:
count:
+4
View File
@@ -4,6 +4,8 @@ final class AppDelegate:
NSObject,
NSApplicationDelegate
{
let render = RenderComponent()
let renderVM = RenderVM()
let root = RootComponent()
let rootVM = RootVM()
@@ -14,6 +16,8 @@ final class AppDelegate:
otherSetupConsoleLogging(root.ctrl, "Root")
root.setup()
otherSetupConsoleLogging(render.ctrl, "Render")
render.setup()
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
+96 -1
View File
@@ -124,8 +124,63 @@ public struct F {
public static let didClickIncrement = "didClickIncrement"
public static let didLaunch = "didLaunch"
public static let didSetup = "didSetup"
public static let isReadyToRender = "isReadyToRender"
public static let pixelHeight = "pixelHeight"
public static let pixelWidth = "pixelWidth"
}
public struct RenderContext: DialectContext {
public var didLaunch = Bool()
public var didSetup = Bool()
public var isReadyToRender = Bool()
public var pixelHeight = Int()
public var pixelWidth = Int()
public var recentField = ""
public func field<T>(_ name: String) -> T {
if (name == "didLaunch") {
return didLaunch as! T
}
else if (name == "didSetup") {
return didSetup as! T
}
else if (name == "isReadyToRender") {
return isReadyToRender as! T
}
else if (name == "pixelHeight") {
return pixelHeight as! T
}
else if (name == "pixelWidth") {
return pixelWidth as! T
}
return "unknown-field-name" as! T
}
public mutating func setField(
_ name: String,
_ value: Any
) {
if (name == "didLaunch") {
didLaunch = value as! Bool
}
else if (name == "didSetup") {
didSetup = value as! Bool
}
else if (name == "isReadyToRender") {
isReadyToRender = value as! Bool
}
else if (name == "pixelHeight") {
pixelHeight = value as! Int
}
else if (name == "pixelWidth") {
pixelWidth = value as! Int
}
}
}
public struct RootContext: DialectContext {
public var count = Int()
public var countText = String()
@@ -178,6 +233,13 @@ public struct RootContext: DialectContext {
}
}
public func renderSet(
_ key: String,
_ value: Any
) {
RenderComponent.singleton!.ctrl.set(key, value)
}
public func rootSet(
_ key: String,
_ value: Any
@@ -185,6 +247,24 @@ public func rootSet(
RootComponent.singleton!.ctrl.set(key, value)
}
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 rootShouldResetCount(_ c: RootContext) -> RootContext {
var c = c
@@ -256,6 +336,15 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext {
return c
}
func renderRegisterShoulds(_ ctrl: DialectController) {
[
renderShouldResetDidLaunch,
].forEach { f in
ctrl.registerFunction { c in f(c as! RenderContext) }
}
}
func rootRegisterShoulds(_ ctrl: DialectController) {
[
rootShouldResetCount,
@@ -267,9 +356,15 @@ func rootRegisterShoulds(_ ctrl: DialectController) {
}
}
func renderRegisterEffects(_ ctrl: DialectController) {
let _: RenderContext? = registerOneliners(ctrl, [
F.isReadyToRender, { (c: RenderContext) in print("ИГР isRTR: '\(c.isReadyToRender)'") },
])
}
func rootRegisterEffects(_ ctrl: DialectController) {
let _: RootContext? = registerOneliners(ctrl, [
F.countText, { (c: RootContext) in print(c.countText) },
F.countText, { (c: RootContext) in RootVM.shared!.countText = c.countText },
])
+1
View File
@@ -0,0 +1 @@
../../../../components/render/render.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/render/renderConst.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/render/renderVM.swift