Fix bug determining max radius of convex polys, fixes bugs in room positioning
This commit is contained in:
@@ -22,6 +22,7 @@ data Configuration = Configuration
|
|||||||
, _debug_noclip :: Bool
|
, _debug_noclip :: Bool
|
||||||
, _debug_cr_status :: Bool
|
, _debug_cr_status :: Bool
|
||||||
, _debug_view_boundaries :: Bool
|
, _debug_view_boundaries :: Bool
|
||||||
|
, _debug_view_clip_bounds :: Bool
|
||||||
, _debug_pathing :: Bool
|
, _debug_pathing :: Bool
|
||||||
}
|
}
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
@@ -61,5 +62,6 @@ defaultConfig = Configuration
|
|||||||
, _debug_noclip = False
|
, _debug_noclip = False
|
||||||
, _debug_cr_status = False
|
, _debug_cr_status = False
|
||||||
, _debug_view_boundaries = False
|
, _debug_view_boundaries = False
|
||||||
|
, _debug_view_clip_bounds = False
|
||||||
, _debug_pathing = False
|
, _debug_pathing = False
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import Data.Preload
|
|||||||
import Picture.Data
|
import Picture.Data
|
||||||
import ShapePicture
|
import ShapePicture
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
|
import Geometry.ConvexPoly
|
||||||
import Sound.Data
|
import Sound.Data
|
||||||
import Dodge.GameRoom
|
import Dodge.GameRoom
|
||||||
import Color
|
import Color
|
||||||
@@ -120,6 +121,7 @@ data World = World
|
|||||||
, _distortions :: [Distortion]
|
, _distortions :: [Distortion]
|
||||||
, _worldBounds :: Bounds
|
, _worldBounds :: Bounds
|
||||||
, _gameRooms :: [GameRoom] -- consider using an IntMap
|
, _gameRooms :: [GameRoom] -- consider using an IntMap
|
||||||
|
, _roomClipping :: [ConvexPoly]
|
||||||
, _maybeWorld :: Maybe' World
|
, _maybeWorld :: Maybe' World
|
||||||
, _rewindWorlds :: [World]
|
, _rewindWorlds :: [World]
|
||||||
, _timeFlow :: TimeFlowStatus
|
, _timeFlow :: TimeFlowStatus
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ defaultWorld = World
|
|||||||
, _foregroundShape = mempty
|
, _foregroundShape = mempty
|
||||||
, _distortions = []
|
, _distortions = []
|
||||||
, _gameRooms = []
|
, _gameRooms = []
|
||||||
|
, _roomClipping = []
|
||||||
, _worldClock = 0
|
, _worldClock = 0
|
||||||
, _worldBounds = defaultBounds
|
, _worldBounds = defaultBounds
|
||||||
, _maybeWorld = Nothing'
|
, _maybeWorld = Nothing'
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import Dodge.Creature
|
|||||||
import Dodge.WorldEvent.Cloud
|
import Dodge.WorldEvent.Cloud
|
||||||
import Dodge.SoundLogic
|
import Dodge.SoundLogic
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
|
import Geometry.ConvexPoly
|
||||||
|
|
||||||
import System.Random
|
import System.Random
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
@@ -42,4 +43,7 @@ initialWorld = defaultWorld
|
|||||||
|
|
||||||
testStringInit :: World -> [String]
|
testStringInit :: World -> [String]
|
||||||
--testStringInit = map (concatMap $ \(_,ct,_,_) -> show ct) . invertListInvMult . yourInv
|
--testStringInit = map (concatMap $ \(_,ct,_,_) -> show ct) . invertListInvMult . yourInv
|
||||||
testStringInit = const []
|
testStringInit w = [show $ f $ _roomClipping w]
|
||||||
|
where
|
||||||
|
f (x:xs) = any (convexPolysOverlap x) xs || f xs
|
||||||
|
f [] = False
|
||||||
|
|||||||
@@ -9,21 +9,23 @@ import Dodge.Initialisation
|
|||||||
--import Dodge.RandomHelp
|
--import Dodge.RandomHelp
|
||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
import Dodge.Tree
|
import Dodge.Tree
|
||||||
|
import Geometry.ConvexPoly
|
||||||
--import Dodge.LevelGen.LevelStructure
|
--import Dodge.LevelGen.LevelStructure
|
||||||
|
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
import System.Random
|
import System.Random
|
||||||
--import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
|
|
||||||
generateWorldFromSeed :: Int -> IO World
|
generateWorldFromSeed :: Int -> IO World
|
||||||
generateWorldFromSeed i = do
|
generateWorldFromSeed i = do
|
||||||
roomList <- layoutLevelFromSeed 0 i
|
(roomList,bounds) <- layoutLevelFromSeed 0 i
|
||||||
return $ saveLevelStartSlot $ _gWorld $ generateLevelFromRoomList roomList
|
return $ saveLevelStartSlot $ (_gWorld $ generateLevelFromRoomList roomList
|
||||||
initialWorld{_randGen=mkStdGen i}
|
initialWorld{_randGen=mkStdGen i})
|
||||||
|
& roomClipping .~ bounds
|
||||||
|
|
||||||
layoutLevelFromSeed :: Int -> Int -> IO (IM.IntMap Room)
|
layoutLevelFromSeed :: Int -> Int -> IO (IM.IntMap Room,[ConvexPoly])
|
||||||
layoutLevelFromSeed i seed = do
|
layoutLevelFromSeed i seed = do
|
||||||
let i' = i + 1
|
let i' = i + 1
|
||||||
putStrLn $ "Generating level with seed " ++ show seed
|
putStrLn $ "Generating level with seed " ++ show seed
|
||||||
@@ -36,13 +38,13 @@ layoutLevelFromSeed i seed = do
|
|||||||
putStrLn "Layout with room names written to aGeneratedRoomLayout"
|
putStrLn "Layout with room names written to aGeneratedRoomLayout"
|
||||||
mrs <- positionRoomsFromTree rmtree
|
mrs <- positionRoomsFromTree rmtree
|
||||||
case mrs of
|
case mrs of
|
||||||
Just rs -> do
|
Just (PosRooms bounds rs) -> do
|
||||||
putStrLn $ "After " ++ show i'
|
putStrLn $ "After " ++ show i'
|
||||||
++ " attempt(s), Successful generation of level with seed "
|
++ " attempt(s), Successful generation of level with seed "
|
||||||
++ show seed
|
++ show seed
|
||||||
--return (fmap setLastLinkToUsed rs)
|
--return (fmap setLastLinkToUsed rs)
|
||||||
putStrLn $ show (Prelude.length rs) ++ " rooms in total"
|
putStrLn $ show (Prelude.length rs) ++ " rooms in total"
|
||||||
return . IM.fromList $ map reversePair rs
|
return (IM.fromList $ map reversePair rs , bounds)
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
putStr $ "Level generation with seed " ++ show seed ++ " failed: "
|
putStr $ "Level generation with seed " ++ show seed ++ " failed: "
|
||||||
let (seed',_) = random g
|
let (seed',_) = random g
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ debugMenuOptions =
|
|||||||
, doption ScancodeC debug_noclip "NOCLIP" _debug_noclip
|
, doption ScancodeC debug_noclip "NOCLIP" _debug_noclip
|
||||||
, doption ScancodeS debug_cr_status "SHOW CREATURE STATUS" _debug_cr_status
|
, doption ScancodeS debug_cr_status "SHOW CREATURE STATUS" _debug_cr_status
|
||||||
, doption ScancodeV debug_view_boundaries "SHOW VIEW BOUNDARIES" _debug_view_boundaries
|
, doption ScancodeV debug_view_boundaries "SHOW VIEW BOUNDARIES" _debug_view_boundaries
|
||||||
|
, doption ScancodeB debug_view_clip_bounds "SHOW ROOM CLIP BOUNDARIES" _debug_view_clip_bounds
|
||||||
, doption ScancodeP debug_pathing "SHOW PATHING" _debug_pathing
|
, doption ScancodeP debug_pathing "SHOW PATHING" _debug_pathing
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -21,8 +21,11 @@ icTryStartReloading it = do
|
|||||||
ammax <- am ^? ammoBaseMax
|
ammax <- am ^? ammoBaseMax
|
||||||
rstate <- am ^? reloadState
|
rstate <- am ^? reloadState
|
||||||
if amloaded < ammax && rstate == Nothing'
|
if amloaded < ammax && rstate == Nothing'
|
||||||
then Just $ it & itConsumption . reloadState .~ Just' (_reloadTime am)
|
then Just $ it
|
||||||
& if _reloadType am == ActiveClear then itConsumption . ammoLoaded .~ 0 else id
|
& itConsumption . reloadState .~ Just' (_reloadTime am)
|
||||||
|
& if _reloadType am == ActiveClear
|
||||||
|
then itConsumption . ammoLoaded .~ 0
|
||||||
|
else id
|
||||||
else Nothing
|
else Nothing
|
||||||
|
|
||||||
crStopReloading :: Creature -> Creature
|
crStopReloading :: Creature -> Creature
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
module Dodge.Render.ShapePicture
|
module Dodge.Render.ShapePicture
|
||||||
( worldSPic
|
( worldSPic
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
import Dodge.Config.Data
|
import Dodge.Config.Data
|
||||||
--import Dodge.Debug.Picture
|
--import Dodge.Debug.Picture
|
||||||
import Dodge.Picture.SizeInvariant
|
import Dodge.Picture.SizeInvariant
|
||||||
@@ -19,6 +18,7 @@ import ShapePicture
|
|||||||
import Shape
|
import Shape
|
||||||
import Picture
|
import Picture
|
||||||
import Sound.Data
|
import Sound.Data
|
||||||
|
import Geometry.ConvexPoly
|
||||||
|
|
||||||
import qualified Data.IntMap.Strict as IM -- Lazy?
|
import qualified Data.IntMap.Strict as IM -- Lazy?
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
@@ -52,6 +52,7 @@ extraPics cfig w = pictures (_decorations w)
|
|||||||
<> concatMapPic ppDraw (_pressPlates w )
|
<> concatMapPic ppDraw (_pressPlates w )
|
||||||
<> soundPics cfig w
|
<> soundPics cfig w
|
||||||
<> viewBoundaries cfig w
|
<> viewBoundaries cfig w
|
||||||
|
<> viewClipBounds cfig w
|
||||||
<> drawPathing cfig w
|
<> drawPathing cfig w
|
||||||
|
|
||||||
testPic :: World -> Picture
|
testPic :: World -> Picture
|
||||||
@@ -110,6 +111,21 @@ viewBoundaries cfig w
|
|||||||
p = _crPos $ you w
|
p = _crPos $ you w
|
||||||
grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
|
grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
|
||||||
|
|
||||||
|
viewClipBounds :: Configuration -> World -> Picture
|
||||||
|
viewClipBounds cfig w
|
||||||
|
| _debug_view_clip_bounds cfig
|
||||||
|
-- = setLayer 5 $ color green $ concatMap (polygonWire . _cpPoints) (_roomClipping w)
|
||||||
|
= setLayer 5 $ f (_roomClipping w)
|
||||||
|
| otherwise = []
|
||||||
|
where
|
||||||
|
f (x:xs) = g x xs <> f xs
|
||||||
|
f [] = mempty
|
||||||
|
g x (y:ys) | convexPolysOverlap x y = color green (polygonWire $ _cpPoints x)
|
||||||
|
<> color yellow (polygonWire $ _cpPoints y)
|
||||||
|
<> g x ys
|
||||||
|
| otherwise = g x ys
|
||||||
|
g _ [] = mempty
|
||||||
|
|
||||||
--wallFloorsToDraw :: World -> [Wall]
|
--wallFloorsToDraw :: World -> [Wall]
|
||||||
--wallFloorsToDraw w = filter isVisible $ IM.elems $ wallsOnScreen w
|
--wallFloorsToDraw w = filter isVisible $ IM.elems $ wallsOnScreen w
|
||||||
-- where
|
-- where
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ longRoomRunPast = do
|
|||||||
(Node (PassDown r)
|
(Node (PassDown r)
|
||||||
[ singleUseAll door
|
[ singleUseAll door
|
||||||
--, return (UseLabel 0 $ door & rmConnectsTo .~ S.singleton InLink)
|
--, return (UseLabel 0 $ door & rmConnectsTo .~ S.singleton InLink)
|
||||||
, treeFromPost [PassDown $ corridor & rmConnectsTo .~ S.member InLink, PassDown corridor]
|
--, treeFromPost [PassDown $ corridor & rmConnectsTo .~ S.member InLink, PassDown corridor]
|
||||||
|
, treeFromPost [PassDown $ corridor & rmConnectsTo .~ S.member InLink]
|
||||||
(UseLabel 0 door)
|
(UseLabel 0 door)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -170,6 +170,8 @@ quarterRoomTri w = do
|
|||||||
]
|
]
|
||||||
, _rmBound = [[V2 0 0,V2 w w,V2 (-w) w]]
|
, _rmBound = [[V2 0 0,V2 w w,V2 (-w) w]]
|
||||||
}
|
}
|
||||||
|
-- where
|
||||||
|
-- w' = w -10
|
||||||
|
|
||||||
quarterRoomSquare :: RandomGen g => Float -> State g Room
|
quarterRoomSquare :: RandomGen g => Float -> State g Room
|
||||||
quarterRoomSquare w = do
|
quarterRoomSquare w = do
|
||||||
@@ -207,8 +209,10 @@ quarterRoomSquare w = do
|
|||||||
, _rmPos = [ RoomPos p pi S.empty NotLink 0
|
, _rmPos = [ RoomPos p pi S.empty NotLink 0
|
||||||
| p <- [V2 20 (2*w-40),V2 25 (2*w-45)] ]
|
| p <- [V2 20 (2*w-40),V2 25 (2*w-45)] ]
|
||||||
--, _rmBound = [map toV2 [(w,w),(0,2*w),(-w,w)]]
|
--, _rmBound = [map toV2 [(w,w),(0,2*w),(-w,w)]]
|
||||||
, _rmBound = thepoly
|
, _rmBound = [ map toV2 [(0,0),(w,w),(0,2*w),(-w,w)] ]
|
||||||
}
|
}
|
||||||
|
-- where
|
||||||
|
-- w' = w - 10
|
||||||
{- | Randomise the ordering of placements in a room.
|
{- | Randomise the ordering of placements in a room.
|
||||||
Useful for randomising the position of generic placements such as 'PutNothing'. -}
|
Useful for randomising the position of generic placements such as 'PutNothing'. -}
|
||||||
shufflePlacements :: RandomGen g => Room -> State g Room
|
shufflePlacements :: RandomGen g => Room -> State g Room
|
||||||
|
|||||||
+25
-13
@@ -1,8 +1,11 @@
|
|||||||
{- | Given a tree of rooms, tries to shift them into place in such a way that their
|
{- | Given a tree of rooms, tries to shift them into place in such a way that their
|
||||||
links connect and that none of them clip.
|
links connect and that none of them clip.
|
||||||
Creates a list of rooms; after this step the structure is determined by the actual positions of rooms. -}
|
Creates a list of rooms; after this step the structure is determined by the actual positions of rooms. -}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE StrictData #-}
|
||||||
module Dodge.Tree.Shift
|
module Dodge.Tree.Shift
|
||||||
( positionRoomsFromTree
|
( positionRoomsFromTree
|
||||||
|
, PosRooms (..)
|
||||||
) where
|
) where
|
||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
import Dodge.Room.Link
|
import Dodge.Room.Link
|
||||||
@@ -16,28 +19,37 @@ import LensHelp hiding (Empty, (<|) , (|>))
|
|||||||
|
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import Data.Tree
|
import Data.Tree
|
||||||
import Data.Sequence hiding (zipWith)
|
import qualified Data.Sequence as Seq
|
||||||
import Data.List (delete)
|
import Data.List (delete)
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
|
import Control.Lens
|
||||||
|
|
||||||
type RoomInt = (Room,Int)
|
type RoomInt = (Room,Int)
|
||||||
|
|
||||||
positionRoomsFromTree :: Tree RoomInt -> IO (Maybe [RoomInt])
|
data PosRooms = PosRooms
|
||||||
|
{ _prBounds :: [ConvexPoly]
|
||||||
|
, _prRooms :: [RoomInt]
|
||||||
|
}
|
||||||
|
makeLenses ''PosRooms
|
||||||
|
|
||||||
|
|
||||||
|
positionRoomsFromTree :: Tree RoomInt -> IO (Maybe PosRooms)
|
||||||
positionRoomsFromTree (Node (r,i) ts) = printColumnTitles
|
positionRoomsFromTree (Node (r,i) ts) = printColumnTitles
|
||||||
>> fmap (fmap (map $ first createUnusedLinkPos))
|
>> fmap (fmap (prRooms %~ (map $ first createUnusedLinkPos)))
|
||||||
(posRms (map pointsToPoly $ _rmBound r') (r',i) (zipCount ts) Empty)
|
(posRms (PosRooms (map pointsToPoly $ _rmBound r') []) (r',i) (zipCount ts) Empty)
|
||||||
where
|
where
|
||||||
r' = r & rmMID ?~ 0
|
r' = r & rmMID ?~ 0
|
||||||
|
|
||||||
posRms :: [ConvexPoly]
|
posRms :: PosRooms
|
||||||
-> RoomInt
|
-> RoomInt
|
||||||
-> [(Int,Tree RoomInt)] -- the list of children, with indices
|
-> [(Int,Tree RoomInt)] -- the list of children, with indices
|
||||||
-> Seq (Tree RoomInt)
|
-> Seq.Seq (Tree RoomInt)
|
||||||
-> IO (Maybe [RoomInt])
|
-> IO (Maybe PosRooms)
|
||||||
posRms bounds roomi [] st = case st of
|
posRms prs roomi [] st = case st of
|
||||||
Empty -> return $ Just [roomi]
|
Empty -> return $ Just $ prs & prRooms .:~ roomi
|
||||||
Node nextroomi ts :<| tseq -> fmap (roomi:) <$> posRms bounds nextroomi (zipCount ts) tseq
|
Node nextroomi ts Seq.:<| tseq -> posRms (prs & prRooms .:~ roomi) nextroomi (zipCount ts) tseq
|
||||||
posRms bounds parenti@(parent,_) ( (numChild,t@(Node childi _) ):its) tseq = do
|
_ -> error "unexpected outcome in posRms"
|
||||||
|
posRms prs parenti@(parent,_) ( (numChild,t@(Node childi _) ):its) tseq = do
|
||||||
printInfoCheckNum parenti numChild childi
|
printInfoCheckNum parenti numChild childi
|
||||||
tryParentLinks outlinks
|
tryParentLinks outlinks
|
||||||
where
|
where
|
||||||
@@ -54,7 +66,7 @@ posRms bounds parenti@(parent,_) ( (numChild,t@(Node childi _) ):its) tseq = do
|
|||||||
| otherwise = do
|
| otherwise = do
|
||||||
putStrLn $ show j ++ "-" ++ show numinlink
|
putStrLn $ show j ++ "-" ++ show numinlink
|
||||||
mayrs <- posRms
|
mayrs <- posRms
|
||||||
(newBounds ++ bounds)
|
(prs & prBounds .++~ newBounds)
|
||||||
(first updateparent parenti)
|
(first updateparent parenti)
|
||||||
its
|
its
|
||||||
(tseq |> shiftedt)
|
(tseq |> shiftedt)
|
||||||
@@ -64,7 +76,7 @@ posRms bounds parenti@(parent,_) ( (numChild,t@(Node childi _) ):its) tseq = do
|
|||||||
>> tryChildLinks ils
|
>> tryChildLinks ils
|
||||||
where
|
where
|
||||||
newBounds = map pointsToPoly . _rmBound . doRoomShift . fst $ rootLabel shiftedt
|
newBounds = map pointsToPoly . _rmBound . doRoomShift . fst $ rootLabel shiftedt
|
||||||
clipping = or (convexPolysOverlap <$> newBounds <*> bounds)
|
clipping = or (convexPolysOverlap <$> newBounds <*> _prBounds prs)
|
||||||
updateparent rm = doLnkEff (lnkPosDir outlnk) $ rm
|
updateparent rm = doLnkEff (lnkPosDir outlnk) $ rm
|
||||||
& rmLinks %~ delete outlnk
|
& rmLinks %~ delete outlnk
|
||||||
& rmPos .:~ RoomPos
|
& rmPos .:~ RoomPos
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ pointsToPoly :: [Point2] -> ConvexPoly
|
|||||||
pointsToPoly xs = ConvexPoly
|
pointsToPoly xs = ConvexPoly
|
||||||
{ _cpPoints = xs
|
{ _cpPoints = xs
|
||||||
, _cpCen = cen
|
, _cpCen = cen
|
||||||
, _cpRad = minimum $ map (dist cen) xs
|
, _cpRad = maximum $ map (dist cen) xs
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
cen = centroid xs
|
cen = centroid xs
|
||||||
|
|||||||
Reference in New Issue
Block a user