aboutsummaryrefslogtreecommitdiffstats
path: root/minilibx_beta/mlx_init.swift
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--minilibx_beta/mlx_init.swift100
-rw-r--r--minilibx_beta/mlx_init.swiftdocbin376 -> 0 bytes
-rw-r--r--minilibx_beta/mlx_init.swiftmodulebin20128 -> 0 bytes
3 files changed, 0 insertions, 100 deletions
diff --git a/minilibx_beta/mlx_init.swift b/minilibx_beta/mlx_init.swift
deleted file mode 100644
index de6edf2..0000000
--- a/minilibx_beta/mlx_init.swift
+++ /dev/null
@@ -1,100 +0,0 @@
-
-import Cocoa
-import Metal
-import mlx_window
-import mlx_image
-
-
-func _mlx_bridge<T : AnyObject>(obj : T) -> UnsafeMutableRawPointer? {
- return UnsafeMutableRawPointer(Unmanaged.passUnretained(obj).toOpaque())
-}
-
-func _mlx_bridge<T : AnyObject>(ptr : UnsafeRawPointer) -> T {
- return Unmanaged<T>.fromOpaque(ptr).takeUnretainedValue()
-}
-
-
-
-public class MlxMain {
-
- public var winList = [MlxWin]()
- public var imgList = [MlxImg]()
- var myMlxApp:NSApplication?
- public var device:MTLDevice!
- var loopHook:UnsafeMutableRawPointer?
- var loopParam:UnsafeMutableRawPointer
- var loopHookTimer:CFRunLoopTimer?
- public var inLoop = false
-
- public init(_ flag:Int = 0)
- {
- /// make app with top menubar
- myMlxApp = NSApplication.shared
- if (flag == 1)
- {
- NSApp.setActivationPolicy(NSApplication.ActivationPolicy.prohibited) /// for non clickable win, no top menu
- }
- else
- {
- NSApp.setActivationPolicy(NSApplication.ActivationPolicy.regular)
- }
-
- device = MTLCreateSystemDefaultDevice()!
- loopParam = UnsafeMutableRawPointer(&inLoop) /// dummy addr init
-
- /// Add observer anyway to flush pixels every loop. If loop_hook exists, call it.
- var ocontext = CFRunLoopObserverContext(version:0, info:_mlx_bridge(obj:self), retain:nil, release:nil, copyDescription:nil)
- let observer = CFRunLoopObserverCreate(kCFAllocatorDefault, CFRunLoopActivity.beforeWaiting.rawValue, true, 0, createOCallback(), &ocontext)
- CFRunLoopAddObserver(CFRunLoopGetMain(), observer, CFRunLoopMode.commonModes)
-
- }
-
- public func addWinToList(_ win:MlxWin)
- { winList.append(win) }
- public func addImgToList(_ img:MlxImg)
- { imgList.append(img) }
-
-
- func doCallLoopHook()
- {
-/// if (loopHook != nil)
-/// {
- _ = (unsafeBitCast(loopHook!,to:(@convention(c)(UnsafeRawPointer)->Void).self))(loopParam)
-/// }
- }
-
- func createOCallback() -> CFRunLoopObserverCallBack
- {
- return { (cfRunloopObserver, cfrunloopactivity, info) -> Void in
- let mlx:MlxMain = _mlx_bridge(ptr:info!)
- mlx.winList.forEach { $0.flushImages() }
-/// mlx.doCallLoopHook()
- }
- }
-
- func createTCallback() -> CFRunLoopTimerCallBack
- {
- return { (cfRunloopTimer, info) -> Void in
- let mlx:MlxMain = _mlx_bridge(ptr:info!)
- mlx.doCallLoopHook()
- }
- }
-
- public func addLoopHook(_ f:UnsafeMutableRawPointer?, _ p:UnsafeMutableRawPointer)
- {
- var tcontext = CFRunLoopTimerContext(version:0, info:_mlx_bridge(obj:self), retain:nil, release:nil, copyDescription:nil)
- if (loopHook != nil)
- {
- CFRunLoopTimerInvalidate(loopHookTimer)
- }
-
- loopHook = f
- loopParam = p
- if (loopHook != nil)
- {
- loopHookTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, 0.0, 0.0001, 0, 0, createTCallback(), &tcontext)
- CFRunLoopAddTimer(CFRunLoopGetMain(), loopHookTimer, CFRunLoopMode.commonModes)
- }
- }
-
-}
diff --git a/minilibx_beta/mlx_init.swiftdoc b/minilibx_beta/mlx_init.swiftdoc
deleted file mode 100644
index 922e521..0000000
--- a/minilibx_beta/mlx_init.swiftdoc
+++ /dev/null
Binary files differ
diff --git a/minilibx_beta/mlx_init.swiftmodule b/minilibx_beta/mlx_init.swiftmodule
deleted file mode 100644
index 9565cfc..0000000
--- a/minilibx_beta/mlx_init.swiftmodule
+++ /dev/null
Binary files differ