From: Daniel Liu Date: Sat, 1 May 2021 14:32:21 +0000 (-0400) Subject: sim step setup X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=bdbd06560f50a45aa12c15d4fefa0e3c303fbd7a;p=ekitaihs.git sim step setup --- diff --git a/Ekitai.hs b/Ekitai.hs index 62e1341..8793052 100644 --- a/Ekitai.hs +++ b/Ekitai.hs @@ -1,5 +1,7 @@ import System.Environment +import qualified Data.Vector as V + import Parse import Sim diff --git a/Sim.hs b/Sim.hs index bb96fe3..e96816e 100644 --- a/Sim.hs +++ b/Sim.hs @@ -1,18 +1,40 @@ -module Sim ( ChunkData, initSimSpace, defaultChunkData ) where +module Sim ( initSimSpace, testSim, physStep ) where +import Data.Vector ((!), (//)) import qualified Data.Vector as V -data ChunkData = ChunkData - { velocity :: (Float, Float) - , density :: Float - } deriving (Show) +-- Simulation simSpace simW simH +data Simulation = Simulation (V.Vector ChunkData) Int Int deriving (Show) -defaultChunkData = ChunkData - { velocity = (0,0) - , density = 0 - } +data ChunkType = Empty + | Water + | Wall deriving (Show) -initSimSpace :: Int -> Int -> V.Vector ChunkData -initSimSpace x y = V.replicate (y*x) defaultChunkData +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 + +initSimSpace x y = Simulation (V.replicate (y*x) (ChunkData Empty)) x y + +testSim = simSet (initSimSpace 10 10) (ChunkData Water) 5 + +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 + +-- initGaussSeidel s = +-- where h = length s +-- w = length (s V.! 0) -- gaussSeidel