Dump some info to sdout when generating level
This commit is contained in:
+3
-1
@@ -56,8 +56,10 @@ firstWorldLoad theConfig = do
|
|||||||
SDL.cursorVisible $= False
|
SDL.cursorVisible $= False
|
||||||
theKeyConfig <- loadKeyConfig
|
theKeyConfig <- loadKeyConfig
|
||||||
pdata <- doPreload >>= applyWorldConfig theConfig
|
pdata <- doPreload >>= applyWorldConfig theConfig
|
||||||
w <- fmap ((keyConfig .~ theKeyConfig) . (config .~ theConfig)) firstWorld
|
w <- firstWorld
|
||||||
return $ w & preloadData .~ pdata
|
return $ w & preloadData .~ pdata
|
||||||
|
& keyConfig .~ theKeyConfig
|
||||||
|
& config .~ theConfig
|
||||||
|
|
||||||
theUpdateStep :: World -> IO World
|
theUpdateStep :: World -> IO World
|
||||||
theUpdateStep = doSideEffects <=< updateRenderSplit
|
theUpdateStep = doSideEffects <=< updateRenderSplit
|
||||||
|
|||||||
+32
-8
@@ -3,6 +3,7 @@
|
|||||||
The tree of rooms that make up a level. -}
|
The tree of rooms that make up a level. -}
|
||||||
module Dodge.Floor
|
module Dodge.Floor
|
||||||
( levx
|
( levx
|
||||||
|
, layoutLevel
|
||||||
) where
|
) where
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
@@ -23,17 +24,19 @@ import Dodge.Creature
|
|||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
import Dodge.Item.Weapon.Launcher
|
import Dodge.Item.Weapon.Launcher
|
||||||
import MonadHelp
|
import MonadHelp
|
||||||
|
import Data.Tree
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Control.Monad.Loops
|
import Control.Monad.Loops
|
||||||
import System.Random
|
import System.Random
|
||||||
{- | A test level tree. -}
|
import Data.Sequence hiding (zipWith)
|
||||||
initialRoomTree :: RandomGen g => State g (Maybe [Room])
|
import Data.Maybe
|
||||||
initialRoomTree = do
|
initialAnoTree :: RandomGen g => Tree [Annotation g]
|
||||||
|
initialAnoTree =
|
||||||
let struct = treeFromPost [[Corridor,SpecificRoom $ fmap (pure . Right) randomFourCornerRoom]] [EndRoom]
|
let struct = treeFromPost [[Corridor,SpecificRoom $ fmap (pure . Right) randomFourCornerRoom]] [EndRoom]
|
||||||
let t' = padCorridors struct
|
t' = padWithCorridors struct
|
||||||
t = treeFromTrunk
|
in treeFromTrunk
|
||||||
[[StartRoom]
|
[[StartRoom]
|
||||||
,[SpecificRoom spawnerRoom]
|
,[SpecificRoom spawnerRoom]
|
||||||
,[Corridor]
|
,[Corridor]
|
||||||
@@ -95,9 +98,30 @@ initialRoomTree = do
|
|||||||
,[TreasureAno [addArmour autoCrit,addArmour autoCrit] [launcher]]
|
,[TreasureAno [addArmour autoCrit,addArmour autoCrit] [launcher]]
|
||||||
]
|
]
|
||||||
t'
|
t'
|
||||||
shiftExpandTree . expandTreeBy id <$> mapM annoToRoomTree t
|
|
||||||
|
{- | A test level tree. -}
|
||||||
|
initialRoomTree :: RandomGen g => State g (Tree Room)
|
||||||
|
initialRoomTree = do
|
||||||
|
expandTreeBy id <$> mapM annoToRoomTree initialAnoTree
|
||||||
|
|
||||||
levx :: RandomGen g => Int -> State g ([Room] , Int)
|
levx :: RandomGen g => Int -> State g ([Room] , Int)
|
||||||
levx _ = untilJustCount initialRoomTree
|
levx _ = untilJustCount $ shiftExpandTree <$> initialRoomTree
|
||||||
|
|
||||||
|
|
||||||
|
layoutLevel :: Int -> IO [Room]
|
||||||
|
layoutLevel seed = do
|
||||||
|
putStrLn $ "Generating level with seed: " ++ show seed
|
||||||
|
let g = mkStdGen seed
|
||||||
|
let rmtree = evalState initialRoomTree g
|
||||||
|
mrs <- shiftRoomSearchIO [] (singleton rmtree)
|
||||||
|
case mrs of
|
||||||
|
Just rs -> return (fmap setLastLinkToUsed rs)
|
||||||
|
Nothing -> do
|
||||||
|
putStrLn "Level generation failed"
|
||||||
|
let (seed',_) = random g
|
||||||
|
layoutLevel seed'
|
||||||
|
where
|
||||||
|
setLastLinkToUsed rm = case _rmLinks rm of
|
||||||
|
(_:_) -> rm
|
||||||
|
& rmLinks %~ init
|
||||||
|
& rmUsedLinks %~ (last (_rmLinks rm) :)
|
||||||
|
_ -> rm
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ firstWorld :: IO World
|
|||||||
firstWorld = do
|
firstWorld = do
|
||||||
-- i <- randomRIO (0,5000)
|
-- i <- randomRIO (0,5000)
|
||||||
let i = 3
|
let i = 3
|
||||||
putStrLn $ "Seed for level generation: " ++ show ( i :: Int)
|
--putStrLn $ "Seed for level generation: " ++ show ( i :: Int)
|
||||||
let g = mkStdGen i
|
-- let g = mkStdGen i
|
||||||
(roomList,n) <- f g
|
-- (roomList,n) <- f g
|
||||||
putStrLn $ "Had to go through "++ show n ++ " random generators"
|
-- putStrLn $ "Had to go through "++ show n ++ " random generators"
|
||||||
return $ generateLevelFromRoomList roomList $ initialWorld {_randGen = g}
|
roomList <- layoutLevel i
|
||||||
|
return $ generateLevelFromRoomList roomList $ initialWorld -- note this uses a random generator defined elsewhere
|
||||||
where
|
where
|
||||||
f :: StdGen -> IO ([Room],Int)
|
f :: StdGen -> IO ([Room],Int)
|
||||||
f g = do
|
f g = do
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ addLock i t = do
|
|||||||
newBefore <- applyToRandomNode (Key i :) beforeLock
|
newBefore <- applyToRandomNode (Key i :) beforeLock
|
||||||
return $ addToTrunk newBefore [Node [Lock i] afterLock]
|
return $ addToTrunk newBefore [Node [Lock i] afterLock]
|
||||||
{- | Add one corridor between each parent-child link of a tree of annotations. -}
|
{- | Add one corridor between each parent-child link of a tree of annotations. -}
|
||||||
padCorridors :: Tree [Annotation g] -> Tree [Annotation g]
|
padWithCorridors :: Tree [Annotation g] -> Tree [Annotation g]
|
||||||
padCorridors (Node x xs) = Node [Corridor] [Node x (map padCorridors xs)]
|
padWithCorridors (Node x xs) = Node [Corridor] [Node x (map padWithCorridors xs)]
|
||||||
{- Add one to three corridors between each parent-child link of a tree of annotations. -}
|
{- Add one to three corridors between each parent-child link of a tree of annotations. -}
|
||||||
randomPadCorridors :: RandomGen g => Tree [Annotation g] -> State g (Tree [Annotation g])
|
randomPadCorridors :: RandomGen g => Tree [Annotation g] -> State g (Tree [Annotation g])
|
||||||
randomPadCorridors (Node x xs) = do
|
randomPadCorridors (Node x xs) = do
|
||||||
|
|||||||
@@ -6,17 +6,20 @@ Returns a list; after this step the structure is determined by the actual positi
|
|||||||
module Dodge.Layout.Tree.Shift
|
module Dodge.Layout.Tree.Shift
|
||||||
( shiftRoomTreeSearchAll
|
( shiftRoomTreeSearchAll
|
||||||
, shiftExpandTree
|
, shiftExpandTree
|
||||||
|
, shiftRoomSearchIO
|
||||||
) where
|
) where
|
||||||
import Dodge.Room.Data
|
import Dodge.Room.Data
|
||||||
import Dodge.Room.Link
|
import Dodge.Room.Link
|
||||||
import Dodge.Layout.Tree.Polymorphic
|
import Dodge.Layout.Tree.Polymorphic
|
||||||
import Geometry.ConvexPoly
|
import Geometry.ConvexPoly
|
||||||
|
import Geometry
|
||||||
|
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
import Data.Sequence hiding (zipWith)
|
import Data.Sequence hiding (zipWith)
|
||||||
import Data.List (delete)
|
import Data.List (delete)
|
||||||
import Data.Maybe (listToMaybe)
|
import Data.Maybe (listToMaybe)
|
||||||
import Control.Lens hiding (Empty, (<|) , (|>))
|
import Control.Lens hiding (Empty, (<|) , (|>))
|
||||||
|
|
||||||
{- | All: Depth first search of trees of rooms, produces a list of lists of rooms that are not clipping. -}
|
{- | All: Depth first search of trees of rooms, produces a list of lists of rooms that are not clipping. -}
|
||||||
shiftRoomTreeSearchAll
|
shiftRoomTreeSearchAll
|
||||||
:: [ConvexPoly] -- ^ Clipping bounds
|
:: [ConvexPoly] -- ^ Clipping bounds
|
||||||
@@ -40,6 +43,43 @@ shiftRoomTreeSearchAll bs (Node r ts :<| tseq)
|
|||||||
useLink l = r & rmLinks %~ delete l
|
useLink l = r & rmLinks %~ delete l
|
||||||
& rmUsedLinks %~ (l :)
|
& rmUsedLinks %~ (l :)
|
||||||
f l = applyToRoot (shiftRoomToLink l)
|
f l = applyToRoot (shiftRoomToLink l)
|
||||||
|
shiftRoomSearchIO
|
||||||
|
:: [ConvexPoly]
|
||||||
|
-> Seq (Tree Room)
|
||||||
|
-> IO (Maybe [Room])
|
||||||
|
shiftRoomSearchIO _ Empty = return (Just [])
|
||||||
|
shiftRoomSearchIO bs (Node r ts :<| tseq)
|
||||||
|
| roomIsClipping = do
|
||||||
|
putStrLn "Room clipping"
|
||||||
|
return Nothing
|
||||||
|
| otherwise = fmap (fmap (r:)) $ placeLinkedRooms newBounds r ts tseq
|
||||||
|
where
|
||||||
|
convexBounds = map pointsToPoly $ _rmBound r
|
||||||
|
newBounds = convexBounds ++ bs
|
||||||
|
roomIsClipping = or (convexPolysOverlap <$> convexBounds <*> bs)
|
||||||
|
placeLinkedRooms :: [ConvexPoly] -> Room -> [Tree Room] -> (Seq (Tree Room)) -> IO (Maybe [Room])
|
||||||
|
placeLinkedRooms bs _ [] tseq
|
||||||
|
= shiftRoomSearchIO bs tseq
|
||||||
|
placeLinkedRooms bs r (t:ts) tseq
|
||||||
|
= tryLinks ls bs r t ts tseq
|
||||||
|
where
|
||||||
|
ls = init $ _rmLinks r
|
||||||
|
|
||||||
|
tryLinks :: [(Point2,Float)] -> [ConvexPoly] -> Room -> Tree Room -> [Tree Room] -> (Seq (Tree Room))
|
||||||
|
-> IO (Maybe [Room])
|
||||||
|
tryLinks [] _ _ _ _ _ = do
|
||||||
|
putStrLn "Tried all links"
|
||||||
|
return Nothing
|
||||||
|
tryLinks (l:ls) bs r t ts tseq = do
|
||||||
|
branch <- placeLinkedRooms bs useLink ts (tseq |> shiftedt)
|
||||||
|
case branch of
|
||||||
|
Nothing -> tryLinks ls bs r t ts tseq
|
||||||
|
Just rs -> return $ Just rs
|
||||||
|
where
|
||||||
|
useLink = r & rmLinks %~ delete l
|
||||||
|
& rmUsedLinks %~ (l :)
|
||||||
|
shiftedt = applyToRoot (shiftRoomToLink l) t
|
||||||
|
|
||||||
{- |
|
{- |
|
||||||
Depth first search of trees of rooms, maybe produces a list rooms that are not clipping.
|
Depth first search of trees of rooms, maybe produces a list rooms that are not clipping.
|
||||||
-}
|
-}
|
||||||
|
|||||||
+3
-5
@@ -12,15 +12,13 @@ import Dodge.Config.Data
|
|||||||
import Dodge.Config.Update
|
import Dodge.Config.Update
|
||||||
import SDL
|
import SDL
|
||||||
import SDL.Internal.Numbered
|
import SDL.Internal.Numbered
|
||||||
--import Dodge.Layout
|
|
||||||
--import Dodge.Floor
|
|
||||||
import Dodge.Initialisation
|
import Dodge.Initialisation
|
||||||
import Preload.Update
|
import Preload.Update
|
||||||
import Dodge.Base.Window
|
import Dodge.Base.Window
|
||||||
import Dodge.SoundLogic
|
import Dodge.SoundLogic
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
--import Control.Monad.State
|
|
||||||
optionMenu :: ScreenLayer
|
optionMenu :: ScreenLayer
|
||||||
optionMenu = OptionScreen
|
optionMenu = OptionScreen
|
||||||
{ _scTitle = const "OPTIONS"
|
{ _scTitle = const "OPTIONS"
|
||||||
@@ -53,7 +51,8 @@ debugMenuOptions =
|
|||||||
, doption ScancodeP debug_pathing "SHOW PATHING" _debug_pathing
|
, doption ScancodeP debug_pathing "SHOW PATHING" _debug_pathing
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
doption scode l t rec = Toggle scode (Just . (config . l %~ not)) (\w -> t ++ ":" ++ show (rec $ _config w))
|
doption scode l t rec
|
||||||
|
= Toggle scode (Just . (config . l %~ not)) (\w -> t ++ ":" ++ show (rec $ _config w))
|
||||||
gameplayMenu :: ScreenLayer
|
gameplayMenu :: ScreenLayer
|
||||||
gameplayMenu = OptionScreen
|
gameplayMenu = OptionScreen
|
||||||
{ _scTitle = const "OPTIONS:GAMEPLAY"
|
{ _scTitle = const "OPTIONS:GAMEPLAY"
|
||||||
@@ -160,7 +159,6 @@ pauseMenuOptions =
|
|||||||
startNewGame :: World -> Maybe World
|
startNewGame :: World -> Maybe World
|
||||||
startNewGame w = Just $ w
|
startNewGame w = Just $ w
|
||||||
& menuLayers .~ [WaitScreen (const "GENERATING...") 1]
|
& menuLayers .~ [WaitScreen (const "GENERATING...") 1]
|
||||||
-- & worldEvents .~ const aNewGame
|
|
||||||
& sideEffects .~ const (firstWorld <&> keyConfig .~ _keyConfig w <&> config .~ _config w
|
& sideEffects .~ const (firstWorld <&> keyConfig .~ _keyConfig w <&> config .~ _config w
|
||||||
<&> preloadData .~ _preloadData w) -- this kills save games etc...
|
<&> preloadData .~ _preloadData w) -- this kills save games etc...
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user