diff options
author | Marc Sunet <jeannekamikaze@gmail.com> | 2012-08-29 13:08:26 +0200 |
---|---|---|
committer | Marc Sunet <jeannekamikaze@gmail.com> | 2012-08-29 13:08:26 +0200 |
commit | a2946c79640a9e811db2b976ba6401da9fe1b88e (patch) | |
tree | 64f6a313297943665408601ec3e9f125fe02182e | |
parent | 44050c4a0a2ea4add31f73ec2aaa6e45fa21542d (diff) |
Changed Octree to QuadTree
-rw-r--r-- | Spear.lkshw | 4 | ||||
-rw-r--r-- | Spear/Scene/Scene.hs | 29 |
2 files changed, 11 insertions, 22 deletions
diff --git a/Spear.lkshw b/Spear.lkshw index a945bab..3c4b807 100644 --- a/Spear.lkshw +++ b/Spear.lkshw | |||
@@ -1,10 +1,10 @@ | |||
1 | Version of workspace file format: | 1 | Version of workspace file format: |
2 | 1 | 2 | 1 |
3 | Time of storage: | 3 | Time of storage: |
4 | "Wed Aug 29 12:27:48 CEST 2012" | 4 | "Wed Aug 29 13:08:08 CEST 2012" |
5 | Name of the workspace: | 5 | Name of the workspace: |
6 | "Spear" | 6 | "Spear" |
7 | File paths of contained packages: | 7 | File paths of contained packages: |
8 | ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] | 8 | ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] |
9 | Maybe file path of an active package: | 9 | Maybe file path of an active package: |
10 | Just "Spear.cabal" \ No newline at end of file | 10 | Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file |
diff --git a/Spear/Scene/Scene.hs b/Spear/Scene/Scene.hs index 4658ddb..0dfa459 100644 --- a/Spear/Scene/Scene.hs +++ b/Spear/Scene/Scene.hs | |||
@@ -1,7 +1,4 @@ | |||
1 | module Spear.Scene.Scene | 1 | module Spear.Scene.Scene |
2 | where | ||
3 | |||
4 | {-module Spear.Scene.Scene | ||
5 | ( | 2 | ( |
6 | -- * Data types | 3 | -- * Data types |
7 | Scene | 4 | Scene |
@@ -9,7 +6,6 @@ where | |||
9 | , listScene | 6 | , listScene |
10 | -- * Insertion and deletion | 7 | -- * Insertion and deletion |
11 | , add | 8 | , add |
12 | , addl | ||
13 | , remove | 9 | , remove |
14 | , Spear.Scene.Scene.filter | 10 | , Spear.Scene.Scene.filter |
15 | -- * Queries | 11 | -- * Queries |
@@ -27,7 +23,7 @@ where | |||
27 | import Spear.Collision.Types | 23 | import Spear.Collision.Types |
28 | import Spear.Game (Game) | 24 | import Spear.Game (Game) |
29 | import Spear.Math.AABB | 25 | import Spear.Math.AABB |
30 | import Spear.Math.Octree as Octree | 26 | import Spear.Math.QuadTree as QT |
31 | 27 | ||
32 | import Control.Applicative ((<*>)) | 28 | import Control.Applicative ((<*>)) |
33 | import Control.Monad (foldM) | 29 | import Control.Monad (foldM) |
@@ -41,9 +37,9 @@ data Scene obj = | |||
41 | { objects :: ![obj] | 37 | { objects :: ![obj] |
42 | } | 38 | } |
43 | | | 39 | | |
44 | OctreeScene | 40 | QuadTreeScene |
45 | { collideAABB :: obj -> AABB -> CollisionType | 41 | { collideAABB :: obj -> AABB -> CollisionType |
46 | , world :: !(Octree obj) | 42 | , world :: !(QuadTree obj) |
47 | } | 43 | } |
48 | 44 | ||
49 | 45 | ||
@@ -57,16 +53,10 @@ listScene = ListScene | |||
57 | --octreeScene collide getAABB objs = OctreeScene [] collide $ makeOctree | 53 | --octreeScene collide getAABB objs = OctreeScene [] collide $ makeOctree |
58 | 54 | ||
59 | 55 | ||
60 | -- | Add a game object to the given 'Scene'. | ||
61 | add :: Scene obj -> obj -> Scene obj | ||
62 | add (scene@ListScene {}) o = scene { objects = o : objects scene } | ||
63 | add (scene@OctreeScene {}) o = scene { world = insert (collideAABB scene) (world scene) o } | ||
64 | |||
65 | |||
66 | -- | Add a list of game objects to the given 'Scene'. | 56 | -- | Add a list of game objects to the given 'Scene'. |
67 | addl :: Scene obj -> [obj] -> Scene obj | 57 | add :: Scene obj -> [obj] -> Scene obj |
68 | addl (scene@ListScene {}) l = scene { objects = l ++ objects scene } | 58 | add (scene@ListScene {}) l = scene { objects = l ++ objects scene } |
69 | addl (scene@OctreeScene {}) l = scene { world = insertl (collideAABB scene) (world scene) l } | 59 | add (scene@QuadTreeScene {}) l = scene { world = QT.insert (collideAABB scene) (world scene) l } |
70 | 60 | ||
71 | 61 | ||
72 | -- | Remove a game object from the given 'Scene'. | 62 | -- | Remove a game object from the given 'Scene'. |
@@ -91,7 +81,7 @@ type Update obj = obj -> obj | |||
91 | -- | Update the given scene. | 81 | -- | Update the given scene. |
92 | update :: (obj -> obj) -> Scene obj -> Scene obj | 82 | update :: (obj -> obj) -> Scene obj -> Scene obj |
93 | update updt (scene@ListScene {}) = scene { objects = fmap updt $ objects scene } | 83 | update updt (scene@ListScene {}) = scene { objects = fmap updt $ objects scene } |
94 | update updt (scene@OctreeScene {}) = scene { world = Octree.map (collideAABB scene) updt $ world scene } | 84 | update updt (scene@QuadTreeScene {}) = scene { world = QT.map (collideAABB scene) updt $ world scene } |
95 | 85 | ||
96 | 86 | ||
97 | -- | Update the given scene. | 87 | -- | Update the given scene. |
@@ -116,7 +106,7 @@ collide col scene@ListScene {} = | |||
116 | in | 106 | in |
117 | scene { objects = objs' } | 107 | scene { objects = objs' } |
118 | 108 | ||
119 | collide col scene@OctreeScene {} = | 109 | collide col scene@QuadTreeScene {} = |
120 | scene { world = gmap (collideAABB scene) col $ world scene } | 110 | scene { world = gmap (collideAABB scene) col $ world scene } |
121 | 111 | ||
122 | 112 | ||
@@ -152,5 +142,4 @@ collide' col scene@ListScene {} = | |||
152 | -- | Render the given 'Scene'. | 142 | -- | Render the given 'Scene'. |
153 | render :: (obj -> Game s ()) -> Scene obj -> Game s () | 143 | render :: (obj -> Game s ()) -> Scene obj -> Game s () |
154 | render rend (scene@ListScene {}) = Prelude.mapM_ rend $ objects scene | 144 | render rend (scene@ListScene {}) = Prelude.mapM_ rend $ objects scene |
155 | render rend (scene@OctreeScene {}) = F.mapM_ rend $ world scene | 145 | render rend (scene@QuadTreeScene {}) = F.mapM_ rend $ world scene |
156 | -} \ No newline at end of file | ||