From 47f9eb904a49d33300f414c23f0db70326b4623b 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: Wed, 21 Oct 2026 17:35:20 +0300 Subject: [PATCH] some --- dialect.yml => chkgfx/dialect.yml | 18 +++ chkgfx/ver-mac/Info.plist | 8 +- chkgfx/ver-mac/Package.swift | 4 +- chkgfx/ver-mac/src/AppDelegate.swift | 26 ++++ chkgfx/ver-mac/src/ChkgfxApp.swift | 18 +++ chkgfx/ver-mac/src/chkgfx/chkgfx.swift | 1 + chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift | 1 + .../ver-mac/src/chkgfx/view/ChkgfxView.swift | 1 + chkgfx/ver-mac/src/other/other.swift | 1 + chkgfx/ver-mac/src/raybri/raybri.c | 1 + chkgfx/ver-mac/src/raybri/raybri.h | 1 + chkgfx/ver-mac/src/render/render.swift | 1 + chkgfx/ver-mac/src/render/renderAux.swift | 1 + chkgfx/ver-mac/src/render/renderConst.swift | 1 + .../src/render/renderConstShader.swift | 1 + chkgfx/ver-mac/src/render/renderEffect.swift | 1 + chkgfx/ver-mac/src/render/renderVM.swift | 1 + .../src/render/view/RenderGLView.swift | 1 + .../ver-mac/src/render/view/RenderView.swift | 1 + components/chkgfx/chkgfx.swift | 14 +++ components/chkgfx/chkgfxVM.swift | 9 ++ components/chkgfx/mac/view/ChkgfxView.swift | 20 +++ components/root/mac/view/RootView.swift | 21 ++-- game/dialect.yml | 115 ++++++++++++++++++ game/ver-mac/Info.plist | 2 +- game/ver-mac/src/GameApp.swift | 6 +- game/ver-mac/src/dialect.swift | 73 +++++++++++ util/{build-mac => build-game-mac} | 6 +- util/step/buildMac | 15 +-- util/step/generateDialect | 5 +- 30 files changed, 339 insertions(+), 35 deletions(-) rename dialect.yml => chkgfx/dialect.yml (87%) create mode 100644 chkgfx/ver-mac/src/AppDelegate.swift create mode 100644 chkgfx/ver-mac/src/ChkgfxApp.swift create mode 120000 chkgfx/ver-mac/src/chkgfx/chkgfx.swift create mode 120000 chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift create mode 120000 chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift create mode 120000 chkgfx/ver-mac/src/other/other.swift create mode 120000 chkgfx/ver-mac/src/raybri/raybri.c create mode 120000 chkgfx/ver-mac/src/raybri/raybri.h create mode 120000 chkgfx/ver-mac/src/render/render.swift create mode 120000 chkgfx/ver-mac/src/render/renderAux.swift create mode 120000 chkgfx/ver-mac/src/render/renderConst.swift create mode 120000 chkgfx/ver-mac/src/render/renderConstShader.swift create mode 120000 chkgfx/ver-mac/src/render/renderEffect.swift create mode 120000 chkgfx/ver-mac/src/render/renderVM.swift create mode 120000 chkgfx/ver-mac/src/render/view/RenderGLView.swift create mode 120000 chkgfx/ver-mac/src/render/view/RenderView.swift create mode 100644 components/chkgfx/chkgfx.swift create mode 100644 components/chkgfx/chkgfxVM.swift create mode 100644 components/chkgfx/mac/view/ChkgfxView.swift create mode 100644 game/dialect.yml rename util/{build-mac => build-game-mac} (53%) diff --git a/dialect.yml b/chkgfx/dialect.yml similarity index 87% rename from dialect.yml rename to chkgfx/dialect.yml index 9969dad..4fd7a71 100644 --- a/dialect.yml +++ b/chkgfx/dialect.yml @@ -4,6 +4,24 @@ output: game/ver-mac/src/dialect.swift: type: swift +ChkgfxComponent: + type: component + shoulds: + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + +ChkgfxContext: + type: context + fields: + didClickLoadModel: Bool + didLaunch: Bool + didSetup: Bool + RenderContext: type: context fields: diff --git a/chkgfx/ver-mac/Info.plist b/chkgfx/ver-mac/Info.plist index dc46284..6a160d9 100644 --- a/chkgfx/ver-mac/Info.plist +++ b/chkgfx/ver-mac/Info.plist @@ -3,13 +3,13 @@ CFBundleName - OGS Mahjong + OGS chkgfx CFBundleDisplayName - OGS Mahjong + OGS chkgfx CFBundleIdentifier - org.opengamestudio.Mahjong + org.opengamestudio.chkgfx CFBundleExecutable - ogs-mahjong + ogs-chkgfx CFBundleIconFile AppIcon CFBundlePackageType diff --git a/chkgfx/ver-mac/Package.swift b/chkgfx/ver-mac/Package.swift index 1dff832..3974170 100644 --- a/chkgfx/ver-mac/Package.swift +++ b/chkgfx/ver-mac/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew" let package = Package( - name: "OGSMahjong", + name: "OGSChkgfx", platforms: [ .macOS(.v13) ], @@ -19,7 +19,7 @@ let package = Package( ] ), .executableTarget( - name: "ogs-mahjong", + name: "ogs-chkgfx", dependencies: ["RaylibBridge"], path: "src", exclude: ["raybri"], diff --git a/chkgfx/ver-mac/src/AppDelegate.swift b/chkgfx/ver-mac/src/AppDelegate.swift new file mode 100644 index 0000000..1442afc --- /dev/null +++ b/chkgfx/ver-mac/src/AppDelegate.swift @@ -0,0 +1,26 @@ +import AppKit + +final class AppDelegate: + NSObject, + NSApplicationDelegate +{ + let chkgfx = ChkgfxComponent() + let chkgfxVM = ChkgfxVM() + let render = RenderComponent() + let renderVM = RenderVM() + + func applicationDidFinishLaunching(_ notification: Notification) { + // Bring the app to the foreground + NSApp.setActivationPolicy(.regular) + NSApp.activate(ignoringOtherApps: true) + + otherSetupConsoleLogging(chkgfx.ctrl, "Chkgfx") + chkgfx.setup() + otherSetupConsoleLogging(render.ctrl, "Render") + render.setup() + } + + func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + true + } +} diff --git a/chkgfx/ver-mac/src/ChkgfxApp.swift b/chkgfx/ver-mac/src/ChkgfxApp.swift new file mode 100644 index 0000000..1aeaeff --- /dev/null +++ b/chkgfx/ver-mac/src/ChkgfxApp.swift @@ -0,0 +1,18 @@ +import AppKit +import SwiftUI + +@main +struct ChkgfxApp: App { + @NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate + + var body: some Scene { + WindowGroup { + ZStack { + RenderView() + .ignoresSafeArea() + ChkgfxView(appDelegate.rootVM) + } + } + .defaultSize(width: 640, height: 480) + } +} diff --git a/chkgfx/ver-mac/src/chkgfx/chkgfx.swift b/chkgfx/ver-mac/src/chkgfx/chkgfx.swift new file mode 120000 index 0000000..3c6bb5e --- /dev/null +++ b/chkgfx/ver-mac/src/chkgfx/chkgfx.swift @@ -0,0 +1 @@ +../../../../components/chkgfx/chkgfx.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift b/chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift new file mode 120000 index 0000000..cf74ca4 --- /dev/null +++ b/chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift @@ -0,0 +1 @@ +../../../../components/chkgfx/chkgfxVM.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift b/chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift new file mode 120000 index 0000000..8533e0c --- /dev/null +++ b/chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift @@ -0,0 +1 @@ +../../../../../components/chkgfx/mac/view/ChkgfxView.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/other/other.swift b/chkgfx/ver-mac/src/other/other.swift new file mode 120000 index 0000000..f91488c --- /dev/null +++ b/chkgfx/ver-mac/src/other/other.swift @@ -0,0 +1 @@ +../../../../components/other/other.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/raybri/raybri.c b/chkgfx/ver-mac/src/raybri/raybri.c new file mode 120000 index 0000000..52b1940 --- /dev/null +++ b/chkgfx/ver-mac/src/raybri/raybri.c @@ -0,0 +1 @@ +../../../../components/raybri/raybri.c \ No newline at end of file diff --git a/chkgfx/ver-mac/src/raybri/raybri.h b/chkgfx/ver-mac/src/raybri/raybri.h new file mode 120000 index 0000000..daec20f --- /dev/null +++ b/chkgfx/ver-mac/src/raybri/raybri.h @@ -0,0 +1 @@ +../../../../components/raybri/raybri.h \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/render.swift b/chkgfx/ver-mac/src/render/render.swift new file mode 120000 index 0000000..5e4b117 --- /dev/null +++ b/chkgfx/ver-mac/src/render/render.swift @@ -0,0 +1 @@ +../../../../components/render/render.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderAux.swift b/chkgfx/ver-mac/src/render/renderAux.swift new file mode 120000 index 0000000..1975b82 --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderAux.swift @@ -0,0 +1 @@ +../../../../components/render/renderAux.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderConst.swift b/chkgfx/ver-mac/src/render/renderConst.swift new file mode 120000 index 0000000..d953714 --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderConst.swift @@ -0,0 +1 @@ +../../../../components/render/renderConst.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderConstShader.swift b/chkgfx/ver-mac/src/render/renderConstShader.swift new file mode 120000 index 0000000..2dcc2d4 --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderConstShader.swift @@ -0,0 +1 @@ +../../../../components/render/renderConstShader.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderEffect.swift b/chkgfx/ver-mac/src/render/renderEffect.swift new file mode 120000 index 0000000..d269bb5 --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderEffect.swift @@ -0,0 +1 @@ +../../../../components/render/renderEffect.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderVM.swift b/chkgfx/ver-mac/src/render/renderVM.swift new file mode 120000 index 0000000..dde0ace --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderVM.swift @@ -0,0 +1 @@ +../../../../components/render/renderVM.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/view/RenderGLView.swift b/chkgfx/ver-mac/src/render/view/RenderGLView.swift new file mode 120000 index 0000000..7223ae3 --- /dev/null +++ b/chkgfx/ver-mac/src/render/view/RenderGLView.swift @@ -0,0 +1 @@ +../../../../../components/render/mac/view/RenderGLView.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/view/RenderView.swift b/chkgfx/ver-mac/src/render/view/RenderView.swift new file mode 120000 index 0000000..754ef01 --- /dev/null +++ b/chkgfx/ver-mac/src/render/view/RenderView.swift @@ -0,0 +1 @@ +../../../../../components/render/mac/view/RenderView.swift \ No newline at end of file diff --git a/components/chkgfx/chkgfx.swift b/components/chkgfx/chkgfx.swift new file mode 100644 index 0000000..fada653 --- /dev/null +++ b/components/chkgfx/chkgfx.swift @@ -0,0 +1,14 @@ +class ChkgfxComponent { + let ctrl = DialectController(ChkgfxContext()) + static private(set) weak var singleton: ChkgfxComponent? + + init() { + Self.singleton = self + chkgfxRegisterEffects(ctrl) + chkgfxRegisterShoulds(ctrl) + } + + func setup() { + chkgfxSet(F.didSetup, true) + } +} diff --git a/components/chkgfx/chkgfxVM.swift b/components/chkgfx/chkgfxVM.swift new file mode 100644 index 0000000..aaf0d9f --- /dev/null +++ b/components/chkgfx/chkgfxVM.swift @@ -0,0 +1,9 @@ +import Combine + +final class ChkgfxVM: ObservableObject { + static private(set) weak var shared: ChkgfxVM? + + init() { + Self.shared = self + } +} diff --git a/components/chkgfx/mac/view/ChkgfxView.swift b/components/chkgfx/mac/view/ChkgfxView.swift new file mode 100644 index 0000000..eda0b97 --- /dev/null +++ b/components/chkgfx/mac/view/ChkgfxView.swift @@ -0,0 +1,20 @@ +import SwiftUI + +struct ChkgfxView: View { + @ObservedObject var vm: ChkgfxVM + + init(_ vm: ChkgfxVM) { + self.vm = vm + } + + var body: some View { + VStack(spacing: 16) { + Text("Check graphics") + .font(.largeTitle) + Button("Load model") { + rootSet(F.didClickLoadModel, true) + } + } + .padding(40) + } +} diff --git a/components/root/mac/view/RootView.swift b/components/root/mac/view/RootView.swift index 034e891..b31b123 100644 --- a/components/root/mac/view/RootView.swift +++ b/components/root/mac/view/RootView.swift @@ -8,22 +8,17 @@ struct RootView: View { } var body: some View { - ZStack { - RenderView() - .ignoresSafeArea() + VStack(spacing: 16) { + Text("Hello, World!") + .font(.largeTitle) - VStack(spacing: 16) { - Text("Hello, World!") - .font(.largeTitle) + Text(vm.countText) + .font(.title3.monospacedDigit()) - Text(vm.countText) - .font(.title3.monospacedDigit()) - - Button("Increment") { - rootSet(F.didClickIncrement, true) - } + Button("Increment") { + rootSet(F.didClickIncrement, true) } - .padding(40) } + .padding(40) } } diff --git a/game/dialect.yml b/game/dialect.yml new file mode 100644 index 0000000..4fd7a71 --- /dev/null +++ b/game/dialect.yml @@ -0,0 +1,115 @@ +version: 4 + +output: + game/ver-mac/src/dialect.swift: + type: swift + +ChkgfxComponent: + type: component + shoulds: + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + +ChkgfxContext: + type: context + fields: + didClickLoadModel: Bool + didLaunch: Bool + didSetup: Bool + +RenderContext: + type: context + fields: + backingPixelSize: [Int32] + didClickIncrement: Bool + didLaunch: Bool + didPrepareGL: Bool + didSetup: Bool + pixelSize: [Int32] + reshapePixelSize: [Int32] + willDeinit: Bool + +RenderComponent: + type: component + oneliners: + - didClickIncrement: renderLoadCubeModel(RenderVM.shared!) + - didPrepareGL: renderInit(RenderVM.shared!) + - didPrepareGL: RenderVM.shared!.didPrepareGL = true + - didPrepareGL: renderStartTimer(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 + +RootComponent: + type: component + oneliners: + - countText: RootVM.shared!.countText = c.countText + - didClickIncrement: renderSet(F.didClickIncrement, true) + shoulds: + count: + 1. Upon hitting 10 the first time: + if: + c.recentField == F.didClickIncrement && + c.count == 7 + then: + c.count += 10 + 2. Upon each button click: + if: + c.recentField == F.didClickIncrement + then: + c.count += 1 + countText: + 1. Upon each count change: + if: + c.recentField == F.count + then: + c.countText = "Count: '\(c.count)'" + 2. Upon launch: + if: + c.recentField == F.didLaunch + then: + c.countText = "Press the button to count" + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + +RootContext: + type: context + fields: + count: Int + countText: String + didClickIncrement: Bool + didLaunch: Bool + didSetup: Bool diff --git a/game/ver-mac/Info.plist b/game/ver-mac/Info.plist index dc46284..47d5716 100644 --- a/game/ver-mac/Info.plist +++ b/game/ver-mac/Info.plist @@ -7,7 +7,7 @@ CFBundleDisplayName OGS Mahjong CFBundleIdentifier - org.opengamestudio.Mahjong + org.opengamestudio.mahjong CFBundleExecutable ogs-mahjong CFBundleIconFile diff --git a/game/ver-mac/src/GameApp.swift b/game/ver-mac/src/GameApp.swift index 65825ae..449a921 100644 --- a/game/ver-mac/src/GameApp.swift +++ b/game/ver-mac/src/GameApp.swift @@ -7,7 +7,11 @@ struct GameApp: App { var body: some Scene { WindowGroup { - RootView(appDelegate.rootVM) + ZStack { + RenderView() + .ignoresSafeArea() + RootView(appDelegate.rootVM) + } } .defaultSize(width: 640, height: 480) } diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index 21e24ec..8138c9a 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -123,6 +123,7 @@ public struct F { public static let count = "count" public static let countText = "countText" public static let didClickIncrement = "didClickIncrement" + public static let didClickLoadModel = "didClickLoadModel" public static let didLaunch = "didLaunch" public static let didPrepareGL = "didPrepareGL" public static let didSetup = "didSetup" @@ -131,6 +132,44 @@ public struct F { public static let willDeinit = "willDeinit" } +public struct ChkgfxContext: DialectContext { + public var didClickLoadModel = Bool() + public var didLaunch = Bool() + public var didSetup = Bool() + + public var recentField = "" + + public func field(_ name: String) -> T { + if (name == "didClickLoadModel") { + return didClickLoadModel as! T + } + else if (name == "didLaunch") { + return didLaunch as! T + } + else if (name == "didSetup") { + return didSetup as! T + } + + return "unknown-field-name" as! T + } + + public mutating func setField( + _ name: String, + _ value: Any + ) { + if (name == "didClickLoadModel") { + didClickLoadModel = value as! Bool + } + else if (name == "didLaunch") { + didLaunch = value as! Bool + } + else if (name == "didSetup") { + didSetup = value as! Bool + } + + } +} + public struct RenderContext: DialectContext { public var backingPixelSize = [Int32]() public var didClickIncrement = Bool() @@ -256,6 +295,13 @@ public struct RootContext: DialectContext { } } +public func chkgfxSet( + _ key: String, + _ value: Any +) { + ChkgfxComponent.singleton!.ctrl.set(key, value) +} + public func renderSet( _ key: String, _ value: Any @@ -270,6 +316,24 @@ public func rootSet( RootComponent.singleton!.ctrl.set(key, value) } +func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext { + 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 renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext { var c = c @@ -394,6 +458,15 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext { return c } +func chkgfxRegisterShoulds(_ ctrl: DialectController) { + [ + chkgfxShouldResetDidLaunch, + + ].forEach { f in + ctrl.registerFunction { c in f(c as! ChkgfxContext) } + } +} + func renderRegisterShoulds(_ ctrl: DialectController) { [ renderShouldResetDidLaunch, diff --git a/util/build-mac b/util/build-game-mac similarity index 53% rename from util/build-mac rename to util/build-game-mac index 872a9f5..ac85d2f 100755 --- a/util/build-mac +++ b/util/build-game-mac @@ -5,6 +5,6 @@ T=$SDIR/step source $SDIR/paths STEP=0 -source $T/generateDialect -source $T/buildMac -source $T/packageMac +source $T/generateDialect game +source $T/buildMac game +#source $T/packageMac game diff --git a/util/step/buildMac b/util/step/buildMac index cee602a..e1d2386 100755 --- a/util/step/buildMac +++ b/util/step/buildMac @@ -1,17 +1,14 @@ #!/bin/bash -e +TARGET=$1 STEP=$((STEP+1)) -echo -e "\n> > > > Step №$STEP. Build for macOS" +echo -e "\n> > > > Step №$STEP. Build '$TARGET' for macOS" -# raylib is required for the 3D scene (used by the RaylibBridge target). -if [[ -z "${RAYLIB_PREFIX:-}" ]] && command -v brew >/dev/null 2>&1; then - RAYLIB_PREFIX="$(HOMEBREW_NO_AUTO_UPDATE=1 brew --prefix raylib 2>/dev/null || true)" -fi if [[ -z "${RAYLIB_PREFIX:-}" ]]; then - RAYLIB_PREFIX=/opt/homebrew + RAYLIB_PREFIX="$(HOMEBREW_NO_AUTO_UPDATE=1 brew --prefix raylib 2>/dev/null)" fi export RAYLIB_PREFIX -echo "> > > > raylib: $RAYLIB_PREFIX" +echo "Raylib: $RAYLIB_PREFIX" -cd $SDIR/../game/ver-mac -swift build # -Xswiftc -swift-version -Xswiftc 6 +cd $SDIR/../$TARGET/ver-mac +swift build diff --git a/util/step/generateDialect b/util/step/generateDialect index 65357f5..5fe5cf4 100755 --- a/util/step/generateDialect +++ b/util/step/generateDialect @@ -1,6 +1,7 @@ #!/bin/bash -e +TARGET=$1 STEP=$((STEP+1)) -echo -e "\n> > > > Step №$STEP. Generate Dialect" +echo -e "\n> > > > Step №$STEP. Generate Dialect for '$TARGET'" -$SDIR/../../dialect/util/run-generator --file=$SDIR/../dialect.yml +$SDIR/../../dialect/util/run-generator --file=$SDIR/../$TARGET/dialect.yml