-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed memory leak + related simplifications
Removed grid-based neighbor updating system. Eliminated use of reducers.
- Loading branch information
Showing
16 changed files
with
102 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>pucks</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>ccw.builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>ccw.leiningen.builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>ccw.leiningen.nature</nature> | ||
<nature>ccw.nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,33 @@ | ||
(ns pucks.neighbors | ||
(:use pucks.globals pucks.util pucks.vec2D)) | ||
|
||
(defn wrap-grid-coordinate | ||
[c] | ||
(if (< c 0) | ||
(dec (:grid-steps @parameters)) | ||
(if (>= c (:grid-steps @parameters)) | ||
0 | ||
c))) | ||
|
||
(defn wrap-gridxy | ||
[xy] | ||
(vec (map wrap-grid-coordinate xy))) | ||
|
||
(defn xy->gridxy | ||
[xy] | ||
(wrap-gridxy (map (fn [c] (int (/ c (:grid-step-size @parameters)))) xy))) | ||
|
||
(defn strip-neighbors | ||
[obj] | ||
(-> obj | ||
(dissoc :neighbors) | ||
(dissoc :sensed) | ||
(dissoc :overlaps))) | ||
|
||
(defn make-world-grid | ||
[objs] | ||
(let [grid-steps (max 1 (int (/ (:screen-size @parameters) | ||
(:neighborhood-size @parameters))))] | ||
(swap! parameters | ||
(fn [params] | ||
(-> params | ||
(assoc :grid-steps grid-steps) | ||
(assoc :grid-step-size (max 1 (int (/ (:screen-size params) | ||
grid-steps))))))) | ||
(loop [grid (vec (repeat grid-steps (vec (repeat grid-steps [])))) | ||
remaining (into [] (map strip-neighbors objs))] | ||
(if (empty? remaining) | ||
grid | ||
(recur (update-in grid | ||
(xy->gridxy (:position (first remaining))) | ||
conj | ||
(first remaining)) | ||
(rest remaining)))))) | ||
|
||
(defn update-neighbors | ||
"Annotates each world object with :neighbors and :overlaps." | ||
[] | ||
(swap! | ||
world-objects | ||
(fn [objs] | ||
(let [grid (make-world-grid objs) | ||
window (fn [c] (mapv #(wrap-grid-coordinate (+ c %)) [-1 0 1]))] | ||
(into [] | ||
(pmapall (fn [obj] | ||
(let [neighs (vec | ||
(relativize-positions | ||
(filter #(and (not (= (:id obj) (:id %))) | ||
(<= (length (map - (:position obj) (:position %))) | ||
(:neighborhood-size @parameters))) | ||
(apply concat | ||
(let [[x y] (xy->gridxy (:position obj))] | ||
(doall | ||
(for [xs (window x) | ||
ys (window y)] | ||
(get-in grid (wrap-gridxy [xs ys]))))))) | ||
(:position obj)))] | ||
(-> obj | ||
(assoc :neighbors neighs) | ||
(assoc :overlaps | ||
(vec (filter #(<= (length (:position %)) | ||
(+ (:radius obj) (:radius %))) | ||
neighs)))))) | ||
objs)))))) | ||
|
||
(let [stripped (mapv strip-neighbors objs)] | ||
(pmapallv (fn [obj] | ||
(let [neighs (vec | ||
(relativize-positions | ||
(filterv #(and (not (= (:id obj) (:id %))) | ||
(<= (length (mapv - (:position obj) (:position %))) | ||
(:neighborhood-size @parameters))) | ||
stripped) | ||
(:position obj)))] | ||
(-> obj | ||
(assoc :neighbors neighs) | ||
(assoc :overlaps | ||
(filterv #(<= (length (:position %)) | ||
(+ (:radius obj) (:radius %))) | ||
neighs))))) | ||
stripped))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,33 @@ | ||
(ns pucks.neighbors | ||
(:use pucks.globals pucks.util pucks.vec2D)) | ||
|
||
(defn wrap-grid-coordinate | ||
[c] | ||
(if (< c 0) | ||
(dec (:grid-steps @parameters)) | ||
(if (>= c (:grid-steps @parameters)) | ||
0 | ||
c))) | ||
|
||
(defn wrap-gridxy | ||
[xy] | ||
(vec (map wrap-grid-coordinate xy))) | ||
|
||
(defn xy->gridxy | ||
[xy] | ||
(wrap-gridxy (map (fn [c] (int (/ c (:grid-step-size @parameters)))) xy))) | ||
|
||
(defn strip-neighbors | ||
[obj] | ||
(-> obj | ||
(dissoc :neighbors) | ||
(dissoc :sensed) | ||
(dissoc :overlaps))) | ||
|
||
(defn make-world-grid | ||
[objs] | ||
(let [grid-steps (max 1 (int (/ (:screen-size @parameters) | ||
(:neighborhood-size @parameters))))] | ||
(swap! parameters | ||
(fn [params] | ||
(-> params | ||
(assoc :grid-steps grid-steps) | ||
(assoc :grid-step-size (max 1 (int (/ (:screen-size params) | ||
grid-steps))))))) | ||
(loop [grid (vec (repeat grid-steps (vec (repeat grid-steps [])))) | ||
remaining (into [] (map strip-neighbors objs))] | ||
(if (empty? remaining) | ||
grid | ||
(recur (update-in grid | ||
(xy->gridxy (:position (first remaining))) | ||
conj | ||
(first remaining)) | ||
(rest remaining)))))) | ||
|
||
(defn update-neighbors | ||
"Annotates each world object with :neighbors and :overlaps." | ||
[] | ||
(swap! | ||
world-objects | ||
(fn [objs] | ||
(let [grid (make-world-grid objs) | ||
window (fn [c] (mapv #(wrap-grid-coordinate (+ c %)) [-1 0 1]))] | ||
(into [] | ||
(pmapall (fn [obj] | ||
(let [neighs (vec | ||
(relativize-positions | ||
(filter #(and (not (= (:id obj) (:id %))) | ||
(<= (length (map - (:position obj) (:position %))) | ||
(:neighborhood-size @parameters))) | ||
(apply concat | ||
(let [[x y] (xy->gridxy (:position obj))] | ||
(doall | ||
(for [xs (window x) | ||
ys (window y)] | ||
(get-in grid (wrap-gridxy [xs ys]))))))) | ||
(:position obj)))] | ||
(-> obj | ||
(assoc :neighbors neighs) | ||
(assoc :overlaps | ||
(vec (filter #(<= (length (:position %)) | ||
(+ (:radius obj) (:radius %))) | ||
neighs)))))) | ||
objs)))))) | ||
|
||
(let [stripped (mapv strip-neighbors objs)] | ||
(pmapallv (fn [obj] | ||
(let [neighs (vec | ||
(relativize-positions | ||
(filterv #(and (not (= (:id obj) (:id %))) | ||
(<= (length (mapv - (:position obj) (:position %))) | ||
(:neighborhood-size @parameters))) | ||
stripped) | ||
(:position obj)))] | ||
(-> obj | ||
(assoc :neighbors neighs) | ||
(assoc :overlaps | ||
(filterv #(<= (length (:position %)) | ||
(+ (:radius obj) (:radius %))) | ||
neighs))))) | ||
stripped))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.