Work on debugging

This commit is contained in:
2023-04-27 11:35:48 +01:00
parent 35990c53bf
commit 9972e0fdea
17 changed files with 39 additions and 28 deletions
-2
View File
@@ -35,10 +35,8 @@ data RenderData = RenderData
, _fboBloom :: (FBO, TO)
, _fboPos :: (FBO, TO)
, _fboLighting :: (FBO, TO)
-- , _fboShadow :: (FBO, (TO, TO))
, _rboBaseBloom :: GLuint -- RenderbufferObject id
, _matUBO :: GLuint -- BufferObject id
-- , _orthonormalMatUBO :: GLuint -- BufferObject id
, _lightsUBO :: GLuint -- BufferObject id
, _vboWindows :: VBO
, _vboShapes :: VBO
+2 -2
View File
@@ -92,8 +92,8 @@ performTurnToA cr p
dirv = p -.- cpos
jit = _mvTurnJit $ _crMvType cr
{- | Performing an action means that a creature has some impulses for a frame, and
updates or deletes the action itself.
{- | Performing an action on a frame creates an OutAction:
adds impulses and updates or deletes the action itself.
-}
performAction :: Creature -> World -> Action -> OutAction
performAction cr w ac = case ac of
+2 -1
View File
@@ -3,6 +3,7 @@ module Dodge.Creature.SetTarget where
import Control.Lens
import Dodge.Data.World
--import MaybeHelp
-- | Assumes that you are id 0: if creature is cognizant of you, sets you as target
targetYouWhenCognizant ::
@@ -11,5 +12,5 @@ targetYouWhenCognizant ::
Creature
targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of
--Just (Cognizant _) -> cr & crIntention . targetCr ?~ _creatures (_cWorld w) IM.! 0
Just (Cognizant _) -> cr & crIntention . targetCr ?~ (w ^?! cWorld . lWorld . creatures . ix 0)
Just (Cognizant _) -> cr & crIntention . targetCr .~ Just (w ^?! cWorld . lWorld . creatures . ix 0)
_ -> cr & crIntention . targetCr .~ Nothing
+1
View File
@@ -24,6 +24,7 @@ module Dodge.Creature.Test (
crSafeDistFromTarg,
) where
--import MaybeHelp
import Control.Lens
import Data.List (find)
import Data.Maybe
+4 -4
View File
@@ -16,10 +16,10 @@ import Sound.Data
data ActionPlan
= Inanimate
| ActionPlan
{ _apImpulse :: [Impulse]
, _apAction :: [Action]
, _apStrategy :: Strategy
, _apGoal :: [Goal]
{ _apImpulse :: [Impulse] -- done per frame
, _apAction :: [Action] -- updated per frame, likely persist across frames
, _apStrategy :: Strategy -- current strategy
, _apGoal :: [Goal] -- particular ordered goals
}
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
deriving (Eq, Ord, Show) --Generic, Flat)
+1
View File
@@ -32,6 +32,7 @@ import Dodge.Data.Item
import Dodge.Data.Material
import Geometry.Data
import qualified IntMapHelp as IM
--import MaybeHelp
data Creature = Creature
{ _crPos :: Point2
+1
View File
@@ -25,6 +25,7 @@ data Input = Input
, _smoothScrollAmount :: Int
, _clickPos :: M.Map MouseButton Point2 -- updates on initial mouse button press
, _heldPos :: M.Map MouseButton Point2 -- updates while mouse button is held, lags one frame
, _clickWorldPos :: M.Map MouseButton Point2 -- updates on initial mouse button press
, _textInput :: [Either TermSignal Char]
, _scrollTestFloat :: Float
, _scrollTestInt :: Int
+7 -13
View File
@@ -45,21 +45,15 @@ data Universe = Universe
data DebugItem = DebugItem
{ _debugPic :: Picture
, _debugInfo :: [DebugMessage]
, _debugMessage :: [String]
, _debugInfo :: DebugInfo
}
data DebugMessage
= DebugSimpleMessage
{ _debugMessage :: [String]
}
| DebugWorldPosMessage
{ _debugWorldPos :: V3 Float
, _debugMessage :: [String]
}
| DebugScreenPosMessage
{ _debugScreenPos :: V2 Float
, _debugMessage :: [String]
}
data DebugInfo
= NoDebugInfo
| DebugV3 { _debugV3 :: V3 Float}
| DebugV2 { _debugV2 :: V2 Float}
| DebugMInt { _debugMInt :: Maybe Int}
data SideEffect
= NewSideEffect
+3 -2
View File
@@ -7,7 +7,7 @@ import qualified Data.Set as S
debugEvents :: Universe -> Universe
debugEvents u = case dbools ^. at Enable_debug of
Nothing -> u
Nothing -> u
Just () -> S.foldr debugEvent u dbools
where
dbools = u ^. uvConfig . debug_booleans
@@ -20,5 +20,6 @@ debugEvent db u = case db of
collisionDebugItem :: Universe -> DebugItem
collisionDebugItem u = DebugItem
{ _debugPic = drawCollisionTest $ u ^. uvWorld
, _debugInfo = []
, _debugMessage = ["Collision test:","asdf"]
, _debugInfo = NoDebugInfo
}
+3 -2
View File
@@ -102,8 +102,9 @@ intersectLinefromScreen cfig w a b =
drawCollisionTest :: World -> Picture
drawCollisionTest w = fromMaybe mempty $ do
a <- w ^. input . clickPos . at ButtonLeft
b <- w ^. input . clickPos . at ButtonRight
-- let f = fmap (screenToWorldPos (w ^. wCam))
a <- w ^. input . clickWorldPos . at ButtonLeft
b <- w ^. input . clickWorldPos . at ButtonRight
return $
setLayer DebugLayer (color orange $ line [a, b])
<> foldMap (drawCross . fst) (crHit a b w)
+1
View File
@@ -7,6 +7,7 @@ import Dodge.Data.FloatFunction
import Geometry.Data
import qualified IntMapHelp as IM
import Picture
--import MaybeHelp
defaultCreature :: Creature
defaultCreature =
+1
View File
@@ -14,6 +14,7 @@ defaultInput :: Input
defaultInput =
Input
{ _clickPos = mempty
, _clickWorldPos = mempty
, _heldPos = mempty
, _textInput = mempty
, _pressedKeys = mempty
-1
View File
@@ -1,5 +1,4 @@
{- | Capture input events, store them in structures for later use.
Should not update the world other than this.
-}
module Dodge.Event.Input (
handleKeyboardEvent,
+4
View File
@@ -2,6 +2,7 @@ module Dodge.Render.ShapePicture (
worldSPic,
) where
import Dodge.Render.List
import Control.Lens
import Control.Monad (guard)
import Data.Foldable
@@ -139,6 +140,9 @@ extraPics cfig u =
<> concatMapPic ppDraw (_pressPlates lw)
<> viewClipBounds cfig w
<> debugDraw cfig w
<> foldMap _debugPic (_uvDebug u)
<> setLayer FixedCoordLayer
(listPicturesAt (1.3 * halfWidth cfig) 0 cfig (map text (foldMap _debugMessage (_uvDebug u))))
where
w = u ^. uvWorld
lw = w ^. cWorld . lWorld
+1 -1
View File
@@ -45,7 +45,7 @@ writeSaveSlot ss u = do
readSaveSlot :: SaveSlot -> IO (Universe -> Maybe Universe)
readSaveSlot ss = do
fExists <- doesFileExist $ saveSlotPath ss
when (not fExists) $ error "Tried to read non-existant save file"
unless fExists $ error "Tried to read non-existant save file"
mcw <- decodeFileStrict $ saveSlotPath ss
flip (maybe (error "Tried to read incorrectly encoded save file")) mcw $ \cw ->
return $ \uv -> Just
+6
View File
@@ -83,10 +83,16 @@ updateUniverse u =
updateUniverseFirst :: Universe -> Universe
updateUniverseFirst u =
u
& uvWorld . input . clickWorldPos %~ M.union (setClickWorldPos u)
& uvWorld . input . smoothScrollAmount %~ calcSmoothScroll (u ^. uvWorld . input . scrollAmount)
& over (uvWorld . input) updateScrollTestValue
& over (uvWorld . cWorld . cClock) (+ 1)
setClickWorldPos :: Universe -> M.Map MouseButton Point2
setClickWorldPos u = fmap
(const (screenToWorldPos (u ^. uvWorld . wCam) (u ^. uvWorld . input . mousePos)))
(M.filter (== 1) $ u ^. uvWorld . input . mouseButtons)
updateWorldEventFlags :: Universe -> Universe
updateWorldEventFlags u =
(uvWorld . worldEventFlags .~ mempty)
+2
View File
@@ -19,6 +19,8 @@ data Maybe' a = Just' {__Just' :: a} | Nothing'
--
--instance FromJSON a => FromJSON (Maybe' a)
--maybe' :: b -> (a -> b) -> Maybe' a -> b
fromJust' :: Maybe' a -> a
fromJust' mx = case mx of
Just' x -> x