summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-12-02 18:34:10 -0500
committerDavid Thompson <dthompson2@worcester.edu>2018-12-02 18:35:55 -0500
commit3a5f0b977dd6ef7581b200515275cc67d8378138 (patch)
tree517f959270a95f051fd9771b326d71ce876bcc5c
parenta15c8c5be1807d82a9c172420321cc0b9a6125d6 (diff)
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.
-rw-r--r--chickadee/math/grid.scm7
1 files 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))))