From 30476a880ddffaa6bf62e3df75d71c62072e85fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 17:08:35 +0300 Subject: [PATCH] recalc --- components/render/mac/view/RenderGLView.swift | 16 ++--- components/render/renderAux.swift | 8 +++ dialect.yml | 11 +++- game/ver-mac/src/dialect.swift | 58 ++++++++++++++----- game/ver-mac/src/render/renderAux.swift | 1 + 5 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 components/render/renderAux.swift create mode 120000 game/ver-mac/src/render/renderAux.swift diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 6eb0f29..927decd 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -6,8 +6,8 @@ import SwiftUI final class RenderGLView: NSOpenGLView { private var renderTimer: Timer? private var ready = false - private var pixelWidth: Int32 = 1 - private var pixelHeight: Int32 = 1 + //private var pixelWidth: Int32 = 1 + //private var pixelHeight: Int32 = 1 private var startTime: CFTimeInterval = 0 override init(frame frameRect: NSRect) { @@ -33,9 +33,7 @@ final class RenderGLView: NSOpenGLView { var swapInterval: Int32 = 1 context.setValues(&swapInterval, for: .swapInterval) - otherPrintStderr("RenderGLView prepareOpenGL bounds \(bounds) backing \(convertToBacking(bounds))") - - sr_init(pixelWidth, pixelHeight, + sr_init(1, 1, RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, RENDER_CONFIG) @@ -84,12 +82,14 @@ final class RenderGLView: NSOpenGLView { super.reshape() otherPrintStderr("RenderGLView reshape bounds \(bounds) backing \(convertToBacking(bounds))") needsDisplay = true + renderSet(F.didReshape, true) } override func viewDidChangeBackingProperties() { super.viewDidChangeBackingProperties() otherPrintStderr("RenderGLView viewDidChangeBackingProperties bounds \(bounds) backing \(convertToBacking(bounds))") needsDisplay = true + renderSet(F.didChangeBacking, true) } override func draw(_ dirtyRect: NSRect) { @@ -98,12 +98,14 @@ final class RenderGLView: NSOpenGLView { context.makeCurrentContext() // Update pixel size + let pixelSize = renderPixelSize(self) + /* let backing = convertToBacking(bounds) - otherPrintStderr("RenderGLView draw bounds \(bounds) backing \(backing)") pixelWidth = Int32(max(1, backing.width)) pixelHeight = Int32(max(1, backing.height)) + */ - sr_resize(pixelWidth, pixelHeight) + sr_resize(pixelSize[0], pixelSize[1]) let t = Float(CACurrentMediaTime() - startTime) diff --git a/components/render/renderAux.swift b/components/render/renderAux.swift new file mode 100644 index 0000000..aa38d1b --- /dev/null +++ b/components/render/renderAux.swift @@ -0,0 +1,8 @@ +import AppKit + +func renderPixelSize(_ view: NSView) -> [Int32] { + let backing = view.convertToBacking(view.bounds) + let w = Int32(max(1, backing.width)) + let h = Int32(max(1, backing.height)) + return [w, h] +} diff --git a/dialect.yml b/dialect.yml index 8bc568f..b17a0aa 100644 --- a/dialect.yml +++ b/dialect.yml @@ -7,11 +7,12 @@ output: RenderContext: type: context fields: + didChangeBacking: Bool didLaunch: Bool + didReshape: Bool didSetup: Bool isReadyToRender: Bool - pixelHeight: Int - pixelWidth: Int + pixelSize: [Int32] RenderComponent: type: component @@ -25,6 +26,12 @@ RenderComponent: c.didLaunch == false then: c.didLaunch = true + pixelSize: + 1. Upon launch: + if: + c.recentField == F.didLaunch + then: + c.pixelSize = [1, 1] RootComponent: type: component diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index a3316be..c32b3ac 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -121,38 +121,43 @@ func registerOneliners( public struct F { public static let count = "count" public static let countText = "countText" + public static let didChangeBacking = "didChangeBacking" public static let didClickIncrement = "didClickIncrement" public static let didLaunch = "didLaunch" + public static let didReshape = "didReshape" public static let didSetup = "didSetup" public static let isReadyToRender = "isReadyToRender" - public static let pixelHeight = "pixelHeight" - public static let pixelWidth = "pixelWidth" + public static let pixelSize = "pixelSize" } public struct RenderContext: DialectContext { + public var didChangeBacking = Bool() public var didLaunch = Bool() + public var didReshape = Bool() public var didSetup = Bool() public var isReadyToRender = Bool() - public var pixelHeight = Int() - public var pixelWidth = Int() + public var pixelSize = [Int32]() public var recentField = "" public func field(_ name: String) -> T { - if (name == "didLaunch") { + if (name == "didChangeBacking") { + return didChangeBacking as! T + } + else if (name == "didLaunch") { return didLaunch as! T } + else if (name == "didReshape") { + return didReshape 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 + else if (name == "pixelSize") { + return pixelSize as! T } return "unknown-field-name" as! T @@ -162,20 +167,23 @@ public struct RenderContext: DialectContext { _ name: String, _ value: Any ) { - if (name == "didLaunch") { + if (name == "didChangeBacking") { + didChangeBacking = value as! Bool + } + else if (name == "didLaunch") { didLaunch = value as! Bool } + else if (name == "didReshape") { + didReshape = 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 + else if (name == "pixelSize") { + pixelSize = value as! [Int32] } } @@ -265,6 +273,23 @@ func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext { 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 + } + + + c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE + return c +} + func rootShouldResetCount(_ c: RootContext) -> RootContext { var c = c @@ -339,6 +364,7 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext { func renderRegisterShoulds(_ ctrl: DialectController) { [ renderShouldResetDidLaunch, + renderShouldResetPixelSize, ].forEach { f in ctrl.registerFunction { c in f(c as! RenderContext) } diff --git a/game/ver-mac/src/render/renderAux.swift b/game/ver-mac/src/render/renderAux.swift new file mode 120000 index 0000000..1975b82 --- /dev/null +++ b/game/ver-mac/src/render/renderAux.swift @@ -0,0 +1 @@ +../../../../components/render/renderAux.swift \ No newline at end of file