create hrb for mac os with ai
This commit is contained in:
1 parent
9789b13f22
commit
423a024de1
33 files changed
+771
No files matched your search
@@ -0,0 +1,14 @@
|
||||
class HRBComponent {
|
||||
let ctrl = DialectController(HRBContext())
|
||||
static private(set) weak var singleton: HRBComponent?
|
||||
|
||||
init() {
|
||||
Self.singleton = self
|
||||
hrbRegisterEffects(ctrl)
|
||||
hrbRegisterShoulds(ctrl)
|
||||
}
|
||||
|
||||
func setup() {
|
||||
hrbSet(F.didSetup, true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import Combine
|
||||
|
||||
final class HRBVM: ObservableObject {
|
||||
@Published var titleText = ""
|
||||
|
||||
static private(set) weak var shared: HRBVM?
|
||||
|
||||
init() {
|
||||
Self.shared = self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import SwiftUI
|
||||
|
||||
struct HRBView: View {
|
||||
@ObservedObject var vm: HRBVM
|
||||
|
||||
init(_ vm: HRBVM) {
|
||||
self.vm = vm
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 16) {
|
||||
ZStack {
|
||||
Text(vm.titleText)
|
||||
.font(.largeTitle)
|
||||
.foregroundStyle(.white)
|
||||
.offset(x: 1, y: 1)
|
||||
Text(vm.titleText)
|
||||
.font(.largeTitle)
|
||||
.foregroundStyle(.black)
|
||||
}
|
||||
}
|
||||
.padding(40)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
# hello-raylib
|
||||
|
||||
macOS SwiftUI sample: raylib clears an NSOpenGLView blue, with the HRBView text overlay. No models, textures or custom shaders are loaded.
|
||||
|
||||
```sh
|
||||
brew install raylib
|
||||
util/build-mac
|
||||
util/run-mac
|
||||
```
|
||||
|
||||
The build generates Swift from `dialect.yml` using the repository generator,
|
||||
compiles the SPM executable and packages `ver-mac/.build/hello-raylib.app`.
|
||||
Only Swift output is configured, so Kotlin/LLM conversion is not needed.
|
||||
`RAYLIB_PREFIX` can override the detected Homebrew raylib prefix.
|
||||
|
||||
`src` links to HRB, Render and helper files in `components/`.
|
||||
HRBAppDelegate owns both components and their models. Render initialization loads
|
||||
OpenGL entry points only after making the view's context current. The timer
|
||||
requests redraws; rendering uses backing-pixel dimensions and presents with
|
||||
flushBuffer. Dialect folds launch, resize and backing-scale events into the
|
||||
render model. The C translation unit compiles the bridge implementation, while
|
||||
rlgl itself comes from the linked Homebrew raylib library.
|
||||
|
||||
Resources contain the shared macOS app icon. The minimum macOS version is 13.
|
||||
A newer Homebrew raylib binary may emit a deployment-target linker warning;
|
||||
building successfully on the current machine does not verify macOS 13 runtime
|
||||
compatibility with that binary.
|
||||
@@ -0,0 +1,90 @@
|
||||
version: 4
|
||||
|
||||
output:
|
||||
ver-mac/src/dialect.swift:
|
||||
type: swift
|
||||
|
||||
HRBContext:
|
||||
type: context
|
||||
fields:
|
||||
titleText: String
|
||||
didLaunch: Bool
|
||||
didSetup: Bool
|
||||
|
||||
HRBComponent:
|
||||
type: component
|
||||
oneliners:
|
||||
- titleText: HRBVM.shared!.titleText = c.titleText
|
||||
shoulds:
|
||||
titleText:
|
||||
1. Upon launch:
|
||||
if:
|
||||
c.recentField == F.didLaunch
|
||||
then:
|
||||
c.titleText = "Blue"
|
||||
didLaunch:
|
||||
1. Only once during the first setup:
|
||||
if:
|
||||
c.recentField == F.didSetup &&
|
||||
c.didLaunch == false
|
||||
then:
|
||||
c.didLaunch = true
|
||||
|
||||
RenderContext:
|
||||
type: context
|
||||
fields:
|
||||
backingPixelSize: [Int32]
|
||||
didLaunch: Bool
|
||||
didPrepareGL: Bool
|
||||
didPrepareMacGL: Bool
|
||||
didSetup: Bool
|
||||
pixelSize: [Int32]
|
||||
reshapePixelSize: [Int32]
|
||||
willDeinit: Bool
|
||||
willRecreateSurface: Bool
|
||||
|
||||
RenderComponent:
|
||||
type: component
|
||||
oneliners:
|
||||
- didPrepareGL: renderInit(RenderVM.shared!)
|
||||
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
|
||||
- didPrepareGL: renderStartTimer(RenderVM.shared!)
|
||||
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
||||
- willDeinit: renderDeinit(RenderVM.shared!)
|
||||
- willRecreateSurface: renderRecreateSurface(RenderVM.shared!)
|
||||
shoulds:
|
||||
didLaunch:
|
||||
1. Only once during the first setup:
|
||||
if:
|
||||
c.recentField == F.didSetup &&
|
||||
!c.didLaunch
|
||||
then:
|
||||
c.didLaunch = true
|
||||
didPrepareGL:
|
||||
1. Upon preparing macOS OpenGL:
|
||||
if:
|
||||
c.recentField == F.didPrepareMacGL
|
||||
then:
|
||||
c.didPrepareGL = 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
|
||||
willRecreateSurface:
|
||||
1. Upon resize:
|
||||
if:
|
||||
c.recentField == F.reshapePixelSize
|
||||
then:
|
||||
c.willRecreateSurface = true
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash -e
|
||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||
|
||||
T=$SDIR/step
|
||||
TARGET=hello-raylib
|
||||
|
||||
STEP=0
|
||||
source $T/generateDialect $TARGET
|
||||
source $T/buildMac $TARGET
|
||||
source $T/packageMac $TARGET hello-raylib
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash -e
|
||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||
|
||||
T=$SDIR/step
|
||||
|
||||
STEP=0
|
||||
source $T/runMac hello-raylib hello-raylib
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TARGET=$1
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Step №$STEP. Build '$TARGET' for macOS"
|
||||
|
||||
cd $SDIR/../ver-mac
|
||||
export RAYLIB_PREFIX="${RAYLIB_PREFIX:-$(brew --prefix raylib)}"
|
||||
swift build
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TARGET=$1
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Step №$STEP. Generate Dialect for '$TARGET'"
|
||||
|
||||
$SDIR/../../../util/run-generator --file=$SDIR/../dialect.yml
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TARGET=$1
|
||||
APP_NAME=$2
|
||||
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Step №$STEP. Make '$APP_NAME' macOS package for '$TARGET'"
|
||||
|
||||
APP_MAC="$SDIR/../ver-mac/.build/$APP_NAME.app"
|
||||
rm -rf "$APP_MAC"
|
||||
|
||||
APP_DAT="$APP_MAC/Contents"
|
||||
mkdir -p "$APP_DAT/MacOS"
|
||||
mkdir -p "$APP_DAT/Resources"
|
||||
cp $SDIR/../ver-mac/.build/debug/$TARGET "$APP_DAT/MacOS/$TARGET"
|
||||
cp $SDIR/../ver-mac/Info.plist "$APP_DAT/Info.plist"
|
||||
# Copy resources with symlink dereferencing
|
||||
cp -R -L $SDIR/../ver-mac/res/* "$APP_DAT/Resources/"
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TARGET=$1
|
||||
APP_NAME=$2
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Step №$STEP. Run macOS app for '$TARGET'"
|
||||
|
||||
"$SDIR/../ver-mac/.build/$APP_NAME.app/Contents/MacOS/$TARGET"
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleName</key>
|
||||
<string>hello-raylib</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>hello-raylib</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.opengamestudio.hello-raylib</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>hello-raylib</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>AppIcon</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>13.0</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,30 @@
|
||||
// swift-tools-version: 5.9
|
||||
import Foundation
|
||||
import PackageDescription
|
||||
|
||||
let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew"
|
||||
|
||||
let package = Package(
|
||||
name: "hello-raylib",
|
||||
platforms: [.macOS(.v13)],
|
||||
targets: [
|
||||
.target(
|
||||
name: "RaylibBridge",
|
||||
path: "src",
|
||||
sources: ["Raylib.c"],
|
||||
publicHeadersPath: "raybri",
|
||||
cSettings: [
|
||||
.headerSearchPath("raybri"),
|
||||
.unsafeFlags(["-I", "\(raylibPrefix)/include"])
|
||||
]
|
||||
),
|
||||
.executableTarget(
|
||||
name: "hello-raylib",
|
||||
dependencies: ["RaylibBridge"],
|
||||
path: "src",
|
||||
exclude: ["raybri", "Raylib.c"],
|
||||
swiftSettings: [.unsafeFlags(["-Xcc", "-DGL_SILENCE_DEPRECATION"])],
|
||||
linkerSettings: [.unsafeFlags(["-L", "\(raylibPrefix)/lib", "-lraylib"])]
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
../../../../res/AppIcon.icns
|
||||
@@ -0,0 +1,16 @@
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct HRBApp: App {
|
||||
@NSApplicationDelegateAdaptor(HRBAppDelegate.self) private var appDelegate
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ZStack {
|
||||
RenderView().ignoresSafeArea()
|
||||
HRBView(appDelegate.hrbVM)
|
||||
}
|
||||
}
|
||||
.defaultSize(width: 640, height: 480)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import AppKit
|
||||
|
||||
final class HRBAppDelegate: NSObject, NSApplicationDelegate {
|
||||
let hrb = HRBComponent()
|
||||
let hrbVM = HRBVM()
|
||||
let render = RenderComponent()
|
||||
let renderVM = RenderVM()
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
NSApp.setActivationPolicy(.regular)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
otherSetupConsoleLogging(hrb.ctrl, "HRB")
|
||||
hrb.setup()
|
||||
otherSetupConsoleLogging(render.ctrl, "Render")
|
||||
render.setup()
|
||||
}
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#define RAYBRI_CONST_IMPLEMENTATION
|
||||
#include "raybriConst.h"
|
||||
|
||||
#define RAYBRI_AUX_IMPLEMENTATION
|
||||
#include "raybriAux.h"
|
||||
|
||||
#define RAYBRI_IMPLEMENTATION
|
||||
#include "raybri.h"
|
||||
|
||||
// rlgl is provided by the linked Homebrew raylib library.
|
||||
@@ -0,0 +1,427 @@
|
||||
|
||||
// Reusable "none" constant
|
||||
public let DIALECT_CONTEXT_RECENT_FIELD_NONE = "none"
|
||||
|
||||
// Base protocol for each component's state
|
||||
public protocol DialectContext {
|
||||
var recentField: String { get set }
|
||||
|
||||
func field<T>(_ name: String) -> T
|
||||
func fieldAny(_ name: String) -> Any
|
||||
mutating func setField(_ name: String, _ value: Any)
|
||||
}
|
||||
|
||||
// Default implementation of `fieldAny` method for the protocol
|
||||
public extension DialectContext {
|
||||
func fieldAny(_ name: String) -> Any {
|
||||
return field(name)
|
||||
}
|
||||
}
|
||||
|
||||
// The engine of the dialect components
|
||||
public class DialectController {
|
||||
var callbacks = [(DialectContext) -> Void]()
|
||||
var context: DialectContext
|
||||
var functions = [(DialectContext) -> DialectContext]()
|
||||
var isProcessingQueue = false
|
||||
var queue = [DialectContext]()
|
||||
|
||||
public init(_ context: DialectContext) {
|
||||
self.context = context
|
||||
}
|
||||
|
||||
func executeFunctions() {
|
||||
let c = queue.removeFirst()
|
||||
// Keep SSOT: Only allow single field change per should-function
|
||||
context.recentField = c.recentField
|
||||
context.setField(c.recentField, c.fieldAny(c.recentField))
|
||||
|
||||
for f in functions {
|
||||
let ctx = f(context)
|
||||
if ctx.recentField != DIALECT_CONTEXT_RECENT_FIELD_NONE {
|
||||
queue.append(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
reportContext()
|
||||
}
|
||||
|
||||
func processQueue() {
|
||||
// Prevent recursion.
|
||||
if isProcessingQueue {
|
||||
return
|
||||
}
|
||||
|
||||
isProcessingQueue = true
|
||||
|
||||
while (queue.count > 0) {
|
||||
executeFunctions()
|
||||
}
|
||||
|
||||
isProcessingQueue = false
|
||||
}
|
||||
|
||||
public func registerCallback(_ cb: @escaping (DialectContext) -> Void) {
|
||||
callbacks.append(cb)
|
||||
}
|
||||
|
||||
public func registerFieldCallback(
|
||||
_ fieldName: String,
|
||||
_ cb: @escaping (DialectContext) -> Void
|
||||
) {
|
||||
callbacks.append({ c in
|
||||
if c.recentField == fieldName {
|
||||
cb(c)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public func registerFunction(_ f: @escaping (DialectContext) -> DialectContext) {
|
||||
functions.append(f)
|
||||
}
|
||||
|
||||
func reportContext() {
|
||||
for cb in callbacks {
|
||||
cb(context)
|
||||
}
|
||||
}
|
||||
|
||||
public func set(
|
||||
_ fieldName: String,
|
||||
_ value: Any
|
||||
) {
|
||||
var c = context
|
||||
c.setField(fieldName, value)
|
||||
c.recentField = fieldName
|
||||
queue.append(c)
|
||||
processQueue()
|
||||
}
|
||||
}
|
||||
|
||||
// Register several oneliner callbacks to a controller
|
||||
func registerOneliners<T>(
|
||||
_ ctrl: DialectController,
|
||||
_ items: [Any]
|
||||
) -> T? {
|
||||
let halfCount = items.count / 2
|
||||
for i in 0..<halfCount {
|
||||
let field = items[i * 2] as! String
|
||||
let callback = items[i * 2 + 1] as! (T) -> Void
|
||||
ctrl.registerFieldCallback(field) { cc in
|
||||
let c = cc as! T
|
||||
callback(c)
|
||||
}
|
||||
}
|
||||
|
||||
// A hack for generics to operate
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 didPrepareMacGL = "didPrepareMacGL"
|
||||
public static let didSetup = "didSetup"
|
||||
public static let pixelSize = "pixelSize"
|
||||
public static let reshapePixelSize = "reshapePixelSize"
|
||||
public static let titleText = "titleText"
|
||||
public static let willDeinit = "willDeinit"
|
||||
public static let willRecreateSurface = "willRecreateSurface"
|
||||
|
||||
}
|
||||
public struct HRBContext: DialectContext {
|
||||
public var titleText = String()
|
||||
public var didLaunch = Bool()
|
||||
public var didSetup = Bool()
|
||||
|
||||
public var recentField = ""
|
||||
|
||||
public func field<T>(_ name: String) -> T {
|
||||
if (name == "titleText") {
|
||||
return titleText 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 == "titleText") {
|
||||
titleText = value as! String
|
||||
}
|
||||
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 didLaunch = Bool()
|
||||
public var didPrepareGL = Bool()
|
||||
public var didPrepareMacGL = Bool()
|
||||
public var didSetup = Bool()
|
||||
public var pixelSize = [Int32]()
|
||||
public var reshapePixelSize = [Int32]()
|
||||
public var willDeinit = Bool()
|
||||
public var willRecreateSurface = 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 == "didPrepareMacGL") {
|
||||
return didPrepareMacGL 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
|
||||
}
|
||||
else if (name == "willRecreateSurface") {
|
||||
return willRecreateSurface 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 == "didPrepareMacGL") {
|
||||
didPrepareMacGL = 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
|
||||
}
|
||||
else if (name == "willRecreateSurface") {
|
||||
willRecreateSurface = value as! Bool
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public func hrbSet(
|
||||
_ key: String,
|
||||
_ value: Any
|
||||
) {
|
||||
HRBComponent.singleton!.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
public func renderSet(
|
||||
_ key: String,
|
||||
_ value: Any
|
||||
) {
|
||||
RenderComponent.singleton!.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
func hrbShouldResetTitleText(_ c: HRBContext) -> HRBContext {
|
||||
var c = c
|
||||
|
||||
/* 1. Upon launch */
|
||||
if
|
||||
c.recentField == F.didLaunch
|
||||
{
|
||||
c.titleText = "Blue"
|
||||
c.recentField = F.titleText
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
func hrbShouldResetDidLaunch(_ c: HRBContext) -> HRBContext {
|
||||
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
|
||||
|
||||
/* 1. Only once during the first setup */
|
||||
if
|
||||
c.recentField == F.didSetup &&
|
||||
!c.didLaunch
|
||||
{
|
||||
c.didLaunch = true
|
||||
c.recentField = F.didLaunch
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
func renderShouldResetDidPrepareGL(_ c: RenderContext) -> RenderContext {
|
||||
var c = c
|
||||
|
||||
/* 1. Upon preparing macOS OpenGL */
|
||||
if
|
||||
c.recentField == F.didPrepareMacGL
|
||||
{
|
||||
c.didPrepareGL = true
|
||||
c.recentField = F.didPrepareGL
|
||||
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 renderShouldResetWillRecreateSurface(_ c: RenderContext) -> RenderContext {
|
||||
var c = c
|
||||
|
||||
/* 1. Upon resize */
|
||||
if
|
||||
c.recentField == F.reshapePixelSize
|
||||
{
|
||||
c.willRecreateSurface = true
|
||||
c.recentField = F.willRecreateSurface
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
func hrbRegisterShoulds(_ ctrl: DialectController) {
|
||||
[
|
||||
hrbShouldResetTitleText,
|
||||
hrbShouldResetDidLaunch,
|
||||
|
||||
].forEach { f in
|
||||
ctrl.registerFunction { c in f(c as! HRBContext) }
|
||||
}
|
||||
}
|
||||
|
||||
func renderRegisterShoulds(_ ctrl: DialectController) {
|
||||
[
|
||||
renderShouldResetDidLaunch,
|
||||
renderShouldResetDidPrepareGL,
|
||||
renderShouldResetPixelSize,
|
||||
renderShouldResetWillRecreateSurface,
|
||||
|
||||
].forEach { f in
|
||||
ctrl.registerFunction { c in f(c as! RenderContext) }
|
||||
}
|
||||
}
|
||||
|
||||
func hrbRegisterEffects(_ ctrl: DialectController) {
|
||||
let _: HRBContext? = registerOneliners(ctrl, [
|
||||
F.titleText, { (c: HRBContext) in HRBVM.shared!.titleText = c.titleText },
|
||||
|
||||
])
|
||||
}
|
||||
|
||||
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.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
||||
F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) },
|
||||
F.willRecreateSurface, { (c: RenderContext) in renderRecreateSurface(RenderVM.shared!) },
|
||||
|
||||
])
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/hrb/hrb.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/hrb/hrbVM.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../components/hrb/mac/view/HRBView.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/other/other.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/raybri/raybri.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/raybri/mac/raybriAux.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/raybri/raybriConst.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/render.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/mac/renderAux.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/renderConst.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/mac/renderConstMac.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/mac/renderEffect.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/renderVM.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../components/render/mac/view/RenderGLView.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../components/render/mac/view/RenderView.swift
|
||||
Reference in new issue
Block a user