aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Sunet <jeannekamikaze@gmail.com>2012-08-06 13:23:54 +0200
committerMarc Sunet <jeannekamikaze@gmail.com>2012-08-06 13:23:54 +0200
commit9c9cbffd57a47abc3459d67e79fe9939c34668b3 (patch)
tree6a26b79268f89f59c528e3fcb808b5549f2e4f99
parent20b09101a88f0e2ea102df3e484ff215177cb290 (diff)
Generalised CreateGameObject to any monad
-rw-r--r--Spear/Scene/Loader.hs17
1 files changed, 9 insertions, 8 deletions
diff --git a/Spear/Scene/Loader.hs b/Spear/Scene/Loader.hs
index 2491907..6001bdb 100644
--- a/Spear/Scene/Loader.hs
+++ b/Spear/Scene/Loader.hs
@@ -293,15 +293,16 @@ newLight _ = return ()
293-- Object Loading -- 293-- Object Loading --
294-------------------- 294--------------------
295 295
296type CreateGameObject a = String -- ^ The object's name. 296type CreateGameObject m a
297 -> SceneResources 297 = String -- ^ The object's name.
298 -> [Property] 298 -> SceneResources
299 -> Matrix4 -- ^ The object's transform. 299 -> [Property]
300 -> Setup a 300 -> Matrix4 -- ^ The object's transform.
301 -> m a
301 302
302 303
303-- | Load objects from the given 'SceneGraph'. 304-- | Load objects from the given 'SceneGraph'.
304loadObjects :: CreateGameObject a -> SceneResources -> SceneGraph -> Setup [a] 305loadObjects :: Monad m => CreateGameObject m a -> SceneResources -> SceneGraph -> m [a]
305loadObjects newGO sceneRes g = 306loadObjects newGO sceneRes g =
306 case node "layout" g of 307 case node "layout" g of
307 Nothing -> return [] 308 Nothing -> return []
@@ -309,7 +310,7 @@ loadObjects newGO sceneRes g =
309 310
310 311
311-- to-do: use a strict accumulator and make loadObjects tail recursive. 312-- to-do: use a strict accumulator and make loadObjects tail recursive.
312newObject :: CreateGameObject a -> SceneResources -> SceneGraph -> [Setup a] 313newObject :: Monad m => CreateGameObject m a -> SceneResources -> SceneGraph -> [m a]
313newObject newGO sceneRes (SceneNode nid props children) = 314newObject newGO sceneRes (SceneNode nid props children) =
314 let o = newObject' newGO sceneRes nid props 315 let o = newObject' newGO sceneRes nid props
315 in o : (concat $ fmap (newObject newGO sceneRes) children) 316 in o : (concat $ fmap (newObject newGO sceneRes) children)
@@ -317,7 +318,7 @@ newObject newGO sceneRes (SceneNode nid props children) =
317newObject newGO sceneRes (SceneLeaf nid props) = [newObject' newGO sceneRes nid props] 318newObject newGO sceneRes (SceneLeaf nid props) = [newObject' newGO sceneRes nid props]
318 319
319 320
320newObject' :: CreateGameObject a -> SceneResources -> String -> [Property] -> Setup a 321newObject' :: Monad m => CreateGameObject m a -> SceneResources -> String -> [Property] -> m a
321newObject' newGO sceneRes nid props = do 322newObject' newGO sceneRes nid props = do
322 -- Optional properties. 323 -- Optional properties.
323 let name = (asString $ value "name" props) `unspecified` "unknown" 324 let name = (asString $ value "name" props) `unspecified` "unknown"