From 3a5f0b977dd6ef7581b200515275cc67d8378138 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 2 Dec 2018 18:34:10 -0500 Subject: math: grid: A couple more optimizations. * chickadee/math/grid.scm (make-grid): Set a high minimum bucket size to avoid rehashing. (grid-move): Use memoized inexact->exact procedure. Fix return value of check procedure being ignored. --- chickadee/math/grid.scm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/chickadee/math/grid.scm b/chickadee/math/grid.scm index 58232fc..9982f90 100644 --- a/chickadee/math/grid.scm +++ b/chickadee/math/grid.scm @@ -114,7 +114,7 @@ needed to make the rectangles no longer overlap." (define* (make-grid #:optional (cell-size 64.0)) "Create new grid partitioned by CELL-SIZE." (%make-grid (f32vector cell-size) - (make-hash-table) + (make-hash-table 1000) (make-hash-table) (make-rect 0.0 0.0 0.0 0.0) (make-array-list) @@ -238,7 +238,7 @@ POSITION may be modified to resolve the colliding objects." (collisions (grid-buffer grid)) (visited (grid-visited grid))) (define (to-cell n) - (inexact->exact (floor (/ n cell-size)))) + (inexact->exact* (floor (/ n cell-size)))) (define (collision? rect1 rect2 goal) (let ((goal-x (vec2-x goal)) (goal-y (vec2-y goal))) @@ -321,8 +321,7 @@ POSITION may be modified to resolve the colliding objects." (when (<= cx maxx) (let ((cell (row-column-ref row cx))) (hash-for-each (lambda (other unused) - (check other (grid-rect-ref grid other)) - #f) + (check other (grid-rect-ref grid other))) (cell-items cell))) (xloop (+ cx 1))))) (yloop (+ cy 1)))) -- cgit v1.2.3