From ccf714a691a95be84ba168a725b6f0187bb903ea Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 19 May 2019 16:50:34 -0400 Subject: Made ringCapacity give vertex-count rather than float-count. --- PointPrimitiveRing.hs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'PointPrimitiveRing.hs') diff --git a/PointPrimitiveRing.hs b/PointPrimitiveRing.hs index acca3ec..f55e08e 100644 --- a/PointPrimitiveRing.hs +++ b/PointPrimitiveRing.hs @@ -2,10 +2,13 @@ module PointPrimitiveRing where import Control.Monad +import Data.Data import Data.Foldable +import Data.Function import Data.Int import Data.IORef import Data.Maybe +import Data.Some import Data.Word import qualified Data.Map.Strict as Map import qualified Data.Vector as V @@ -32,9 +35,9 @@ data Ring = Ring { rBufferObject :: Buffer , rStorage :: GLStorage , rObject :: Object - , rSize :: IORef Int -- Current count of Floats in the ring buffer. - , rBack :: IORef Int -- Where next vector will be added. - , ringCapacity :: CPtrdiff -- Maximum number of floats in buffer. + , rSize :: IORef Int -- Current count of vertices in the ring buffer. + , rBack :: IORef Int -- Where next vertex will be added. + , ringCapacity :: Int -- Maximum number of vertices in buffer. , rPosition :: AttributeKey (GLVector 3 Float) } @@ -54,7 +57,7 @@ newRing storage sz = do , rObject = obj , rSize = sizeRef , rBack = startRef - , ringCapacity = 3 * fromIntegral sz + , ringCapacity = sz , rPosition = k } updateRingCommands r @@ -65,9 +68,11 @@ updateRingCommands r = do back <- fromIntegral <$> readIORef (rBack r) size <- fromIntegral <$> readIORef (rSize r) let mask 0 = [] - mask cnt = case cnt + back - size of - front | front > cnt -> [(front - cnt,size)] - | otherwise -> [(0,back), (front,cnt - front)] + mask cnt + | cnt==size = [(0,cnt)] + | otherwise = case cnt + back - size of + front | front > cnt -> [(front - cnt,size)] + | otherwise -> [(0,back), (front,cnt - front)] updateCommands (rStorage r) (rObject r) mask readIORef (objCommands $ rObject r) >>= mapM_ print return () @@ -75,12 +80,12 @@ updateRingCommands r = do pushBack :: Ring -> Float -> Float -> Float -> IO () pushBack r x y z = do back <- readIORef $ rBack r - writeIORef (rBack r) (mod (back + 1) (fromIntegral $ ringCapacity r `div` 3)) + writeIORef (rBack r) (mod (back + 1) (ringCapacity r)) updateAttributes back $ do rPosition r @<- V3 x y z -- (fromList [x,y,z] :: Vector Float) sz <- readIORef (rSize r) putStrLn $ "pushBack "++show (sz,back,(x,y,z)) - when (sz < fromIntegral (ringCapacity r `div` 3)) $ do + when (sz < ringCapacity r) $ do writeIORef (rSize r) (sz + 1) updateRingCommands r -- cgit v1.2.3