GameLib is my library for making games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.0 KiB

(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(import &comptime-only "Macros.cake")
(c-import "stdio.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)
(return false))
(set (deref window-out)
(SDL_CreateWindow "Gamelib"
(unless (deref window-out)
(return false))
;; Must explicitly create the GL context for Ogre
(unless (SDL_GL_CreateContext (deref window-out))
(return false))
(return true))
(defun sdl-shutdown (window (* SDL_Window))
(SDL_DestroyWindow window)
;; 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"
(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
(command-add-string-argument "-LDependencies/SDL/buildSDLBuild/lib")
(command-add-string-argument "-lSDL2")
(command-add-string-argument "-Wl,-rpath,.:../Dependencies/SDL/buildSDLBuild/lib"))
(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)