|
|
@ -553,7 +553,7 @@ |
|
|
|
(unless texture (sdl-print-error)) |
|
|
|
(return texture)) |
|
|
|
|
|
|
|
(defun-local print-time-delta (start-num-perf-ticks Uint64 label (* (const char))) |
|
|
|
(defun-local sdl-print-time-delta (start-num-perf-ticks Uint64 label (* (const char))) |
|
|
|
(var performance-num-ticks-per-second (const Uint64) (SDL_GetPerformanceFrequency)) |
|
|
|
|
|
|
|
(var current-counter-ticks Uint64 (SDL_GetPerformanceCounter)) |
|
|
@ -563,6 +563,18 @@ |
|
|
|
|
|
|
|
(printf "%s at %f seconds\n" label delta-time)) |
|
|
|
|
|
|
|
;; Factor 0 to 1 |
|
|
|
(defun-local vec2-interpolate (factor float from vec2 to vec2 &return vec2) |
|
|
|
(return (array |
|
|
|
(interpolate-range (vec-x from) (vec-x to) |
|
|
|
0.f 1.f factor) |
|
|
|
(interpolate-range (vec-y from) (vec-y to) |
|
|
|
0.f 1.f factor)))) |
|
|
|
|
|
|
|
(defun-local vec2-is-zero (vec vec2 &return bool) |
|
|
|
(return (and (= 0.f (vec-x vec)) |
|
|
|
(= 0.f (vec-y vec))))) |
|
|
|
|
|
|
|
;; |
|
|
|
;; Main |
|
|
|
;; |
|
|
@ -629,11 +641,11 @@ Rush Hour database from Michael Fogleman.\n\n") |
|
|
|
(SDL_RenderPresent renderer) |
|
|
|
(SDL_DestroyTexture loading-texture)) |
|
|
|
|
|
|
|
(print-time-delta start-load-ticks "Loading screen displayed") |
|
|
|
(sdl-print-time-delta start-load-ticks "Loading screen displayed") |
|
|
|
|
|
|
|
;; (unless (bunzip-decompress puzzle-database-filename) |
|
|
|
;; (return 1)) |
|
|
|
;; (print-time-delta start-load-ticks "Database loaded") |
|
|
|
;; (sdl-print-time-delta start-load-ticks "Database loaded") |
|
|
|
|
|
|
|
(var background-texture (* SDL_Texture) (sdl-texture-from-bmp (in-data-dir "Board.bmp") |
|
|
|
renderer)) |
|
|
@ -680,14 +692,15 @@ Rush Hour database from Michael Fogleman.\n\n") |
|
|
|
(in-data-dir "Undo_Button.bmp") renderer)) |
|
|
|
(unless undo-button-texture (return 1)) |
|
|
|
|
|
|
|
(print-time-delta start-load-ticks "Textures loaded") |
|
|
|
(sdl-print-time-delta start-load-ticks "Textures loaded") |
|
|
|
|
|
|
|
;; (game-board-load "60 IBBxooIooLDDJAALooJoKEEMFFKooMGGHHHM 2332") |
|
|
|
(game-board-load "07 BBBoooooFxooAAFGooEooGooEDDDoooooooo 478") |
|
|
|
;; |
|
|
|
;; Game loop |
|
|
|
;; |
|
|
|
(var last-frame-perf-count Uint64 (* 0.016f performance-num-ticks-per-second)) |
|
|
|
(var delta-time float 0.016f) ;; Made up but reasonable frame time |
|
|
|
(var last-frame-perf-count Uint64 (* delta-time performance-num-ticks-per-second)) |
|
|
|
(var recent-n-perf-counts ([] 10 Uint64) (array 0)) |
|
|
|
(var recent-n-perf-counts-write-head int 0) |
|
|
|
|
|
|
@ -697,7 +710,7 @@ Rush Hour database from Michael Fogleman.\n\n") |
|
|
|
|
|
|
|
(var in-state input-state (array 0)) |
|
|
|
|
|
|
|
(print-time-delta start-load-ticks "Game loop starting") |
|
|
|
(sdl-print-time-delta start-load-ticks "Game loop starting") |
|
|
|
|
|
|
|
(var exit-reason (* (const char)) null) |
|
|
|
(while (not exit-reason) |
|
|
@ -787,6 +800,13 @@ Rush Hour database from Michael Fogleman.\n\n") |
|
|
|
(set exit-reason "Piece movement constraints failed to keep piece on board") |
|
|
|
(break)) |
|
|
|
(set (path selected-piece > grid-position) new-position) |
|
|
|
;; Remove the moving position difference from changing grid position, b/c moving is relative |
|
|
|
(set (vec-x (path selected-piece > moving-position)) |
|
|
|
(- (vec-x (path selected-piece > moving-position)) |
|
|
|
(* g-game-board-cell-size-px (vec-x delta-grid-movement)))) |
|
|
|
(set (vec-y (path selected-piece > moving-position)) |
|
|
|
(- (vec-y (path selected-piece > moving-position)) |
|
|
|
(* g-game-board-cell-size-px (vec-y delta-grid-movement)))) |
|
|
|
(game-board-sync-occupied-state)) |
|
|
|
(set selected-piece nullptr))) |
|
|
|
|
|
|
@ -846,7 +866,16 @@ Rush Hour database from Michael Fogleman.\n\n") |
|
|
|
(set (path piece > moving-position) |
|
|
|
(constrain-piece-moving-position piece mouse-delta-pos))) |
|
|
|
;; Reset positions on release |
|
|
|
(set (path piece > moving-position) (array 0))) |
|
|
|
(when (not (vec2-is-zero (path piece > moving-position))) |
|
|
|
(var ease-position vec2 (vec2-interpolate |
|
|
|
(/ delta-time 0.1f) |
|
|
|
(path piece > moving-position) (array 0.f 0.f))) |
|
|
|
;; Make sure it's not always approaching smaller and smaller values |
|
|
|
(when (< (fabs (vec-x ease-position)) 0.01f) |
|
|
|
(set (vec-x ease-position) 0.f)) |
|
|
|
(when (< (fabs (vec-y ease-position)) 0.01f) |
|
|
|
(set (vec-y ease-position) 0.f)) |
|
|
|
(set (path piece > moving-position) ease-position))) |
|
|
|
|
|
|
|
(var piece-position vec2 (game-piece-position-to-screen-position piece)) |
|
|
|
(var piece-size vec2 (game-piece-get-screen-size piece)) |
|
|
@ -886,8 +915,8 @@ Rush Hour database from Michael Fogleman.\n\n") |
|
|
|
(when (>= recent-n-perf-counts-write-head (array-size recent-n-perf-counts)) |
|
|
|
(set recent-n-perf-counts-write-head 0)) |
|
|
|
|
|
|
|
(var delta-time float (/ frame-diff-ticks |
|
|
|
(type-cast performance-num-ticks-per-second float))) |
|
|
|
(set delta-time (/ frame-diff-ticks |
|
|
|
(type-cast performance-num-ticks-per-second float))) |
|
|
|
;; (printf "%lu %f %fhz\n" frame-diff-ticks delta-time (/ 1.f delta-time)) |
|
|
|
(SDL_Delay todo-arbitrary-delay-ms)) |
|
|
|
|
|
|
@ -917,6 +946,8 @@ Rush Hour database from Michael Fogleman.\n\n") |
|
|
|
(set win-texture null) |
|
|
|
(SDL_DestroyTexture theme-button-texture) |
|
|
|
(set theme-button-texture null) |
|
|
|
(SDL_DestroyTexture undo-button-texture) |
|
|
|
(set undo-button-texture null) |
|
|
|
|
|
|
|
(SDL_DestroyRenderer renderer) |
|
|
|
|
|
|
|