Add trajectory to grenades, various refactoring
This commit is contained in:
+56
-39
@@ -5,9 +5,9 @@ module Shader.Poke
|
||||
, pokeLayVerxs
|
||||
, pokeArrayOff
|
||||
, pokePoint33s
|
||||
, poke224s
|
||||
, pokeShape
|
||||
, pokePoint3s
|
||||
, pokeWallsWindowsFloor
|
||||
) where
|
||||
import Shader.Data
|
||||
import Shader.Parameters
|
||||
@@ -39,7 +39,7 @@ pokeVerxs vbos count vxs = VS.mapM_ (pokeVerx vbos count) $ VS.fromList vxs
|
||||
pokeVerx :: MV.MVector (PrimState IO) FullShader -> UMV.MVector (PrimState IO) Int -> Verx -> IO ()
|
||||
pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxExt=ext,_vxShadNum=theShadNum} = do
|
||||
typeOff <- UMV.unsafeRead offsets sn
|
||||
basePtr <- _vboPtr . _vaoVBO . _shadVAO <$> MV.read vbos sn
|
||||
basePtr <- _vboPtr . _vaoVBO . _shadVAO <$> MV.unsafeRead vbos sn
|
||||
let thePtr = plusPtr basePtr (typeOff * pokeStride sn * floatSize)
|
||||
poke34 thePtr thePos theCol
|
||||
pokeArrayOff thePtr 7 ext
|
||||
@@ -47,6 +47,46 @@ pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxExt=ext,_vxShadNum=the
|
||||
where
|
||||
sn = _unShadNum theShadNum
|
||||
|
||||
pokeWallsWindowsFloor
|
||||
:: Ptr Float
|
||||
-> Ptr Float
|
||||
-> Ptr Float
|
||||
-> UMV.MVector (PrimState IO) Int
|
||||
-> [ ( (Point2,Point2) , Point4 ) ]
|
||||
-> [ ( (Point2,Point2) , Point4 ) ]
|
||||
-> [ ( Point3 , Point3 ) ]
|
||||
-> IO ()
|
||||
pokeWallsWindowsFloor wlptr wiptr flptr counts wls wis fls = do
|
||||
VS.mapM_ (pokeW wlptr counts 0) (VS.fromList wls)
|
||||
VS.mapM_ (pokeW wiptr counts 1) (VS.fromList wis)
|
||||
VS.mapM_ (pokeF flptr counts) (VS.fromList fls)
|
||||
|
||||
pokeF :: Ptr Float -> UMV.MVector (PrimState IO) Int -> (Point3,Point3) -> IO ()
|
||||
pokeF ptr counts (V3 a b c,V3 d e f) = do
|
||||
i' <- UMV.unsafeRead counts 2
|
||||
let i = i' * 6
|
||||
pokeElemOff ptr (i + 0) a
|
||||
pokeElemOff ptr (i + 1) b
|
||||
pokeElemOff ptr (i + 2) c
|
||||
pokeElemOff ptr (i + 3) d
|
||||
pokeElemOff ptr (i + 4) e
|
||||
pokeElemOff ptr (i + 5) f
|
||||
UMV.unsafeModify counts (+1) 2
|
||||
|
||||
pokeW :: Ptr Float -> UMV.MVector (PrimState IO) Int -> Int -> ((Point2,Point2),Point4) -> IO ()
|
||||
pokeW ptr counts iv ((V2 a b,V2 c d),V4 e f g h) = do
|
||||
i' <- UMV.unsafeRead counts iv
|
||||
let i = i' * 8
|
||||
pokeElemOff ptr (i + 0) a
|
||||
pokeElemOff ptr (i + 1) b
|
||||
pokeElemOff ptr (i + 2) c
|
||||
pokeElemOff ptr (i + 3) d
|
||||
pokeElemOff ptr (i + 4) e
|
||||
pokeElemOff ptr (i + 5) f
|
||||
pokeElemOff ptr (i + 6) g
|
||||
pokeElemOff ptr (i + 7) h
|
||||
UMV.unsafeModify counts (+1) iv
|
||||
|
||||
pokeShape
|
||||
:: Ptr Float
|
||||
-> Ptr GLushort
|
||||
@@ -64,7 +104,7 @@ pokeShapeObj
|
||||
-> ShapeObj
|
||||
-> IO ()
|
||||
pokeShapeObj ptr iptr ieptr counts (ShapeObj shType shVerts) = case shType of
|
||||
TopPrism size -> pokeTopPrism size ptr iptr ieptr counts shVerts
|
||||
TopPrism size -> pokeTopPrism (size - 2) ptr iptr ieptr counts shVerts
|
||||
|
||||
pokeTopPrism :: Int -> Ptr Float -> Ptr GLushort
|
||||
-> Ptr GLushort
|
||||
@@ -72,44 +112,37 @@ pokeTopPrism :: Int -> Ptr Float -> Ptr GLushort
|
||||
-> [ShapeV]
|
||||
-> IO ()
|
||||
pokeTopPrism size ptr iptr ieptr counts svs = do
|
||||
-- MP.bindM3 (\a b c -> return (a,b,c))
|
||||
-- (VS.foldlM' (pokeJustV ptr) nv (VS.fromList svs) )
|
||||
-- (UV.foldM (pokeTopPrismIndex nv iptr) ni (memoTopPrismIndices V.! (size - 2)) )
|
||||
-- (UV.foldM (pokeTopPrismEdgeIndex nv ieptr) nei (memoTopPrismEdgeIndices V.! (size - 2)) )
|
||||
nv <- UMV.read counts 0
|
||||
UV.mapM_ (pokeTopPrismIndex nv iptr counts) (memoTopPrismIndices V.! (size - 2))
|
||||
UV.mapM_ (pokeTopPrismEdgeIndex nv ieptr counts) (memoTopPrismEdgeIndices V.! (size - 2))
|
||||
VS.mapM_ (pokeJustV ptr counts) (VS.fromList svs)
|
||||
-- UMV.modify counts (+ nv') 0
|
||||
-- UMV.modify counts (+ ni') 1
|
||||
-- UMV.modify counts (+ nei') 2
|
||||
--return (nv',ni',nei')
|
||||
nv <- UMV.unsafeRead counts 0
|
||||
-- MP.bindM3 (\_ _ _ -> return ())
|
||||
UV.mapM_ (pokeTopPrismIndex nv iptr counts) (memoTopPrismIndices V.! size)
|
||||
UV.mapM_ (pokeTopPrismEdgeIndex nv ieptr counts) (memoTopPrismEdgeIndices V.! size)
|
||||
VS.mapM_ (pokeJustV ptr counts) (VS.fromList svs)
|
||||
|
||||
pokeTopPrismEdgeIndex :: Int -> Ptr GLushort
|
||||
-> UMV.MVector (PrimState IO) Int
|
||||
-> Int
|
||||
-> IO ()
|
||||
pokeTopPrismEdgeIndex nv eiptr counts ioff = do
|
||||
nei <- UMV.read counts 2
|
||||
nei <- UMV.unsafeRead counts 2
|
||||
pokeElemOff eiptr nei (fromIntegral $ nv + ioff)
|
||||
UMV.modify counts (+1) 2
|
||||
UMV.unsafeModify counts (+1) 2
|
||||
|
||||
pokeTopPrismIndex :: Int -> Ptr GLushort
|
||||
-> UMV.MVector (PrimState IO) Int
|
||||
-> Int
|
||||
-> IO ()
|
||||
pokeTopPrismIndex nv iptr counts ioff = do
|
||||
ni <- UMV.read counts 1
|
||||
ni <- UMV.unsafeRead counts 1
|
||||
pokeElemOff iptr ni (fromIntegral $ nv + ioff)
|
||||
UMV.modify counts (+1) 1
|
||||
UMV.unsafeModify counts (+1) 1
|
||||
|
||||
memoTopPrismEdgeIndices :: V.Vector (UV.Vector Int)
|
||||
memoTopPrismEdgeIndices = V.generate 6 f
|
||||
memoTopPrismEdgeIndices = V.generate 10 f
|
||||
where
|
||||
f n = UV.fromList $ topPrismEdgeIndices (n + 2)
|
||||
|
||||
memoTopPrismIndices :: V.Vector (UV.Vector Int)
|
||||
memoTopPrismIndices = V.generate 6 f
|
||||
memoTopPrismIndices = V.generate 10 f
|
||||
where
|
||||
f n = UV.fromList $ topPrismIndices (n + 2)
|
||||
|
||||
@@ -136,7 +169,7 @@ topPrismIndices n = concatMap f [1..n-2] -- triangles on top face
|
||||
|
||||
pokeJustV :: Ptr Float -> UMV.MVector (PrimState IO) Int -> ShapeV -> IO ()
|
||||
pokeJustV ptr counts sh = do
|
||||
nv <- UMV.read counts 0
|
||||
nv <- UMV.unsafeRead counts 0
|
||||
let off i = nv*7 + i
|
||||
pokeElemOff ptr (off 0) a
|
||||
pokeElemOff ptr (off 1) b
|
||||
@@ -145,7 +178,7 @@ pokeJustV ptr counts sh = do
|
||||
pokeElemOff ptr (off 4) e
|
||||
pokeElemOff ptr (off 5) f
|
||||
pokeElemOff ptr (off 6) g
|
||||
UMV.modify counts (+1) 0
|
||||
UMV.unsafeModify counts (+1) 0
|
||||
where
|
||||
V3 a b c = _svPos sh
|
||||
V4 d e f g = _svCol sh
|
||||
@@ -226,19 +259,3 @@ pokePoint33 ptr n (V3 a b c,V3 d e f) = do
|
||||
where
|
||||
off i = n*6 + i
|
||||
|
||||
pokePoint224 :: Ptr Float -> Int -> ((Point2,Point2),Point4) -> IO Int
|
||||
pokePoint224 ptr n ((V2 a b,V2 c d),V4 e f g h) = do
|
||||
pokeElemOff ptr (off 0) a
|
||||
pokeElemOff ptr (off 1) b
|
||||
pokeElemOff ptr (off 2) c
|
||||
pokeElemOff ptr (off 3) d
|
||||
pokeElemOff ptr (off 4) e
|
||||
pokeElemOff ptr (off 5) f
|
||||
pokeElemOff ptr (off 6) g
|
||||
pokeElemOff ptr (off 7) h
|
||||
return (n + 1)
|
||||
where
|
||||
off i = n*8 + i
|
||||
|
||||
poke224s :: Ptr Float -> [((Point2,Point2),Point4)] -> IO Int
|
||||
poke224s ptr = VS.foldlM' (pokePoint224 ptr) 0 . VS.fromList
|
||||
|
||||
Reference in New Issue
Block a user