aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Sunet <jeannekamikaze@gmail.com>2012-08-29 13:08:26 +0200
committerMarc Sunet <jeannekamikaze@gmail.com>2012-08-29 13:08:26 +0200
commita2946c79640a9e811db2b976ba6401da9fe1b88e (patch)
tree64f6a313297943665408601ec3e9f125fe02182e
parent44050c4a0a2ea4add31f73ec2aaa6e45fa21542d (diff)
Changed Octree to QuadTree
-rw-r--r--Spear.lkshw4
-rw-r--r--Spear/Scene/Scene.hs29
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 @@
1Version of workspace file format: 1Version of workspace file format:
2 1 2 1
3Time of storage: 3Time of storage:
4 "Wed Aug 29 12:27:48 CEST 2012" 4 "Wed Aug 29 13:08:08 CEST 2012"
5Name of the workspace: 5Name of the workspace:
6 "Spear" 6 "Spear"
7File paths of contained packages: 7File paths of contained packages:
8 ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] 8 ["demos/simple-scene/simple-scene.cabal","Spear.cabal"]
9Maybe file path of an active package: 9Maybe 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 @@
1module Spear.Scene.Scene 1module Spear.Scene.Scene
2where
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
27import Spear.Collision.Types 23import Spear.Collision.Types
28import Spear.Game (Game) 24import Spear.Game (Game)
29import Spear.Math.AABB 25import Spear.Math.AABB
30import Spear.Math.Octree as Octree 26import Spear.Math.QuadTree as QT
31 27
32import Control.Applicative ((<*>)) 28import Control.Applicative ((<*>))
33import Control.Monad (foldM) 29import 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'.
61add :: Scene obj -> obj -> Scene obj
62add (scene@ListScene {}) o = scene { objects = o : objects scene }
63add (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'.
67addl :: Scene obj -> [obj] -> Scene obj 57add :: Scene obj -> [obj] -> Scene obj
68addl (scene@ListScene {}) l = scene { objects = l ++ objects scene } 58add (scene@ListScene {}) l = scene { objects = l ++ objects scene }
69addl (scene@OctreeScene {}) l = scene { world = insertl (collideAABB scene) (world scene) l } 59add (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.
92update :: (obj -> obj) -> Scene obj -> Scene obj 82update :: (obj -> obj) -> Scene obj -> Scene obj
93update updt (scene@ListScene {}) = scene { objects = fmap updt $ objects scene } 83update updt (scene@ListScene {}) = scene { objects = fmap updt $ objects scene }
94update updt (scene@OctreeScene {}) = scene { world = Octree.map (collideAABB scene) updt $ world scene } 84update 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
119collide col scene@OctreeScene {} = 109collide 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'.
153render :: (obj -> Game s ()) -> Scene obj -> Game s () 143render :: (obj -> Game s ()) -> Scene obj -> Game s ()
154render rend (scene@ListScene {}) = Prelude.mapM_ rend $ objects scene 144render rend (scene@ListScene {}) = Prelude.mapM_ rend $ objects scene
155render rend (scene@OctreeScene {}) = F.mapM_ rend $ world scene 145render rend (scene@QuadTreeScene {}) = F.mapM_ rend $ world scene
156-} \ No newline at end of file