remove old libmach approach (see hexops/mach#858)
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
34048c0191
commit
751e6d1fa8
5 changed files with 0 additions and 141 deletions
2
libmach/.gitignore
vendored
2
libmach/.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
||||||
build/
|
|
||||||
test
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
build/libmach.dylib: ../build.zig ../src/*.zig ../src/**/*.zig
|
|
||||||
cd ..; zig build
|
|
||||||
|
|
||||||
test: test.c build/libmach.dylib
|
|
||||||
clang -L./build -lmach -o test test.c
|
|
||||||
|
|
||||||
test_c: test
|
|
||||||
# my best attempt at cross-platform dynamic linking (for now)
|
|
||||||
DYLD_LIBRARY_PATH=./build LD_LIBRARY_OATH=./build ./test
|
|
||||||
|
|
||||||
test_lisp: build/libmach.dylib
|
|
||||||
sbcl --load test.lisp
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
# libmach
|
|
||||||
|
|
||||||
Build the `libmach` dynamic library by running `make` (or running `zig build` in the parent directory).
|
|
||||||
The resulting binary should be located in `libmach/build/`.
|
|
||||||
|
|
||||||
Test the functionality of `libmach` using `make test_c` and `make test_lisp`.
|
|
||||||
These commands use C and Lisp to call into `libmach`, and both should show a blank window for 5 seconds.
|
|
||||||
If you resize the window, it should print the new dimensions to the standard output.
|
|
||||||
|
|
||||||
Note: `make test_lisp` requires a relatively recent version of Steel Bank Common Lisp (`sbcl`) to be installed, plus Quicklisp.
|
|
||||||
|
|
||||||
You can find the Zig source code for `libmach` in `src/platform/libmach.zig`.
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
typedef void resize_callback(void*, uint32_t, uint32_t);
|
|
||||||
|
|
||||||
typedef enum MachStatus {
|
|
||||||
MachStatus_Success = 0x00000000,
|
|
||||||
MachStatus_Error = 0x00000001,
|
|
||||||
MachStatus_Force32 = 0x7FFFFFFF
|
|
||||||
} MachStatus;
|
|
||||||
|
|
||||||
// `libmach` exported API bindings
|
|
||||||
void* mach_core_init(void);
|
|
||||||
void mach_core_deinit(void*);
|
|
||||||
void mach_core_set_should_close(void*);
|
|
||||||
bool mach_core_window_should_close(void*);
|
|
||||||
MachStatus mach_core_update(void*, resize_callback);
|
|
||||||
float mach_core_delta_time(void*);
|
|
||||||
|
|
||||||
void resize_fn(void* core, uint32_t width, uint32_t height) {
|
|
||||||
printf("Resize callback: %u %u\n", width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
static float elapsed = 0;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
void* core = mach_core_init();
|
|
||||||
|
|
||||||
if (core == 0) {
|
|
||||||
printf("Error instantiating mach core\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!mach_core_window_should_close(core)) {
|
|
||||||
if (mach_core_update(core, resize_fn) == MachStatus_Error) {
|
|
||||||
printf("Error updating Mach\n");
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
elapsed += mach_core_delta_time(core);
|
|
||||||
if (elapsed > 5.0) {
|
|
||||||
mach_core_set_should_close(core);
|
|
||||||
}
|
|
||||||
|
|
||||||
// printf("Elapsed: %f\n", elapsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
mach_core_deinit(core);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
;; Tests the behavior of `libmach` using Common Lisp's CFFI
|
|
||||||
;; This Lisp script is basically a one-to-one translation of `test.c`
|
|
||||||
|
|
||||||
(ql:quickload :cffi)
|
|
||||||
|
|
||||||
(defpackage :cffi-user
|
|
||||||
(:use :cl :cffi))
|
|
||||||
|
|
||||||
(in-package :cffi-user)
|
|
||||||
|
|
||||||
(define-foreign-library libmach
|
|
||||||
(t (:default "./build/libmach")))
|
|
||||||
|
|
||||||
(use-foreign-library libmach)
|
|
||||||
|
|
||||||
;; Note: CFFI automatically translates C_style names into lispier kebab-case ones
|
|
||||||
|
|
||||||
(defcenum mach-status
|
|
||||||
(:success 0)
|
|
||||||
(:error 1))
|
|
||||||
|
|
||||||
(defcfun "mach_core_init" :pointer)
|
|
||||||
|
|
||||||
(defcfun "mach_core_update" :int
|
|
||||||
(core :pointer) (resize-fn :pointer))
|
|
||||||
|
|
||||||
(defcfun "mach_core_deinit" :void
|
|
||||||
(core :pointer))
|
|
||||||
|
|
||||||
;; void mach_set_should_close(void*);
|
|
||||||
(defcfun "mach_core_set_should_close" :void
|
|
||||||
(core :pointer))
|
|
||||||
|
|
||||||
;; float mach_delta_time(void*);
|
|
||||||
(defcfun "mach_core_delta_time" :float
|
|
||||||
(core :pointer))
|
|
||||||
|
|
||||||
;; bool mach_window_should_close(void*);
|
|
||||||
(defcfun "mach_core_window_should_close" :bool
|
|
||||||
(core :pointer))
|
|
||||||
|
|
||||||
;; main
|
|
||||||
(defvar *elapsed* 0.0)
|
|
||||||
|
|
||||||
(defcallback resize-fn :void ((core :pointer) (width :unsigned-int) (height :unsigned-int))
|
|
||||||
(format t "Resize Callback: ~S ~S~%" width height))
|
|
||||||
|
|
||||||
(setf core (mach-core-init))
|
|
||||||
|
|
||||||
(when (pointer-eq core (null-pointer))
|
|
||||||
(format t "Failed to initialize mach core~%")
|
|
||||||
(sb-ext:exit))
|
|
||||||
|
|
||||||
(loop while (not (mach-core-window-should-close core))
|
|
||||||
do (progn
|
|
||||||
(when (= (foreign-enum-value 'mach-status :error)
|
|
||||||
(mach-core-update core (callback resize-fn)))
|
|
||||||
(format t "Error updating mach~%")
|
|
||||||
(sb-ext:exit))
|
|
||||||
(when (> (incf *elapsed* (mach-core-delta-time core)) 5.0)
|
|
||||||
(mach-core-set-should-close core))))
|
|
||||||
|
|
||||||
(sb-ext:exit)
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue