Browse Source

Started using Math.cake

* Convert VocalGame to use Math.cake instead of hand-rolled vectors
* Update cakelisp for HotReloading const variable filtering
* Add "HandmadeMath" build label as a temporary workaround to
unnecessary rebuilding of non-math libs
* Rename vec accessors to be dimension agnostic
* Add more useful vector math functions
pitch-detection
Macoy Madson 12 months ago
parent
commit
ca1a921dd6
  1. 10
      Build_Debug.sh
  2. 2
      Dependencies/cakelisp
  3. 48
      src/Math.cake
  4. 27
      test/src/VocalGame.cake

10
Build_Debug.sh

@ -10,17 +10,19 @@ echo "\n\nOgre\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake test/src/OgreApp.cake || exit $?
echo "\n\nSDL Ogre\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake test/src/SDLOgreApp.cake || exit $?
echo "\n\nAuto Test\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake src/AutoTest.cake src/Math.cake src/SDL.cake src/Tracy.cake || exit $?
echo "\n\nAuto Test (Math only)\n\n"
./Dependencies/cakelisp/bin/cakelisp --execute test/src/Config_Linux.cake src/AutoTest.cake src/Math.cake || exit $?
# echo "\n\nAuto Test\n\n"
# ./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake src/AutoTest.cake src/SDL.cake src/Tracy.cake src/Math.cake || exit $?
echo "\n\nVocal Game (hot reload)\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake test/src/MakeHotReload.cake test/src/VocalGame.cake || exit $?
echo "\n\nLoader\n\n"
./Dependencies/cakelisp/bin/cakelisp --execute test/src/Config_Linux.cake test/src/Loader.cake || exit $?
./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake test/src/Loader.cake || exit $?
echo "\n\nVocal Game (no reload)\n\n"
./Dependencies/cakelisp/bin/cakelisp --execute \
./Dependencies/cakelisp/bin/cakelisp \
test/src/Config_Linux.cake test/src/NoHotReload.cake test/src/VocalGame.cake || exit $?
# TESTING

2
Dependencies/cakelisp

@ -1 +1 @@
Subproject commit d1c3e75359d15dac36a47a25edd5799364165158
Subproject commit 82195c8d442d4697f20d6cc35b896cecae4332f5

48
src/Math.cake

@ -13,6 +13,8 @@
;; TODO: Make this an "infect" to the importer rather than having to be global
(add-c-search-directory-global "Dependencies/Handmade-Math")
;; TODO: Remove once importing Math.cake no longer changes all compile commands
(add-build-config-label "HandmadeMath")
(c-define HANDMADE_MATH_IMPLEMENTATION)
(c-import &with-decls "HandmadeMath.h"
@ -44,24 +46,44 @@
(global-var g-up-axis (const vec3) (array 0.f 1.f 0.f))
(register-c-function-alias vec3-length HMM_LengthVec3) ;; (a vec3 &return float)
(register-c-function-alias vec3-normalize HMM_NormalizeVec3) ;; (a vec3 &return vec3)
(register-c-function-alias vec3-scale HMM_MultiplyVec3f) ;; (a vec3 &return vec3)
(register-c-function-alias vec3-add HMM_AddVec3) ;; (a vec3 &return vec3)
;; (register-c-function-alias vec3-vec3-angle HMM_LengthVec3)
;; (register-c-function-alias vec3-rotate-by-mat4 HMM_LengthVec3)
;; (register-c-function-alias vec3-translate-by-mat4 HMM_LengthVec3)
(register-c-function-alias vec4-create HMM_Vec4) ;; (x float y float z float w float &return vec4)
(defun vec3-scale-add-vec3 (vec-to-scale vec3 scale float vec-to-add vec3 &return vec3)
(return (vec3-add vec-to-add (vec3-scale vec-to-scale scale))))
;; Expand vector to each of its components
;; TODO: Change to any, prevent multiple eval
(defmacro vec3-xyz (vec symbol)
(defmacro vec-xyz (vec symbol)
(tokenize-push output
(field (token-splice vec) X)
(field (token-splice vec) Y)
(field (token-splice vec) Z))
(return true))
(register-c-function-alias vec3-length HMM_LengthVec3) ;; (a vec3 &return float)
(register-c-function-alias vec3-normalize HMM_NormalizeVec3) ;; (a vec3 &return vec3)
;; (register-c-function-alias vec3-vec3-angle HMM_LengthVec3)
(defmacro vec-x (vec any)
(tokenize-push output
(field (token-splice vec) X))
(return true))
;; (register-c-function-alias vec3-rotate-by-mat4 HMM_LengthVec3)
;; (register-c-function-alias vec3-translate-by-mat4 HMM_LengthVec3)
(defmacro vec-y (vec any)
(tokenize-push output
(field (token-splice vec) Y))
(return true))
(register-c-function-alias vec4-create HMM_Vec4) ;; (x float y float z float w float &return vec4)
(defmacro vec-z (vec any)
(tokenize-push output
(field (token-splice vec) Z))
(return true))
;;
;; Matrices
@ -104,8 +126,8 @@
(defun mat4-transform-vec3 (mat mat4 vec vec3 &return vec3)
(var temp-vec4 vec4
(mat4-multiply-vec4 mat
(vec4-create (vec3-xyz vec) 1.f)))
(var converted-vec3 vec3 (array (vec3-xyz temp-vec4)))
(vec4-create (vec-xyz vec) 1.f)))
(var converted-vec3 vec3 (array (vec-xyz temp-vec4)))
(return converted-vec3))
;; TODO: Change to any, prevent multiple eval
@ -230,10 +252,10 @@
g-pi (radians-to-degrees g-pi) (degrees-to-radians 180.f))
(var my-vec vec3 (array 1.f 2.f 3.f))
(printf "%f %f %f\n" (vec3-xyz my-vec))
(printf "%f %f %f\n" (vec-xyz my-vec))
(var vec-a vec3 (array 0.f 1.f 2.f))
(printf "%f %f %f magnitude = %f\n" (vec3-xyz vec-a) (vec3-length vec-a))
(printf "%f %f %f magnitude = %f\n" (vec-xyz vec-a) (vec3-length vec-a))
(printf "\nTranslation matrix:\n")
(var mat-a mat4 (mat4-identity))
@ -251,6 +273,6 @@
(mat4-print transformation-mat)
(var transformed-vec vec3 (mat4-transform-vec3 transformation-mat (array 1.f 0.f 0.f)))
(printf "%f %f %f\n" (vec3-xyz transformed-vec))
(printf "%f %f %f\n" (vec-xyz transformed-vec))
(return 0))))

