sim step setup
[ekitaihs.git] / Sim.hs
1 module Sim ( initSimSpace, testSim, physStep ) where
2
3 import           Data.Vector ((!), (//))
4 import qualified Data.Vector as V
5
6 -- Simulation simSpace simW simH
7 data Simulation = Simulation (V.Vector ChunkData) Int Int deriving (Show)
8
9 data ChunkType = Empty
10     | Water 
11     | Wall deriving (Show)
12
13 data ChunkData = ChunkData ChunkType deriving (Show)
14
15 -- vec accessors
16 veccGet v w i = v ! i
17 simGet (Simulation s w _) i = veccGet s w i
18
19 veccSet v w c i = v // [(i,c)]
20 simSet (Simulation s w h) c i = Simulation (veccSet s w c i) w h
21
22 initSimSpace x y = Simulation (V.replicate (y*x) (ChunkData Empty)) x y
23
24 testSim = simSet (initSimSpace 10 10) (ChunkData Water) 5
25
26 physStep sim@(Simulation _ w h) = _physStep 0 (initSimSpace w h) sim
27 _physStep i acc sim@(Simulation s w h) =
28     if i >= w*h then acc
29     else _physStep (i+1) next sim
30     where
31         getChunkData (ChunkData c) = c
32         next = case getChunkData $ simGet sim i of
33             Water -> sim
34             _ -> sim
35
36 -- initGaussSeidel s =
37 --     where h = length s
38 --           w = length (s V.! 0)
39
40 -- gaussSeidel