Rename shaders, remove a dependency on Dodge.Data

This commit is contained in:
jgk
2021-04-28 13:32:50 +02:00
parent 2085d5a048
commit 1b4eac2da7
28 changed files with 163 additions and 176 deletions
+1 -1
View File
@@ -264,7 +264,7 @@ Items you start with.
-}
startInventory = IM.fromList (zip [0..20]
(
[--pistol
[pistol
--,blinkGun
--,spawnGun lamp
--,poisonSprayer
+1 -1
View File
@@ -8,7 +8,6 @@ circular imports are scary.
{-# LANGUAGE StrictData #-}
module Dodge.Data
( module Dodge.Data
, module Dodge.Data.Menu
, module Dodge.Data.DamageType
, module Dodge.Data.SoundOrigin
, module Dodge.Creature.Data
@@ -58,6 +57,7 @@ data World = World
, _cloudsZone :: IM.IntMap (IM.IntMap (IM.IntMap Cloud))
, _projectiles :: IM.IntMap Projectile
, _particles :: ![Particle]
, _staticWalls :: [Wall]
, _walls :: !(IM.IntMap Wall)
, _wallsZone :: (IM.IntMap (IM.IntMap (IM.IntMap Wall)))
, _forceFields :: IM.IntMap ForceField
+2 -1
View File
@@ -6,7 +6,8 @@ data MenuLayer
| PauseMenu
| GameOverMenu
| OptionMenu
| SoundOptionMenu
| GraphicsOptionMenu
| ConfigSaveScreen
| ControlList
deriving (Eq,Ord)
+2
View File
@@ -9,6 +9,7 @@ module Dodge.Default where
import Dodge.Item.Weapon.Recock
import Dodge.Data
import Dodge.Data.Menu
import Dodge.SoundLogic
import Dodge.Base
import Dodge.Config.Data
@@ -208,6 +209,7 @@ defaultWorld = World
, _itemPositions = IM.empty
, _projectiles = IM.empty
, _particles = []
, _staticWalls = []
, _walls = IM.empty
, _wallsZone = IM.empty
, _forceFields = IM.empty
+1
View File
@@ -6,6 +6,7 @@ module Dodge.Event.Keyboard
)
where
import Dodge.Data
import Dodge.Data.Menu
import Dodge.Base
import Dodge.Creature.Action
import Dodge.Config.KeyConfig
+1
View File
@@ -2,6 +2,7 @@ module Dodge.Event.Menu
( handlePressedKeyInMenu
) where
import Dodge.Data
import Dodge.Data.Menu
import Dodge.Floor
import Dodge.Initialisation
import Dodge.SoundLogic
+4 -2
View File
@@ -2,6 +2,7 @@ module Dodge.Initialisation where
-- imports {{{
import Dodge.Default
import Dodge.Data
import Dodge.Data.Menu
import Dodge.Creature
import Dodge.Base
import Dodge.Floor
@@ -21,8 +22,9 @@ initializeWorld w = w
firstWorld :: IO World
firstWorld = do
i <- randomRIO (0,5000)
putStrLn $ "Random seed for level generation: " ++ show ( i :: Int)
-- i <- randomRIO (0,5000)
let i = 2
putStrLn $ "Seed for level generation: " ++ show ( i :: Int)
return $ generateFromList levx $ initialWorld {_randGen = mkStdGen i}
initialWorld :: World
+2 -40
View File
@@ -1,7 +1,6 @@
module Dodge.Render
( module Dodge.Render.Picture
, doDrawing
, doDrawing'
)
where
import Dodge.Data
@@ -55,6 +54,7 @@ doDrawing pdata w = do
depthFunc $= Just Always
renderBackground pdata rot zoom trans wins
depthFunc $= Just Lequal
-- depthFunc $= Just Less
renderWalls pdata wallPointsCol pmat
setWallDepth pdata wallPoints (viewFromx,viewFromy) pmat
-- depthFunc $= Just Lequal
@@ -64,53 +64,15 @@ doDrawing pdata w = do
blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha) , (Zero,One))
-- blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
renderFoldable pdata $ picToLTree (Just 1) pic
-- set drawing for on top
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
renderFoldable pdata $ picToLTree (Just 2) pic
depthMask $= Disabled
renderWalls pdata windowPoints pmat
depthMask $= Enabled
resetShaderUniforms (map extractProgAndUnis $ _listShaders pdata)
resetShaderUniforms (map extractProgAndUnis $ _pictureShaders pdata)
----------------------
blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
renderFoldable pdata (picToLTree Nothing $ fixedCoordPictures w)
eTicks <- SDL.ticks
return (eTicks - sTicks)
doDrawing' :: RenderData -> World -> IO (Word32)
doDrawing' pdata w = do
bindFramebuffer Framebuffer $= defaultFramebufferObject
sTicks <- SDL.ticks
clear [ColorBuffer,DepthBuffer]
let rot = _cameraRot w
zoom = _cameraZoom w
trans@(tranx,trany) = _cameraCenter w
wins@(winx,winy) = (_windowX w,_windowY w)
wallPointsCol = wallsPointsAndCols w
windowPoints = wallsWindows w
lightPoints = lightsForGloom' w
viewFroms@(viewFromx,viewFromy) = _cameraViewFrom w
pic = worldPictures w
wallPoints = map fst wallPointsCol
pmat <- (newMatrix RowMajor
$ perspectiveMatrix w) :: IO (GLmatrix GLfloat)
setCommonUniforms pdata rot zoom trans wins
depthMask $= Disabled
renderBackground pdata rot zoom trans wins
depthMask $= Enabled
blend $= Enabled
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
-- not sure why renderWalls and setWallDepth aren't combined
renderWalls pdata wallPointsCol pmat
setWallDepth pdata wallPoints (viewFromx,viewFromy) pmat
depthFunc $= Just Lequal
renderFoldable pdata $ picToLTree (Just 0) pic
renderFoldable pdata $ picToLTree (Just 1) pic
renderFoldable pdata $ picToLTree (Just 2) pic
eTicks <- SDL.ticks
return (eTicks - sTicks)
+30 -17
View File
@@ -1,22 +1,30 @@
{-
The menu picture.
-}
module Dodge.Render.MenuScreen
( menuScreen
)
where
import Dodge.Data
import Dodge.Data.Menu
import Dodge.Config.Update
import Dodge.Config.Data
import Dodge.Base (halfWidth,halfHeight)
import Picture
menuScreen :: World -> Picture
menuScreen w = case _menuLayers w of
menuScreen
:: Configuration
-> Float -- Half width of screen
-> Float -- Half height of screen
-> [MenuLayer]
-> Picture
menuScreen cfig hw hh mLays = case mLays of
[] -> blank
(LevelMenu x:_) -> pictures
[color (withAlpha 0.5 black) $ polygon $ screenBox w
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
,tst (-100) 100 0.4 ("LEVEL "++show x)
]
(PauseMenu:_) -> pictures
[color (withAlpha 0.5 black) $ polygon $ screenBox w
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
,tst (-100) 100 0.4 "PAUSED"
,tst (-100) 50 0.2 "n - new level"
,tst (-100) 0 0.2 "r - restart"
@@ -24,7 +32,7 @@ menuScreen w = case _menuLayers w of
,tst (-100) (-100) 0.2 "c - controls"
]
(GameOverMenu:_) -> pictures
[color (withAlpha 0.5 black) $ polygon $ screenBox w
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
,tst (-100) 100 0.4 "GAME OVER"
,tst (-100) 50 0.2 "n - new level"
,tst (-100) 0 0.2 "r - restart"
@@ -32,19 +40,19 @@ menuScreen w = case _menuLayers w of
,tst (-100) (-100) 0.2 "c - controls"
]
(OptionMenu : _) -> pictures
[color (withAlpha 0.5 black) $ polygon $ screenBox w
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
,tst (-100) 100 0.4 "OPTIONS"
,tst (-180) 50 0.2 $ "y - master volume + u : " ++ mavol
,tst (-180) 0 0.2 $ "h - sound volume + j : " ++ snvol
,tst (-180) (-50) 0.2 $ "n - music volume + m : " ++ muvol
]
(ControlList : _) -> pictures
[color (withAlpha 0.5 black) $ polygon $ screenBox w
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
,tst (-100) 100 0.4 "CONTROLS"
,controlsList
]
(ConfigSaveScreen : _) -> pictures
[color (withAlpha 0.5 black) $ polygon $ screenBox w
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
,tst (-100) 100 0.4 "OPTIONS"
,tst (-180) 50 0.2 $ "y - master volume + u : " ++ mavol
,tst (-180) 0 0.2 $ "h - sound volume + j : " ++ snvol
@@ -53,9 +61,9 @@ menuScreen w = case _menuLayers w of
_ -> blank
where
tst x y sc t = translate x y $ scale sc sc $ color white $ text t
mavol = f $ _volume_master $ _config w
snvol = f $ _volume_sound $ _config w
muvol = f $ _volume_music $ _config w
mavol = f $ _volume_master $ cfig
snvol = f $ _volume_sound $ cfig
muvol = f $ _volume_music $ cfig
f x = show $ round $ 10 * x
controlsList = pictures $ concat $ zipWith butAndEff
@@ -76,9 +84,14 @@ controlsList = pictures $ concat $ zipWith butAndEff
,translate 0 y $ scale 0.15 0.15 $ color white $ text etext
]
screenBox w = [ (halfWidth w, halfHeight w)
, (-halfWidth w, halfHeight w)
, (-halfWidth w,-halfHeight w)
, ( halfWidth w,-halfHeight w)
]
screenBox
:: Float
-> Float
-> [(Float,Float)]
screenBox halfW halfH =
[ (halfW, halfH)
, (-halfW, halfH)
, (-halfW,-halfH)
, ( halfW,-halfH)
]
+1 -1
View File
@@ -30,7 +30,7 @@ worldPictures w = pictures $ concat
fixedCoordPictures :: World -> Picture
fixedCoordPictures w = pictures
[ hudDrawings w
, scaler . onLayer MenuDepth $ menuScreen w
, scaler . onLayer MenuDepth $ menuScreen (_config w) (halfWidth w) (halfHeight w) (_menuLayers w)
, customMouseCursor w
]
where
+1
View File
@@ -6,6 +6,7 @@ module Dodge.Update
( update
) where
import Dodge.Data
import Dodge.Data.Menu
import Dodge.Base
import Dodge.WallCreatureCollisions
import Dodge.LevelGen.Block