Browse Source

Use timer for movement; fix build opts

* Rename to SDLOgreApp so I stop getting confused
* Build options no longer copy-pasted. I have macros for that!
SDLAttempt
Macoy Madson 1 year ago
parent
commit
1e2c00b704
  1. 2
      .gitignore
  2. 3
      Build_Debug.sh
  3. 19
      src/SDL.cake
  4. 35
      test/SDLOgreApp.cake

2
.gitignore

@ -48,4 +48,4 @@ Dependencies/SDL/
test/100000000PixelShader_ps.glsl
test/100000000VertexShader_vs.glsl
test/ogreSDLApp
test/SDLOgreApp

3
Build_Debug.sh

@ -5,4 +5,5 @@
# ./Dependencies/cakelisp/bin/cakelisp --verbose-processes test/OgreApp.cake
# ./Dependencies/cakelisp/bin/cakelisp --verbose-processes src/SDL.cake
./Dependencies/cakelisp/bin/cakelisp --verbose-compile-time-build-objects test/SDLOgreApp.cake && cd test && ./ogreSDLApp
./Dependencies/cakelisp/bin/cakelisp --verbose-compile-time-build-objects test/SDLOgreApp.cake \
&& echo "\n\nRUNTIME\n" && cd test && ./SDLOgreApp

19
src/SDL.cake

@ -65,12 +65,18 @@
;; 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")
;; For now, an easy way to build files which include SDL headers
(defmacro module-use-sdl-build-options ()
(tokenize-push output
(set-module-option build-time-compiler "/usr/bin/clang++")
;; Include cakelisp source for DynamicLoader.hpp
(set-module-option build-time-compile-arguments
"-Werror" "-Wall" "-Wextra" "-Wno-unused-parameter" "-Wno-unused-variable"
"-g" "-c" 'source-input "-o" 'object-output "-fPIC"
"-IDependencies/SDL/buildSDLBuild/include/SDL2"))
(return true))
(module-use-sdl-build-options)
(defun-comptime sdl-link-hook (manager (& ModuleManager)
linkCommand (& ProcessCommand)
@ -93,4 +99,5 @@
(command-add-string-argument "-Wl,-rpath,.:../Dependencies/SDL/buildSDLBuild/lib")))
(return true))
(add-compile-time-hook pre-link sdl-link-hook)

35
test/SDLOgreApp.cake

@ -21,7 +21,7 @@
(var x float 0.f)
(var y float 0.f)
(var z float 0.f)
(var move-speed float 0.3f)
(var move-speed float 10.f)
(var counter-num-ticks-per-second (const Uint64) (SDL_GetPerformanceFrequency))
(var last-frame-perf-count Uint64 (* 0.016f counter-num-ticks-per-second))
@ -37,22 +37,27 @@
(var currentKeyStates (* (const Uint8)) (SDL_GetKeyboardState nullptr))
(when (at SDL_SCANCODE_ESCAPE currentKeyStates)
(set exit-reason "Escape pressed"))
(var delta-position ([] 3 float) (array 0))
(when (at SDL_SCANCODE_RIGHT currentKeyStates)
(set x (+ x move-speed)))
(set (at 0 delta-position) (+ (at 0 delta-position) move-speed)))
(when (at SDL_SCANCODE_LEFT currentKeyStates)
(set x (- x move-speed)))
(set (at 0 delta-position) (- (at 0 delta-position) move-speed)))
(when (at SDL_SCANCODE_UP currentKeyStates)
(set y (+ y move-speed)))
(set (at 1 delta-position) (+ (at 1 delta-position) move-speed)))
(when (at SDL_SCANCODE_DOWN currentKeyStates)
(set y (- y move-speed)))
(ogre-node-set-position (addr monkey-node) x y z)
(set (at 1 delta-position) (- (at 1 delta-position) move-speed)))
(var current-counter-ticks Uint64 (SDL_GetPerformanceCounter))
(var frame-diff-ticks Uint64 (- current-counter-ticks last-frame-perf-count))
(printf "%lu %f\n" frame-diff-ticks
(/ frame-diff-ticks
(type-cast counter-num-ticks-per-second float)))
(var delta-time float (/ frame-diff-ticks
(type-cast counter-num-ticks-per-second float)))
(printf "%lu %f\n" frame-diff-ticks delta-time)
(set x (+ x (* delta-time (at 0 delta-position))))
(set y (+ y (* delta-time (at 1 delta-position))))
(set z (+ z (* delta-time (at 2 delta-position))))
(ogre-node-set-position (addr monkey-node) x y z)
(set last-frame-perf-count (SDL_GetPerformanceCounter))
@ -61,16 +66,12 @@
(break)))
(ogre-shutdown)
(sdl-shutdown window)
(when exit-reason
(printf "Exit reason: %s\n" exit-reason))
(return 0))
(set-cakelisp-option executable-output "test/ogreSDLApp")
(set-cakelisp-option executable-output "test/SDLOgreApp")
;; TODO: Somehow inherit this from SDL.cake?
(set-module-option build-time-compiler "/usr/bin/clang++")
;; Include cakelisp source for DynamicLoader.hpp
(set-module-option build-time-compile-arguments
"-Werror" "-Wall" "-Wextra" "-Wno-unused-parameter"
"-g" "-c" 'source-input "-o" 'object-output "-fPIC"
"-IDependencies/SDL/buildSDLBuild/include/SDL2")
(module-use-sdl-build-options)

Loading…
Cancel
Save