27
test/src/VocalGame.cake

@ -1,6 +1,6 @@
(import &comptime-only "Options.cake" "Macros.cake" "GamelibMacros.cake")
(import "Ogre.cake" "OgreInitialize.cake" "SDL.cake")
(import "Ogre.cake" "OgreInitialize.cake" "SDL.cake" "Math.cake")
;; TODO: Should this happen automatically, because import automatically adds current working dir?
;; Should it add working dir?
(add-c-search-directory-module ".")
@ -330,9 +330,7 @@
(var exit-reason (* (const char)) null)
(var x float -10.f)
(var y float 0.f)
(var z float 0.f)
(var tracker-position vec3 (array -10.f 0.f 0.f))
(var move-speed float 10.f)
(var counter-num-ticks-per-second (const Uint64) (SDL_GetPerformanceFrequency))
@ -366,15 +364,15 @@
g-input-device)
(return reload-sentinel))
(var delta-position ([] 3 float) (array 0))
(var delta-position vec3 (array 0.f 0.f 0.f))
(when (at SDL_SCANCODE_RIGHT currentKeyStates)
(set (at 0 delta-position) (+ (at 0 delta-position) move-speed)))
(set (vec-x delta-position) (+ (vec-x delta-position) move-speed)))
(when (at SDL_SCANCODE_LEFT currentKeyStates)
(set (at 0 delta-position) (- (at 0 delta-position) move-speed)))
(set (vec-x delta-position) (- (vec-x delta-position) move-speed)))
(when (at SDL_SCANCODE_UP currentKeyStates)
(set (at 1 delta-position) (+ (at 1 delta-position) move-speed)))
(set (vec-y delta-position) (+ (vec-y delta-position) move-speed)))
(when (at SDL_SCANCODE_DOWN currentKeyStates)
(set (at 1 delta-position) (- (at 1 delta-position) move-speed)))
(set (vec-y delta-position) (- (vec-y delta-position) move-speed)))
(var prev-recording-value bool audio-is-recording)
(set audio-is-recording (at SDL_SCANCODE_SPACE currentKeyStates))
@ -482,12 +480,10 @@
(/ (- (at audio-input-read-head audio-input-buffer) 127)
127.f)))
(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) (+ audio-read-head-to-world x)
y
(+ audio-volume-to-world z))
(var audio-pos vec3 (array audio-read-head-to-world 0.f audio-volume-to-world))
(var final-pos vec3 (vec3-scale-add-vec3 delta-position delta-time
(vec3-add tracker-position audio-pos)))
(ogre-node-set-position (addr monkey-node) (vec-xyz final-pos))
(set last-frame-perf-count (SDL_GetPerformanceCounter))
@ -585,6 +581,7 @@
(free (type-cast model-output-dir (* void))))
;; TODO: Convert this to non-sequential to convert in parallel
(scope ;; Textures
(var texture-assets ([] (* (const char))) (array "Monkey_Texture"))
(var i int 0)

Loading…
Cancel
Save