Introduce chkgfx #3

Merged
kornerr merged 57 commits from rfix into master 2026-10-22 03:17:23 +00:00
30 changed files with 330 additions and 26 deletions
Showing only changes of commit 47f9eb904a - Show all commits

No files matched your search

+18
View File
@@ -4,6 +4,24 @@ output:
game/ver-mac/src/dialect.swift: game/ver-mac/src/dialect.swift:
type: 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: RenderContext:
type: context type: context
fields: fields:
+4 -4
View File
@@ -3,13 +3,13 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>CFBundleName</key> <key>CFBundleName</key>
<string>OGS Mahjong</string> <string>OGS chkgfx</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>OGS Mahjong</string> <string>OGS chkgfx</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>org.opengamestudio.Mahjong</string> <string>org.opengamestudio.chkgfx</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>ogs-mahjong</string> <string>ogs-chkgfx</string>
<key>CFBundleIconFile</key> <key>CFBundleIconFile</key>
<string>AppIcon</string> <string>AppIcon</string>
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
+2 -2
View File
@@ -5,7 +5,7 @@ import PackageDescription
let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew" let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew"
let package = Package( let package = Package(
name: "OGSMahjong", name: "OGSChkgfx",
platforms: [ platforms: [
.macOS(.v13) .macOS(.v13)
], ],
@@ -19,7 +19,7 @@ let package = Package(
] ]
), ),
.executableTarget( .executableTarget(
name: "ogs-mahjong", name: "ogs-chkgfx",
dependencies: ["RaylibBridge"], dependencies: ["RaylibBridge"],
path: "src", path: "src",
exclude: ["raybri"], exclude: ["raybri"],
+26
View File
@@ -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
}
}
+18
View File
@@ -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)
}
}
+1
View File
@@ -0,0 +1 @@
../../../../components/chkgfx/chkgfx.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/chkgfx/chkgfxVM.swift
+1
View File
@@ -0,0 +1 @@
../../../../../components/chkgfx/mac/view/ChkgfxView.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/other/other.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/raybri/raybri.c
+1
View File
@@ -0,0 +1 @@
../../../../components/raybri/raybri.h
+1
View File
@@ -0,0 +1 @@
../../../../components/render/render.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/render/renderAux.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/render/renderConst.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/render/renderConstShader.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/render/renderEffect.swift
+1
View File
@@ -0,0 +1 @@
../../../../components/render/renderVM.swift
+1
View File
@@ -0,0 +1 @@
../../../../../components/render/mac/view/RenderGLView.swift
+1
View File
@@ -0,0 +1 @@
../../../../../components/render/mac/view/RenderView.swift
+14
View File
@@ -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)
}
}
+9
View File
@@ -0,0 +1,9 @@
import Combine
final class ChkgfxVM: ObservableObject {
static private(set) weak var shared: ChkgfxVM?
init() {
Self.shared = self
}
}
@@ -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)
}
}
-5
View File
@@ -8,10 +8,6 @@ struct RootView: View {
} }
var body: some View { var body: some View {
ZStack {
RenderView()
.ignoresSafeArea()
VStack(spacing: 16) { VStack(spacing: 16) {
Text("Hello, World!") Text("Hello, World!")
.font(.largeTitle) .font(.largeTitle)
@@ -25,5 +21,4 @@ struct RootView: View {
} }
.padding(40) .padding(40)
} }
}
} }
+115
View File
@@ -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
+1 -1
View File
@@ -7,7 +7,7 @@
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>OGS Mahjong</string> <string>OGS Mahjong</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>org.opengamestudio.Mahjong</string> <string>org.opengamestudio.mahjong</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>ogs-mahjong</string> <string>ogs-mahjong</string>
<key>CFBundleIconFile</key> <key>CFBundleIconFile</key>
+4
View File
@@ -7,8 +7,12 @@ struct GameApp: App {
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
ZStack {
RenderView()
.ignoresSafeArea()
RootView(appDelegate.rootVM) RootView(appDelegate.rootVM)
} }
}
.defaultSize(width: 640, height: 480) .defaultSize(width: 640, height: 480)
} }
} }
+73
View File
@@ -123,6 +123,7 @@ public struct F {
public static let count = "count" public static let count = "count"
public static let countText = "countText" public static let countText = "countText"
public static let didClickIncrement = "didClickIncrement" public static let didClickIncrement = "didClickIncrement"
public static let didClickLoadModel = "didClickLoadModel"
public static let didLaunch = "didLaunch" public static let didLaunch = "didLaunch"
public static let didPrepareGL = "didPrepareGL" public static let didPrepareGL = "didPrepareGL"
public static let didSetup = "didSetup" public static let didSetup = "didSetup"
@@ -131,6 +132,44 @@ public struct F {
public static let willDeinit = "willDeinit" 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<T>(_ 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 struct RenderContext: DialectContext {
public var backingPixelSize = [Int32]() public var backingPixelSize = [Int32]()
public var didClickIncrement = Bool() 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( public func renderSet(
_ key: String, _ key: String,
_ value: Any _ value: Any
@@ -270,6 +316,24 @@ public func rootSet(
RootComponent.singleton!.ctrl.set(key, value) 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 { func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext {
var c = c var c = c
@@ -394,6 +458,15 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext {
return c return c
} }
func chkgfxRegisterShoulds(_ ctrl: DialectController) {
[
chkgfxShouldResetDidLaunch,
].forEach { f in
ctrl.registerFunction { c in f(c as! ChkgfxContext) }
}
}
func renderRegisterShoulds(_ ctrl: DialectController) { func renderRegisterShoulds(_ ctrl: DialectController) {
[ [
renderShouldResetDidLaunch, renderShouldResetDidLaunch,
+3 -3
View File
@@ -5,6 +5,6 @@ T=$SDIR/step
source $SDIR/paths source $SDIR/paths
STEP=0 STEP=0
source $T/generateDialect source $T/generateDialect game
source $T/buildMac source $T/buildMac game
source $T/packageMac #source $T/packageMac game
+6 -9
View File
@@ -1,17 +1,14 @@
#!/bin/bash -e #!/bin/bash -e
TARGET=$1
STEP=$((STEP+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 if [[ -z "${RAYLIB_PREFIX:-}" ]]; then
RAYLIB_PREFIX=/opt/homebrew RAYLIB_PREFIX="$(HOMEBREW_NO_AUTO_UPDATE=1 brew --prefix raylib 2>/dev/null)"
fi fi
export RAYLIB_PREFIX export RAYLIB_PREFIX
echo "> > > > raylib: $RAYLIB_PREFIX" echo "Raylib: $RAYLIB_PREFIX"
cd $SDIR/../game/ver-mac cd $SDIR/../$TARGET/ver-mac
swift build # -Xswiftc -swift-version -Xswiftc 6 swift build
+3 -2
View File
@@ -1,6 +1,7 @@
#!/bin/bash -e #!/bin/bash -e
TARGET=$1
STEP=$((STEP+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