dusting off

This commit is contained in:
nek0 2017-11-27 02:18:23 +01:00
parent 1bb1af935b
commit 6e11ff9b1e
6 changed files with 12 additions and 73 deletions

View file

@ -36,18 +36,12 @@ flag examples
library library
exposed-modules: Affection exposed-modules: Affection
-- , Affection.Draw
-- , Affection.Particle
, Affection.Types , Affection.Types
, Affection.StateMachine , Affection.StateMachine
, Affection.MouseInteractable , Affection.MouseInteractable
-- , Affection.Property
-- , Affection.Actor
-- , Affection.Animation
, Affection.Util , Affection.Util
, Affection.MessageBus.Util , Affection.MessageBus.Util
, Affection.MessageBus.Class , Affection.MessageBus.Class
, Affection.MessageBus.Engine
, Affection.MessageBus.Message , Affection.MessageBus.Message
default-extensions: OverloadedStrings default-extensions: OverloadedStrings
@ -69,8 +63,6 @@ library
, text , text
, mtl , mtl
, time , time
-- , gegl
-- , babl
, monad-loops , monad-loops
, monad-parallel , monad-parallel
, containers , containers
@ -79,7 +71,6 @@ library
, bytestring , bytestring
, OpenGL , OpenGL
, stm , stm
-- , sdl2-image
-- executable example00 -- executable example00
-- hs-source-dirs: examples -- hs-source-dirs: examples

View file

