pinosaur
/
ekitaihs.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bdbd065
)
reworked phystep loop
author
Daniel Liu
<mr.picklepinosaur@gmail.com>
Sat, 1 May 2021 16:23:09 +0000
(12:23 -0400)
committer
Daniel Liu
<mr.picklepinosaur@gmail.com>
Sat, 1 May 2021 16:23:09 +0000
(12:23 -0400)
Sim.hs
patch
|
blob
|
history
diff --git
a/Sim.hs
b/Sim.hs
index
e96816e
..
7f1688f
100644
(file)
--- a/
Sim.hs
+++ b/
Sim.hs
@@
-1,4
+1,4
@@
-module Sim ( initSimSpace, testSim, physStep ) where
+module Sim ( initSimSpace, testSim, physStep
, validDirects
) where
import Data.Vector ((!), (//))
import qualified Data.Vector as V
import Data.Vector ((!), (//))
import qualified Data.Vector as V
@@
-13,28
+13,23
@@
data ChunkType = Empty
data ChunkData = ChunkData ChunkType deriving (Show)
-- vec accessors
data ChunkData = ChunkData ChunkType deriving (Show)
-- vec accessors
-veccGet v w i = v ! i
-simGet (Simulation s w _) i = veccGet s w i
-
-veccSet v w c i = v // [(i,c)]
-simSet (Simulation s w h) c i = Simulation (veccSet s w c i) w h
+simGet (Simulation s w _) x y = s ! (y*w+x)
+simSet (Simulation s w h) c x y = Simulation (s // [(y*w+x,c)]) w h
initSimSpace x y = Simulation (V.replicate (y*x) (ChunkData Empty)) x y
initSimSpace x y = Simulation (V.replicate (y*x) (ChunkData Empty)) x y
-testSim = simSet (initSimSpace 10 10) (ChunkData Water) 5
+testSim = simSet (initSimSpace 10 10) (ChunkData Water) 5
0
-physStep sim@(Simulation _ w h) = _physStep 0 (initSimSpace w h) sim
-_physStep i acc sim@(Simulation s w h) =
- if i >= w*h then acc
- else _physStep (i+1) next sim
- where
- getChunkData (ChunkData c) = c
- next = case getChunkData $ simGet sim i of
- Water -> sim
- _ -> sim
+physStep sim@(Simulation _ w h) = _physStep [(x, y) | x <- [0..w-1], y <- [0..h-1]] (initSimSpace w h) sim
+_physStep grid acc sim@(Simulation s w h) =
+ if null grid then acc
+ else _physStep (tail grid) next sim
+ where x = fst $ head grid
+ y = snd $ head grid
+ next = sim
--- initGaussSeidel s =
--- where h = length s
--- w = length (s V.! 0)
+-- gets chunks around a given chunk that are inside grid
+validDirects x y w h = filter
+ (\q -> 0 <= (fst q) && (fst q) < w && (snd q) <= 0 && (snd q) < h)
+ [(a,b) | a <- [x-1..x+1], b <- [y-1..y+1], not (a==x && b==y)]
--- gaussSeidel