diff options
| -rw-r--r-- | Spear/Scene/Loader.hs | 17 |
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 | ||
| 296 | type CreateGameObject a = String -- ^ The object's name. | 296 | type 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'. |
| 304 | loadObjects :: CreateGameObject a -> SceneResources -> SceneGraph -> Setup [a] | 305 | loadObjects :: Monad m => CreateGameObject m a -> SceneResources -> SceneGraph -> m [a] |
| 305 | loadObjects newGO sceneRes g = | 306 | loadObjects 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. |
| 312 | newObject :: CreateGameObject a -> SceneResources -> SceneGraph -> [Setup a] | 313 | newObject :: Monad m => CreateGameObject m a -> SceneResources -> SceneGraph -> [m a] |
| 313 | newObject newGO sceneRes (SceneNode nid props children) = | 314 | newObject 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) = | |||
| 317 | newObject newGO sceneRes (SceneLeaf nid props) = [newObject' newGO sceneRes nid props] | 318 | newObject newGO sceneRes (SceneLeaf nid props) = [newObject' newGO sceneRes nid props] |
| 318 | 319 | ||
| 319 | 320 | ||
| 320 | newObject' :: CreateGameObject a -> SceneResources -> String -> [Property] -> Setup a | 321 | newObject' :: Monad m => CreateGameObject m a -> SceneResources -> String -> [Property] -> m a |
| 321 | newObject' newGO sceneRes nid props = do | 322 | newObject' 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" |