@ -5,8 +5,6 @@ module Affection
, get , get
, getAffection , getAffection
, putAffection , putAffection
-- , withWindow
-- , withDefaultWindow
, delaySec , delaySec
, get , get
, put , put
@ -17,7 +15,6 @@ import SDL (($=))
import qualified SDL import qualified SDL
import qualified SDL.Internal.Numbered as SDL (toNumber) import qualified SDL.Internal.Numbered as SDL (toNumber)
import qualified SDL.Raw as Raw import qualified SDL.Raw as Raw
-- import qualified GEGL as G
import Data.Maybe import Data.Maybe
import Data.IORef import Data.IORef
@ -33,22 +30,13 @@ import Foreign.Storable (peek)
import Debug.Trace import Debug.Trace
import Affection.Types as A import Affection.Types as A
-- import Affection.Draw as A
-- import Affection.Particle as A
import Affection.StateMachine as A import Affection.StateMachine as A
import Affection.MouseInteractable as A import Affection.MouseInteractable as A
-- import Affection.Property as A
-- import Affection.Actor as A
-- import Affection.Animation as A
import Affection.Util as A import Affection.Util as A
import Affection.MessageBus.Class as A import Affection.MessageBus as A
import Affection.MessageBus.Message as A
import Affection.MessageBus.Engine as A
import Affection.MessageBus.Util as A
import Graphics.Rendering.OpenGL as GL (clear, flush, ClearBuffer(..)) import Graphics.Rendering.OpenGL as GL (clear, flush, ClearBuffer(..))
-- import qualified BABL as B
-- | Main function which bootstraps everything else. -- | Main function which bootstraps everything else.
withAffection withAffection
@ -61,7 +49,6 @@ withAffection AffectionConfig{..} = do
SDL.initializeAll SDL.initializeAll
Only is -> Only is ->
SDL.initialize is SDL.initialize is
-- G.gegl_init
-- give SDL render quality -- give SDL render quality
SDL.HintRenderScaleQuality SDL.$= SDL.ScaleLinear SDL.HintRenderScaleQuality SDL.$= SDL.ScaleLinear
-- just checking… -- just checking…
@ -73,54 +60,23 @@ withAffection AffectionConfig{..} = do
window <- SDL.createWindow windowTitle windowConfig window <- SDL.createWindow windowTitle windowConfig
SDL.showWindow window SDL.showWindow window
context <- SDL.glCreateContext(window) context <- SDL.glCreateContext(window)
-- -- create renderer
-- renderer <- SDL.createRenderer
-- window
-- (-1)
-- SDL.defaultRenderer
-- -- make draw texture
-- texture <- SDL.createTexture
-- renderer
-- SDL.ABGR8888
-- SDL.TextureAccessStreaming
-- (case canvasSize of
-- Just (cw, ch) -> (SDL.V2
-- (CInt $ fromIntegral cw)
-- (CInt $ fromIntegral ch)
-- )
-- Nothing ->
-- SDL.windowInitialSize windowConfig
-- )
-- -- make draw surface
-- -- pixelFormat <- liftIO $ peek . Raw.surfaceFormat =<< peek ptr
let SDL.V2 (CInt rw) (CInt rh) = SDL.windowInitialSize windowConfig let SDL.V2 (CInt rw) (CInt rh) = SDL.windowInitialSize windowConfig
(w, h) = case canvasSize of (w, h) = case canvasSize of
Just (cw, ch) -> (cw, ch) Just (cw, ch) -> (cw, ch)
Nothing -> (fromIntegral rw, fromIntegral rh) Nothing -> (fromIntegral rw, fromIntegral rh)
-- -- stride = fromIntegral (Raw.pixelFormatBytesPerPixel pixelFormat) * w
-- bablFormat = B.PixelFormat B.RGBA B.CFu8
-- cpp = B.babl_components_per_pixel bablFormat
-- !stride = cpp * w
-- format <- B.babl_format bablFormat
-- get current time
SDL.setWindowMode window initScreenMode SDL.setWindowMode window initScreenMode
SDL.swapInterval $= SDL.SynchronizedUpdates SDL.swapInterval $= SDL.SynchronizedUpdates
-- get current time
execTime <- getTime Monotonic execTime <- getTime Monotonic
initContainer <- (\x -> AffectionData initContainer <- (\x -> AffectionData
{ quitEvent = False { quitEvent = False
, userState = x , userState = x
, drawWindow = window , drawWindow = window
, glContext = context , glContext = context
-- , windowRenderer = renderer
-- , drawTexture = texture
-- , drawFormat = format
, drawDimensions = case canvasSize of , drawDimensions = case canvasSize of
Just (cw, ch) -> (cw, ch) Just (cw, ch) -> (cw, ch)
Nothing -> (w, h) Nothing -> (w, h)
, screenMode = initScreenMode , screenMode = initScreenMode
-- , drawStride = stride
-- , drawCPP = cpp
-- , drawStack = []
, elapsedTime = 0 , elapsedTime = 0
, deltaTime = 0 , deltaTime = 0
, sysTime = execTime , sysTime = execTime
@ -138,15 +94,10 @@ withAffection AffectionConfig{..} = do
-- Measure time difference form last run -- Measure time difference form last run
now <- liftIO $ getTime Monotonic now <- liftIO $ getTime Monotonic
let lastTime = sysTime ad let lastTime = sysTime ad
-- -- clean draw requests from last run
-- MP.mapM_ (invalidateDrawRequest (drawStride ad) (drawCPP ad)) (drawStack ad)
-- clean the renderer form last time
-- SDL.clear renderer
-- compute dt and update elapsedTime -- compute dt and update elapsedTime
let !dt = fromIntegral (toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ 9) let !dt = fromIntegral (toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ 9)
!ne = elapsedTime ad + dt !ne = elapsedTime ad + dt
put $ ad put $ ad
-- { drawStack = []
{ elapsedTime = ne { elapsedTime = ne
, deltaTime = dt , deltaTime = dt
} }
@ -161,14 +112,8 @@ withAffection AffectionConfig{..} = do
liftIO $ flush liftIO $ flush
-- handle all new draw requests -- handle all new draw requests
ad2 <- get ad2 <- get
-- clear <- catMaybes <$>
-- mapM (handleDrawRequest (drawStride ad) (drawCPP ad)) (drawStack ad2)
-- -- save all draw requests to clear in next run
-- put $ ad2
-- { drawStack = clear }
-- actual drawing -- actual drawing
SDL.glSwapWindow window SDL.glSwapWindow window
-- SDL.present (windowRenderer ad2)
-- save new time -- save new time
ad3 <- get ad3 <- get
when (sysTime ad == sysTime ad3) ( when (sysTime ad == sysTime ad3) (
@ -178,7 +123,6 @@ withAffection AffectionConfig{..} = do
) )
) )
) initContainer ) initContainer
-- G.gegl_exit
cleanUp $ userState nState cleanUp $ userState nState
SDL.destroyWindow window SDL.destroyWindow window
SDL.quit SDL.quit

View file

@ -0,0 +1,7 @@
module Affection.Messagebus
( module M
) where
import Affection.MessageBus.Class as M
import Affection.MessageBus.Message as M
import Affection.MessageBus.Util as M

View file

@ -16,4 +16,4 @@ class (Message msg) => Participant prt msg where
partListen :: prt -> IO msg partListen :: prt -> IO msg
partBroadcast :: prt -> msg -> IO () partEmit :: prt -> msg -> IO ()

View file

@ -1,3 +0,0 @@
module Affection.MessageBus.Engine where
import Affection.MessageBus.Class

View file

@ -6,13 +6,13 @@ import Data.Time.Clock (UTCTime(..))
class Message msg where class Message msg where
msgTime :: msg -> UTCTime msgTime :: msg -> UTCTime
data EngineMessage m data SystemMessage m
= MsgUserMessage = MsgUserMessage
{ msgPayload :: m { msgPayload :: m
, msgWhen :: UTCTime , msgWhen :: UTCTime
} -- ^ Generic user defined message with custom payload } -- ^ Generic user defined message with custom payload
| MsgEngineReady UTCTime | MsgEngineReady UTCTime
instance Message (EngineMessage m) where instance Message (SystemMessage m) where
msgTime (MsgUserMessage _ t) = t msgTime (MsgUserMessage _ t) = t
msgTime (MsgEngineReady t) = t msgTime (MsgEngineReady t) = t