(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
|
|
|
|
(import &comptime-only "Macros.cake")
|
|
|
|
(c-import "stdio.h"
|
|
"SDL.h"
|
|
"SDL_syswm.h")
|
|
|
|
(defun-local print-sdl-error ()
|
|
(printf "SDL_Error: %s\n" (SDL_GetError)))
|
|
|
|
(forward-declare (struct SDL_Window))
|
|
|
|
(defun sdl-initialize (window-out (* (* SDL_Window)) &return bool)
|
|
(when (< (SDL_Init SDL_INIT_VIDEO) 0)
|
|
(print-sdl-error)
|
|
(return false))
|
|
|
|
(set (deref window-out)
|
|
(SDL_CreateWindow "Gamelib"
|
|
SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED 1920 1080
|
|
(bit-or SDL_WINDOW_RESIZABLE SDL_WINDOW_OPENGL)))
|
|
(unless (deref window-out)
|
|
(print-sdl-error)
|
|
(return false))
|
|
;; Must explicitly create the GL context for Ogre
|
|
(unless (SDL_GL_CreateContext (deref window-out))
|
|
(print-sdl-error)
|
|
(return false))
|
|
(return true))
|
|
|
|
(defun sdl-shutdown (window (* SDL_Window))
|
|
(SDL_DestroyWindow window)
|
|
(SDL_Quit))
|
|
|
|
;; TODO: Automatically promote this if no main is defined. Separate target instead?
|
|
(defun sdl-main (&return int)
|
|
(printf "Hello, SDL!\n")
|
|
(var window (* SDL_Window) nullptr)
|
|
(unless (sdl-initialize (addr window)) (return 1))
|
|
|
|
;; (var window-surface (* SDL_Surface) (SDL_GetWindowSurface window))
|
|
|
|
(var exit-reason (* (const char)) nullptr)
|
|
(while (not exit-reason)
|
|
(var event SDL_Event)
|
|
(while (SDL_PollEvent (addr event))
|
|
(when (= (field event type) SDL_QUIT)
|
|
(set exit-reason "Window event")))
|
|
(SDL_UpdateWindowSurface window))
|
|
|
|
(when exit-reason
|
|
(printf "Exiting. Reason: %s\n" exit-reason))
|
|
|
|
(sdl-shutdown window)
|
|
(return 0))
|
|
|
|
;;
|
|
;; Building
|
|
;;
|
|
|
|
(set-module-option build-time-compiler "/usr/bin/clang++")
|
|
;; Include cakelisp source for DynamicLoader.hpp
|
|
(set-module-option build-time-compile-arguments
|
|
"-Wall" "-Wextra" "-Wno-unused-parameter"
|
|
"-g" "-c" 'source-input "-o" 'object-output "-fPIC"
|
|
"-IDependencies/SDL/buildSDLBuild/include/SDL2")
|
|
|
|
(defun-comptime sdl-link-hook (manager (& ModuleManager)
|
|
linkCommand (& ProcessCommand)
|
|
linkTimeInputs (* ProcessCommandInput) numLinkTimeInputs int
|
|
&return bool)
|
|
;; TODO: Expose this option somehow?
|
|
(var is-debug-build bool true)
|
|
|
|
(printf "SDL: Adding %s link arguments\n" (? is-debug-build "debug" "release"))
|
|
|
|
(if is-debug-build
|
|
;; TODO: Actually add debug build
|
|
(block
|
|
(command-add-string-argument "-LDependencies/SDL/buildSDLBuild/lib")
|
|
(command-add-string-argument "-lSDL2")
|
|
(command-add-string-argument "-Wl,-rpath,.:../Dependencies/SDL/buildSDLBuild/lib"))
|
|
(block
|
|
(command-add-string-argument "-LDependencies/sdl-next/build/Release/lib")
|
|
(command-add-string-argument "-lSDL2")
|
|
(command-add-string-argument "-Wl,-rpath,.:../Dependencies/SDL/buildSDLBuild/lib")))
|
|
|
|
(return true))
|
|
(add-compile-time-hook pre-link sdl-link-hook)
|