trying hard to make it better

This commit is contained in:
nek0 2016-12-20 11:29:03 +01:00
parent a1b0b50b57
commit 179e2f9516
3 changed files with 51 additions and 19 deletions

View file

@ -116,16 +116,17 @@ load _ = do
draw :: Affection UserData () draw :: Affection UserData ()
draw = do draw = do
traceM "drawing" traceM "drawing"
AffectionData{..} <- get UserData{..} <- getAffection
let UserData{..} = userState -- AffectionData{..} <- get
liftIO $ SDL.lockSurface drawSurface -- let UserData{..} = userState
pixels <- liftIO $ SDL.surfacePixels drawSurface -- -- liftIO $ SDL.lockSurface drawSurface
let SDL.Surface rawSurfacePtr _ = drawSurface -- pixels <- liftIO $ SDL.surfacePixels drawSurface
rawSurface <- liftIO $ peek rawSurfacePtr -- let SDL.Surface rawSurfacePtr _ = drawSurface
pixelFormat <- liftIO $ peek $ Raw.surfaceFormat rawSurface -- rawSurface <- liftIO $ peek rawSurfacePtr
format <- liftIO $ (B.babl_format $ B.PixelFormat B.RGBA B.CFu8) -- pixelFormat <- liftIO $ peek $ Raw.surfaceFormat rawSurface
SDL.V2 (CInt rw) (CInt rh) <- SDL.surfaceDimensions drawSurface -- format <- liftIO $ (B.babl_format $ B.PixelFormat B.RGBA B.CFu8)
let (w, h) = (fromIntegral rw, fromIntegral rh) -- SDL.V2 (CInt rw) (CInt rh) <- SDL.surfaceDimensions drawSurface
-- let (w, h) = (fromIntegral rw, fromIntegral rh)
drawRect foreground (nodeGraph M.! "over") (G.RGB 1 0 0) (Line 2) (G.GeglRectangle 10 10 500 500) drawRect foreground (nodeGraph M.! "over") (G.RGB 1 0 0) (Line 2) (G.GeglRectangle 10 10 500 500)
-- liftIO $ G.gegl_node_blit -- liftIO $ G.gegl_node_blit
-- (nodeGraph M.! "over" :: G.GeglNode) -- (nodeGraph M.! "over" :: G.GeglNode)
@ -135,8 +136,8 @@ draw = do
-- pixels -- pixels
-- (fromIntegral (Raw.pixelFormatBytesPerPixel pixelFormat) * w) -- (fromIntegral (Raw.pixelFormatBytesPerPixel pixelFormat) * w)
-- [G.GeglBlitDefault] -- [G.GeglBlitDefault]
liftIO $ SDL.unlockSurface drawSurface -- liftIO $ SDL.unlockSurface drawSurface
liftIO $ SDL.updateWindowSurface drawWindow -- liftIO $ SDL.updateWindowSurface drawWindow
update :: Double -> AffectionState (AffectionData UserData) IO () update :: Double -> AffectionState (AffectionData UserData) IO ()
update sec = do update sec = do

View file

@ -117,9 +117,9 @@ update sec = do
{ psParts = (Particle { psParts = (Particle
{ particleLife = life { particleLife = life
, particlePosition = (fromIntegral x, fromIntegral y) , particlePosition = (fromIntegral x, fromIntegral y)
, particleRotation = 0 , particleRotation = Rad 0
, particleVelocity = (vx, vy) , particleVelocity = (vx, vy)
, particlePitchRate = 0 , particlePitchRate = Rad 0
}) : (psParts $ partsys ud) }) : (psParts $ partsys ud)
} }
} }

View file

@ -13,6 +13,8 @@ module Affection.Types
, RGBA(..) , RGBA(..)
, DrawType(..) , DrawType(..)
, DrawRequest(..) , DrawRequest(..)
, Angle(..)
, ConvertAngle(..)
-- | Particle system -- | Particle system
, Particle(..) , Particle(..)
, ParticleSystem(..) , ParticleSystem(..)
@ -126,13 +128,42 @@ data DrawType
{ lineWidth :: Int -- ^ Width of line in pixels { lineWidth :: Int -- ^ Width of line in pixels
} }
-- | Type for defining angles
data Angle
= Rad Double -- ^ Angle in radians
| Deg Double -- ^ Angle in degrees
deriving (Show)
-- | Typeclass for converting Angles from 'Deg' to 'Rad' and vice versa.
class ConvertAngle a where
toRad :: a -> a -- Convert to 'Rad'
toDeg :: a -> a -- Convert to 'Deg'
instance ConvertAngle Angle where
toRad (Deg x) = Rad $ x * pi / 180
toRad x = x
toDeg (Rad x) = Deg $ x * 180 / pi
toDeg x = x
instance Eq Angle where
(==) (Deg x) (Deg y) = x == y
(==) (Rad x) (Rad y) = x == y
(==) dx@(Deg _) ry@(Rad _) = dx == toDeg ry
(==) rx@(Rad _) dy@(Deg _) = toDeg rx == dy
-- | A single particle -- | A single particle
data Particle = Particle data Particle = Particle
{ particleLife :: Double -- ^ Time to live in seconds { particleLife :: Double
, particlePosition :: (Double, Double) -- ^ Position of particle on canvas -- ^ Time to live in seconds
, particleRotation :: Double -- ^ Particle rotation , particlePosition :: (Double, Double)
, particleVelocity :: (Int, Int) -- ^ particle velocity as vector of pixels per second -- ^ Position of particle on canvas
, particlePitchRate :: Double -- ^ Rotational velocity of particle , particleRotation :: Angle
-- ^ Particle rotation
, particleVelocity :: (Int, Int)
-- ^ particle velocity as vector of pixels per second
, particlePitchRate :: Angle
-- ^ Rotational velocity of particle in angle per second
} deriving (Show, Eq) } deriving (Show, Eq)
data ParticleSystem = ParticleSystem data ParticleSystem = ParticleSystem