|
|
@ -3,5 +3,64 @@ |
|
|
|
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime") |
|
|
|
(add-cakelisp-search-directory "src") |
|
|
|
|
|
|
|
(import |
|
|
|
;; GameLib |
|
|
|
"SDL.cake" "DynamicArray.cake") |
|
|
|
|
|
|
|
(define-keybind s-quit-keybind (array SDL_SCANCODE_Q keybind-modifier-flags-ctrl)) |
|
|
|
|
|
|
|
(var s-key-states sdl-key-states (array 0)) |
|
|
|
|
|
|
|
(defmacro preslog (format string &optional &rest arguments any) |
|
|
|
(if arguments |
|
|
|
(scope |
|
|
|
(tokenize-push output |
|
|
|
(fprintf stderr (token-splice format) (token-splice-rest arguments tokens)))) |
|
|
|
(scope |
|
|
|
(tokenize-push output |
|
|
|
(fprintf stderr (token-splice format))))) |
|
|
|
(return true)) |
|
|
|
|
|
|
|
(defun main (&return int) |
|
|
|
(SDL_GL_SetAttribute SDL_GL_CONTEXT_MAJOR_VERSION 4) |
|
|
|
(SDL_GL_SetAttribute SDL_GL_CONTEXT_MINOR_VERSION 6) |
|
|
|
(SDL_SetHint SDL_HINT_RENDER_VSYNC "1") |
|
|
|
(var window (* SDL_Window) null) |
|
|
|
(unless (sdl-initialize-for-2d (addr window) "Presentation" 1920 1080) |
|
|
|
(preslog "Failed to initialize SDL\n") |
|
|
|
(return 1)) |
|
|
|
(defer (sdl-shutdown window)) |
|
|
|
|
|
|
|
;; -1 = pick driver that is compatible with what we want |
|
|
|
(var renderer (* SDL_Renderer) (SDL_CreateRenderer window -1 SDL_RENDERER_ACCELERATED)) |
|
|
|
(unless renderer |
|
|
|
(sdl-print-error) |
|
|
|
(return 1)) |
|
|
|
(defer (SDL_DestroyRenderer renderer)) |
|
|
|
|
|
|
|
;; current-key-states is owned by SDL, but we own last-frame-states |
|
|
|
(defer (dynarray-free (field s-key-states last-frame-states))) |
|
|
|
|
|
|
|
(var exit-reason (* (const char)) null) |
|
|
|
(while true |
|
|
|
(var event SDL_Event) |
|
|
|
(while (SDL_PollEvent (addr event)) |
|
|
|
(when (= (field event type) SDL_QUIT) |
|
|
|
(set exit-reason "Window event"))) |
|
|
|
|
|
|
|
(var num-keys int 0) |
|
|
|
(set (field s-key-states this-frame-states) (SDL_GetKeyboardState (addr num-keys))) |
|
|
|
(when (keybind-tapped (addr s-quit-keybind) (addr s-key-states)) |
|
|
|
(set exit-reason "Quit keybind pressed")) |
|
|
|
|
|
|
|
(SDL_UpdateWindowSurface window) |
|
|
|
|
|
|
|
(dynarray-set-length (field s-key-states last-frame-states) num-keys) |
|
|
|
(memcpy (field s-key-states last-frame-states) (field s-key-states this-frame-states) num-keys) |
|
|
|
|
|
|
|
(when exit-reason |
|
|
|
(break))) |
|
|
|
|
|
|
|
(when exit-reason |
|
|
|
(preslog "Exited reason: %s\n" exit-reason)) |
|
|
|
(return 0)) |
|
|
|