|
|
@ -0,0 +1,247 @@ |
|
|
|
(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src") |
|
|
|
(set-cakelisp-option cakelisp-lib-dir "Dependencies/cakelisp/bin") |
|
|
|
(add-cakelisp-search-directory "Dependencies/gamelib/src") |
|
|
|
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime") |
|
|
|
(add-cakelisp-search-directory "src") |
|
|
|
|
|
|
|
(import |
|
|
|
;; Cakelisp |
|
|
|
"CHelpers.cake" |
|
|
|
;; GameLib |
|
|
|
"Introspection.cake" "SDL.cake" "DynamicArray.cake" "Dictionary.cake" "DataBundle.cake" |
|
|
|
"SDLFontAtlas.cake" "FreeType.cake") |
|
|
|
|
|
|
|
(c-import "<stdio.h>" |
|
|
|
&with-decls "<stdint.h>") |
|
|
|
|
|
|
|
(bundle-file s-start-ubuntu-regular-font s-end-ubuntu-regular-font |
|
|
|
(unsigned char) "data/Fonts/Ubuntu-R.ttf") |
|
|
|
|
|
|
|
(bundle-file s-start-ubuntu-mono-font s-end-ubuntu-mono-font |
|
|
|
(unsigned char) "data/Fonts/UbuntuMono-R.ttf") |
|
|
|
|
|
|
|
(define-keybind s-quit-keybind (array SDL_SCANCODE_Q keybind-modifier-flags-ctrl)) |
|
|
|
(define-keybind s-next-slide-keybind (array SDL_SCANCODE_RIGHT) |
|
|
|
(array SDL_SCANCODE_DOWN) |
|
|
|
(array SDL_SCANCODE_SPACE) |
|
|
|
(array SDL_SCANCODE_RETURN) |
|
|
|
(array SDL_SCANCODE_PAGEDOWN)) |
|
|
|
(define-keybind s-previous-slide-keybind (array SDL_SCANCODE_LEFT) |
|
|
|
(array SDL_SCANCODE_UP) |
|
|
|
(array SDL_SCANCODE_BACKSPACE) |
|
|
|
(array SDL_SCANCODE_PAGEUP)) |
|
|
|
|
|
|
|
(define-keybind s-toggle-fullscreen-keybind (array SDL_SCANCODE_F11)) |
|
|
|
|
|
|
|
(var s-key-states sdl-key-states (array 0)) |
|
|
|
|
|
|
|
(defmacro vpslog (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)) |
|
|
|
|
|
|
|
(comptime-cond |
|
|
|
('Windows |
|
|
|
(c-import "<windows.h>") |
|
|
|
(add-static-link-objects "User32.lib"))) |
|
|
|
|
|
|
|
(defun main (&return int) |
|
|
|
(comptime-cond |
|
|
|
('Windows |
|
|
|
(SetProcessDpiAwarenessContext DPI_AWARENESS_CONTEXT_SYSTEM_AWARE))) |
|
|
|
(data-bundle-load-all-resources) |
|
|
|
|
|
|
|
(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 (addr SDL_Window) null) |
|
|
|
(unless (sdl-initialize-for-2d (addr window) "Presentation" 1920 1080) |
|
|
|
(vpslog "Failed to initialize SDL\n") |
|
|
|
(return 1)) |
|
|
|
(defer (sdl-shutdown window)) |
|
|
|
|
|
|
|
;; -1 = pick driver that is compatible with what we want |
|
|
|
(var renderer (addr SDL_Renderer) (SDL_CreateRenderer window -1 SDL_RENDERER_ACCELERATED)) |
|
|
|
(unless renderer |
|
|
|
(sdl-print-error) |
|
|
|
(return 1)) |
|
|
|
(defer (SDL_DestroyRenderer renderer)) |
|
|
|
|
|
|
|
;; |
|
|
|
;; Fonts |
|
|
|
;; |
|
|
|
|
|
|
|
(var device-dpi (unsigned char) 144) |
|
|
|
;; 1 point = 1/72". Accurate if device-dpi is properly set |
|
|
|
|
|
|
|
(defstruct font-atlas-texture |
|
|
|
atlas font-atlas |
|
|
|
texture (addr SDL_Texture) |
|
|
|
|
|
|
|
;; Only needed before it is built |
|
|
|
start-file-data (addr (unsigned char)) |
|
|
|
end-file-data (addr (unsigned char)) |
|
|
|
font-size-points (unsigned char)) |
|
|
|
(var font-atlases (array font-atlas-texture) |
|
|
|
(array |
|
|
|
(array ;; Heading font, 1080p |
|
|
|
(array 0) null |
|
|
|
s-start-ubuntu-regular-font s-end-ubuntu-regular-font |
|
|
|
38) |
|
|
|
(array ;; Body font, 1080p |
|
|
|
(array 0) null |
|
|
|
s-start-ubuntu-regular-font s-end-ubuntu-regular-font |
|
|
|
20) |
|
|
|
(array ;; Body code font, 1080p |
|
|
|
(array 0) null |
|
|
|
s-start-ubuntu-mono-font s-end-ubuntu-mono-font |
|
|
|
20) |
|
|
|
|
|
|
|
(array ;; Heading font, 4k |
|
|
|
(array 0) null |
|
|
|
s-start-ubuntu-regular-font s-end-ubuntu-regular-font |
|
|
|
58) |
|
|
|
(array ;; Body font, 4k |
|
|
|
(array 0) null |
|
|
|
s-start-ubuntu-regular-font s-end-ubuntu-regular-font |
|
|
|
34) |
|
|
|
(array ;; Body code font, 4k |
|
|
|
(array 0) null |
|
|
|
s-start-ubuntu-mono-font s-end-ubuntu-mono-font |
|
|
|
34))) |
|
|
|
(var heading-font-index-1080p (const int) 0) |
|
|
|
(var body-font-index-1080p (const int) 1) |
|
|
|
(var body-code-font-index-1080p (const int) 2) |
|
|
|
(var heading-font-index-4k (const int) 3) |
|
|
|
(var body-font-index-4k (const int) 4) |
|
|
|
(var body-code-font-index-4k (const int) 5) |
|
|
|
(var heading-font-index int heading-font-index-1080p) |
|
|
|
(var body-font-index int body-font-index-1080p) |
|
|
|
(var body-code-font-index int body-code-font-index-1080p) |
|
|
|
|
|
|
|
(defer |
|
|
|
(each-item-addr-in-array font-atlases i font (addr font-atlas-texture) |
|
|
|
(free-font-atlas (addr (path font > atlas))) |
|
|
|
(when (path font > texture) |
|
|
|
(SDL_DestroyTexture (path font > texture))))) |
|
|
|
|
|
|
|
(each-item-addr-in-array font-atlases i font (addr font-atlas-texture) |
|
|
|
(unless (make-font-atlas-and-texture renderer |
|
|
|
(addr (path font > atlas)) |
|
|
|
(addr (path font > texture)) |
|
|
|
(path font > start-file-data) |
|
|
|
(- (path font > end-file-data) (path font > start-file-data)) |
|
|
|
device-dpi |
|
|
|
(path font > font-size-points)) |
|
|
|
(return 1))) |
|
|
|
|
|
|
|
|
|
|
|
;; current-key-states is owned by SDL, but we own last-frame-states |
|
|
|
(defer (dynarray-free (field s-key-states last-frame-states))) |
|
|
|
|
|
|
|
(var enable-fullscreen bool false) |
|
|
|
|
|
|
|
(var exit-reason (addr (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")) |
|
|
|
|
|
|
|
(when (keybind-tapped (addr s-toggle-fullscreen-keybind) (addr s-key-states)) |
|
|
|
(set enable-fullscreen (not enable-fullscreen)) |
|
|
|
(if enable-fullscreen |
|
|
|
(SDL_SetWindowFullscreen window SDL_WINDOW_FULLSCREEN_DESKTOP) |
|
|
|
(SDL_SetWindowFullscreen window 0))) |
|
|
|
|
|
|
|
(var true-window-width int 0) |
|
|
|
(var true-window-height int 0) |
|
|
|
(SDL_GetWindowSize window (addr true-window-width) (addr true-window-height)) |
|
|
|
|
|
|
|
;; (if (> true-window-height 1440) |
|
|
|
;; (scope |
|
|
|
;; (unless upscale-to-4k |
|
|
|
;; (vpslog "Now upscaling 2x\n")) |
|
|
|
;; (set heading-font-index heading-font-index-4k) |
|
|
|
;; (set body-font-index body-font-index-4k) |
|
|
|
;; (set body-code-font-index body-code-font-index-4k) |
|
|
|
;; (set upscale-to-4k true)) |
|
|
|
;; (scope |
|
|
|
;; (when upscale-to-4k |
|
|
|
;; (vpslog "No longer upscaling\n")) |
|
|
|
;; (set heading-font-index heading-font-index-1080p) |
|
|
|
;; (set body-font-index body-font-index-1080p) |
|
|
|
;; (set body-code-font-index body-code-font-index-1080p) |
|
|
|
;; (set upscale-to-4k false))) |
|
|
|
|
|
|
|
;; (var virtual-window-width int true-window-width) |
|
|
|
;; (var virtual-window-height int true-window-height) |
|
|
|
|
|
|
|
;; ;; We always master to 1080p in "game space". Text is all true window relative |
|
|
|
;; (when upscale-to-4k |
|
|
|
;; (set virtual-window-width 1920) |
|
|
|
;; (set virtual-window-height 1080)) |
|
|
|
|
|
|
|
(SDL_SetRenderDrawColor renderer 11 19 40 255) |
|
|
|
(SDL_RenderClear renderer) |
|
|
|
|
|
|
|
(render-string |
|
|
|
renderer (addr (field (at heading-font-index font-atlases) atlas)) |
|
|
|
(field (at heading-font-index font-atlases) texture) |
|
|
|
(/ true-window-width 4.5f) (/ true-window-height 8) |
|
|
|
"This is a test string") |
|
|
|
|
|
|
|
|
|
|
|
;; (when s-enable-debug-overlay |
|
|
|
;; (var buffer (array 256 char) (array 0)) |
|
|
|
;; (var mouse-x int 0) |
|
|
|
;; (var mouse-y int 0) |
|
|
|
;; (SDL_GetMouseState (addr mouse-x) (addr mouse-y)) |
|
|
|
;; (snprintf buffer (- (array-size buffer) 1) "Mouse: %4d %4d Percent of window: %.2f %.2f Wizard relative: %4d %4d" |
|
|
|
;; mouse-x mouse-y |
|
|
|
;; (/ mouse-x (type-cast true-window-width float)) (/ mouse-y (type-cast true-window-height float)) |
|
|
|
;; (- mouse-x (field g-wizard-hero x)) (- mouse-y (field g-wizard-hero y))) |
|
|
|
;; (render-string |
|
|
|
;; renderer (addr (field (at body-code-font-index font-atlases) atlas)) |
|
|
|
;; (field (at body-code-font-index font-atlases) texture) |
|
|
|
;; 10 (- true-window-height 20) |
|
|
|
;; buffer)) |
|
|
|
;; ;; #"# |
|
|
|
;; ;; result= FT_Set_Char_Size(typeface, 0, (16 * 64), 300, 300); |
|
|
|
;; ;; if (!((result== FT_Err_Ok))) |
|
|
|
;; ;; { |
|
|
|
;; ;; fprintf(stderr, "error: encountered error %d while %s\n", result, "setting character size"); |
|
|
|
;; ;; FT_Done_Face(typeface); |
|
|
|
;; ;; FT_Done_FreeType(freetypeLibrary); |
|
|
|
;; ;; return 1; |
|
|
|
;; ;; }#"#) |
|
|
|
|
|
|
|
(SDL_RenderPresent renderer) |
|
|
|
(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 |
|
|
|
(vpslog "Exited reason: %s\n" exit-reason)) |
|
|
|
(return 0)) |
|
|
|
|
|
|
|
(comptime-cond |
|
|
|
('Windows |
|
|
|
(add-c-build-dependency "VectorPuppetShowWinMain.cpp") |
|
|
|
(set-cakelisp-option executable-output "VectorPuppetShow.exe")) |
|
|
|
(true |
|
|
|
(set-cakelisp-option executable-output "vector-puppet-show"))) |