From 6189b3bcb8e91f4ee28d46c3dbfbf99d5bd03c26 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 24 Jun 2018 00:43:09 +0200 Subject: [PATCH] smaller aesthetics --- src/Main.hs | 9 ++++++++- src/NPC.hs | 18 +++++++++--------- src/Test.hs | 2 +- src/Types/UserData.hs | 4 ++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 92da103..298c629 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -6,11 +6,14 @@ import Affection as A import qualified SDL import NanoVG hiding (V2(..), V3(..)) +import Graphics.Rendering.OpenGL.GL.FlushFinish (finish) import Linear import Foreign.C.Types (CInt(..)) +import Data.Maybe (fromJust) + -- internal imports import Types @@ -38,7 +41,7 @@ main = do , updateLoop = update , drawLoop = draw , loadState = Init.init - , cleanUp = const (return ()) + , cleanUp = clean , initScreenMode = SDL.Windowed } withAffection config @@ -81,3 +84,7 @@ exitOnWindowClose (MsgWindowClose _ _) = do liftIO $ logIO A.Debug "Window Closed" quit exitOnWindowClose _ = return () + +clean :: UserData -> IO () +clean ud = do + SDL.glDeleteContext $ fromJust $ threadContext ud diff --git a/src/NPC.hs b/src/NPC.hs index c2caa01..5ce3a53 100644 --- a/src/NPC.hs +++ b/src/NPC.hs @@ -10,7 +10,7 @@ import Data.List (find) import Control.Monad.IO.Class (MonadIO(..)) import Control.Concurrent.MVar -import Control.Concurrent (forkOS) +import Control.Concurrent (forkIO) import Linear @@ -118,19 +118,19 @@ updateNPCs -> SystemT Entity m () updateNPCs imgmat rp dt = emap allEnts $ do - with npcState + with npcMoveState with vel with pos with rot with anim - npcState' <- query npcState + npcState' <- query npcMoveState case npcState' of NPCStanding ttl future -> do let nttl = ttl - dt if nttl > 0 then return $ unchanged - { npcState = Set $ NPCStanding nttl future + { npcMoveState = Set $ NPCStanding nttl future , vel = Set $ V2 0 0 } else do @@ -138,11 +138,11 @@ updateNPCs imgmat rp dt = case mpath of Just path -> return $ unchanged - { npcState = Set $ NPCWalking path + { npcMoveState = Set $ NPCWalking path } Nothing -> return $ unchanged - { npcState = Set $ NPCStanding 1 future + { npcMoveState = Set $ NPCStanding 1 future } NPCWalking path -> do pos' <- query pos @@ -152,7 +152,7 @@ updateNPCs imgmat rp dt = if distance pos' itarget < 0.1 then return $ unchanged - { npcState = Set $ NPCWalking (tail path) + { npcMoveState = Set $ NPCWalking (tail path) } else return $ unchanged @@ -166,9 +166,9 @@ updateNPCs imgmat rp dt = let mdir = (pointDir <$> find (\a -> pointCoord a == fmap floor pos') rp) -- _ <- liftIO $ forkOS $ getPath (fmap floor pos') future rp imgmat - _ <- liftIO $ getPath (fmap floor pos') future rp imgmat + _ <- liftIO $ forkIO $ getPath (fmap floor pos') future rp imgmat return $ unchanged - { npcState = Set $ NPCStanding ttl future + { npcMoveState = Set $ NPCStanding ttl future , vel = Set $ V2 0 0 , rot = Set $ fromMaybe rot' mdir , anim = Set state diff --git a/src/Test.hs b/src/Test.hs index 57ac77e..0fbfa28 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -96,7 +96,7 @@ loadMapFork ud future progress = do , vel = Just (V2 0 0) , velFact = Just fact , rot = Just SE - , npcState = Just (NPCStanding 0 future) + , npcMoveState = Just (NPCStanding 0 future) , anim = Just $ AnimState (AnimId 1 "standing" SE) 0 0 } ) npcposs diff --git a/src/Types/UserData.hs b/src/Types/UserData.hs index 5b47fb6..3cc1b73 100644 --- a/src/Types/UserData.hs +++ b/src/Types/UserData.hs @@ -55,12 +55,12 @@ data Entity f = Entity , rot :: Component f 'Field Direction , obstacle :: Component f 'Field (Boundaries Double) , player :: Component f 'Unique () - , npcState :: Component f 'Field NPCState + , npcMoveState :: Component f 'Field NPCMoveState , anim :: Component f 'Field AnimState } deriving (Generic) -data NPCState +data NPCMoveState = NPCWalking { npcWalkPath :: [V2 Int] }