Remove temporary light sources as separate entity

This commit is contained in:
2024-11-26 13:12:55 +00:00
parent e93a804559
commit cc302a6846
17 changed files with 243 additions and 241 deletions
+2 -1
View File
@@ -252,7 +252,8 @@ shineTorch cr itmtree (p, q) = fromMaybe id $ do
guard $ i >= x
invid <- mag ^? ldtValue . cItem . itLocation . ilInvID
return $
(cWorld . lWorld . tempLightSources .:~ tlsTimeRadColPos 1 250 0.7 pos'')
--(cWorld . lWorld . tempLightSources .:~ tlsTimeRadColPos 1 250 0.7 pos'')
(cWorld . lWorld . lights .:~ LSParam pos'' 250 0.7)
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . amagLoadStatus . iaLoaded -~ x)
where
x = 10
+1 -1
View File
@@ -134,7 +134,7 @@ data LWorld = LWorld
, _foregroundShapes :: IM.IntMap ForegroundShape
, _corpses :: IM.IntMap Corpse
, _lightSources :: IM.IntMap LightSource
, _tempLightSources :: [TempLightSource]
-- , _tempLightSources :: [TempLightSource]
, _lights :: [LSParam]
, _seenLocations :: IM.IntMap (WdP2, String)
, _selLocation :: Int
+21 -21
View File
@@ -13,18 +13,18 @@ import Geometry
data LightSourceDraw = DefaultLightSourceDraw
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data TLSIntensity
= ConstantIntensity
| TLSFade Point3 Int
deriving (Eq, Ord, Show, Read) --Generic, Flat)
--data TLSIntensity
-- = ConstantIntensity
-- | TLSFade Point3 Int
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
--
--data TLSUpdate
-- = DestroyTLS
-- | TimerTLS
-- | IntensityTLS TLSIntensity
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
data TLSUpdate
= DestroyTLS
| TimerTLS
| IntensityTLS TLSIntensity
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data LSParam = LSParam
data LSParam = LSParam -- LSPosRadCol
{ _lsPos :: !Point3
, _lsRad :: !Float
, _lsCol :: !Point3
@@ -39,19 +39,19 @@ data LightSource = LS
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data TempLightSource = TLS
{ _tlsParam :: LSParam
, _tlsUpdate :: TLSUpdate --TempLightSource -> Maybe TempLightSource
, _tlsTime :: Int
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
--data TempLightSource = TLS
-- { _tlsParam :: LSParam
-- , _tlsUpdate :: TLSUpdate --TempLightSource -> Maybe TempLightSource
-- , _tlsTime :: Int
-- }
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''LSParam
makeLenses ''LightSource
makeLenses ''TempLightSource
--makeLenses ''TempLightSource
deriveJSON defaultOptions ''LightSourceDraw
deriveJSON defaultOptions ''TLSIntensity
deriveJSON defaultOptions ''TLSUpdate
--deriveJSON defaultOptions ''TLSIntensity
--deriveJSON defaultOptions ''TLSUpdate
deriveJSON defaultOptions ''LSParam
deriveJSON defaultOptions ''LightSource
deriveJSON defaultOptions ''TempLightSource
--deriveJSON defaultOptions ''TempLightSource
+12 -12
View File
@@ -17,15 +17,15 @@ defaultLS =
, _lsPict = DefaultLightSourceDraw --defLSPic
}
defaultTLS :: TempLightSource
defaultTLS =
TLS
{ _tlsParam =
LSParam
{ _lsPos = 0
, _lsRad = 0
, _lsCol = 0.5
}
, _tlsUpdate = TimerTLS
, _tlsTime = 1
}
--defaultTLS :: TempLightSource
--defaultTLS =
-- TLS
-- { _tlsParam =
-- LSParam
-- { _lsPos = 0
-- , _lsRad = 0
-- , _lsCol = 0.5
-- }
-- , _tlsUpdate = TimerTLS
-- , _tlsTime = 1
-- }
+1 -1
View File
@@ -135,7 +135,7 @@ defaultLWorld =
, _buttons = IM.empty
, _corpses = IM.empty
, _lightSources = IM.empty
, _tempLightSources = []
-- , _tempLightSources = []
, _lights = mempty
, _seenLocations =
IM.fromList
+3 -2
View File
@@ -94,6 +94,7 @@ makeFlashBall p w =
ebFlicker :: EnergyBall -> World -> World
ebFlicker pt
| _ebTimer pt `mod` 7 == 0 =
cWorld . lWorld . tempLightSources
.:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_ebColor pt)) (addZ 20 $ _ebPos pt)
cWorld . lWorld . lights
.:~ LSParam (addZ 20 $ _ebPos pt) 70 (0.5 *.*.* xyzV4 (_ebColor pt))
-- .:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_ebColor pt)) (addZ 20 $ _ebPos pt)
| otherwise = id
+10 -5
View File
@@ -158,12 +158,17 @@ removeShieldWall it _ w = case it ^? itParams . flatShieldWlMIX . _Just of
createHeadLamp :: Item -> Creature -> World -> World
createHeadLamp _ cr =
cWorld . lWorld . tempLightSources
.:~ tlsTimeRadColPos
1
200
0.7
cWorld . lWorld . lights .:~ LSParam
((_crPos cr `v2z` 0) +.+.+ rotate3 (_crDir cr) (translatePointToHead cr (V3 5 0 3)))
200
0.7
-- cWorld . lWorld . tempLightSources
-- .:~ tlsTimeRadColPos
-- 1
-- 200
-- 0.7
-- ((_crPos cr `v2z` 0) +.+.+ rotate3 (_crDir cr) (translatePointToHead cr (V3 5 0 3)))
overCID :: (Creature -> Creature) -> Item -> Creature -> World -> World
overCID f _ cr = cWorld . lWorld . creatures . ix (_crID cr) %~ f
+3 -2
View File
@@ -124,8 +124,9 @@ flDamageInArea crt wlt pt w = damwls damcrs
flFlicker :: Flame -> World -> World
flFlicker pt
| _flTimer pt `mod` 7 == 0 =
cWorld . lWorld . tempLightSources
.:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_flColor pt)) (addZ 10 $ _flPos pt)
cWorld . lWorld . lights
.:~ LSParam (addZ 10 $ _flPos pt) 70 (0.5 *.*.* xyzV4 (_flColor pt))
-- .:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_flColor pt)) (addZ 10 $ _flPos pt)
| otherwise = id
makeFlame :: Point2 -> Point2 -> World -> World
+11 -6
View File
@@ -147,17 +147,21 @@ makeMuzzleFlare mz itmtree cr = case mz ^. mzFlareType of
DefaultFlareType -> id
PistolFlare -> basicMuzFlare pos dir
MiniGunFlare ->
makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (pos `v2z` 20)
--makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (pos `v2z` 20)
(cWorld . lWorld . lights .:~ LSParam (pos `v2z` 20) 100 (V3 1 1 0.5))
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
HeavySmokeFlare -> basicMuzFlare pos dir
LasGunFlare ->
flareCircleAt (getLaserColor itmtree) 0.8 (pos `v2z` 20)
. ( cWorld . lWorld . tempLightSources
.:~ tlsTimeRadColPos 1 100 (xyzV4 $ getLaserColor itmtree) (pos `v2z` 10)
-- . ( cWorld . lWorld . tempLightSources
-- .:~ tlsTimeRadColPos 1 100 (xyzV4 $ getLaserColor itmtree) (pos `v2z` 10)
. ( cWorld . lWorld . lights
.:~ LSParam (pos `v2z` 10) 100 (xyzV4 $ getLaserColor itmtree)
)
TeslaGunFlare ->
cWorld . lWorld . tempLightSources
.:~ tlsTimeRadColPos 1 100 (V3 0 0 1) (pos `v2z` 10)
cWorld . lWorld . lights
.:~ LSParam (pos `v2z` 10) 100 (V3 0 0 1)
-- .:~ tlsTimeRadColPos 1 100 (V3 0 0 1) (pos `v2z` 10)
where
itm = itmtree ^. ldtValue
pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
@@ -198,7 +202,8 @@ getLaserColor = const yellow
basicMuzFlare :: Point2 -> Float -> World -> World
basicMuzFlare pos dir =
makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (pos `v2z` 20)
-- makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (pos `v2z` 20)
(cWorld . lWorld . lights .:~ LSParam (pos `v2z` 20) 100 (V3 1 1 0.5))
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
+3 -1
View File
@@ -18,7 +18,9 @@ updateLampoid cr w = case cr ^?! crType . lampLSID of
Just i
| _crHP cr < 0 ->
w
& cWorld . lWorld . tempLightSources .:~ tlsTimeRadFunPos 20 150 (TLSFade 1 10) (addZ 20 cpos)
-- & cWorld . lWorld . tempLightSources .:~ tlsTimeRadFunPos 20 150 (TLSFade 1 10) (addZ 20 cpos)
& cWorld . lWorld . worldEvents .:~ MakeTempLight
(LSParam (addZ 20 cpos) 150 1) 20
& originsIDsAt [MaterialSound Glass n | n <- [0, 1, 2]] (destroyMatS Glass) cpos
& cWorld . lWorld . lightSources . at i .~ Nothing
& cWorld . lWorld . creatures . at cid .~ Nothing
+44 -42
View File
@@ -1,13 +1,13 @@
module Dodge.LightSource (
tlsTimeRadFunPos,
tlsTimeRadColPos,
-- tlsTimeRadFunPos,
-- tlsTimeRadColPos,
lsRadCol,
lsColPosRad,
lsColPos,
lsPosCol,
lsPosRad,
lsColPosID,
makeTlsTimeRadColPos,
-- makeTlsTimeRadColPos,
destroyLS,
) where
@@ -23,18 +23,18 @@ import LensHelp
lsPosRad :: Point3 -> Float -> LightSource
lsPosRad = lsColPosRad 0.75
tlsTimeRadFunPos :: Int -> Float -> TLSIntensity -> Point3 -> TempLightSource
tlsTimeRadFunPos t rmax intensityF p =
TLS
{ _tlsParam =
LSParam
{ _lsPos = p
, _lsRad = rmax
, _lsCol = 0 -- intensityF t
}
, _tlsUpdate = IntensityTLS intensityF
, _tlsTime = t
}
--tlsTimeRadFunPos :: Int -> Float -> TLSIntensity -> Point3 -> TempLightSource
--tlsTimeRadFunPos t rmax intensityF p =
-- TLS
-- { _tlsParam =
-- LSParam
-- { _lsPos = p
-- , _lsRad = rmax
-- , _lsCol = 0 -- intensityF t
-- }
-- , _tlsUpdate = IntensityTLS intensityF
-- , _tlsTime = t
-- }
-- where
-- upF tls
@@ -66,27 +66,27 @@ lsRadCol r col =
defaultLS & lsParam . lsRad .~ r
& lsParam . lsCol .~ col
tlsTimeRadColPos ::
Int ->
-- | maximal radius
Float ->
Point3 ->
Point3 ->
TempLightSource
tlsTimeRadColPos t rmax col (V3 x y z) =
TLS
{ _tlsParam =
LSParam
{ _lsPos = V3 x y z
, _lsRad = rmax
, _lsCol = col
}
, _tlsUpdate = TimerTLS
, _tlsTime = t
}
makeTlsTimeRadColPos :: Int -> Float -> Point3 -> Point3 -> World -> World
makeTlsTimeRadColPos i rad (V3 r g b) p = cWorld . lWorld . tempLightSources .:~ tlsTimeRadColPos i rad (V3 r g b) p
--tlsTimeRadColPos ::
-- Int ->
-- -- | maximal radius
-- Float ->
-- Point3 ->
-- Point3 ->
-- TempLightSource
--tlsTimeRadColPos t rmax col (V3 x y z) =
-- TLS
-- { _tlsParam =
-- LSParam
-- { _lsPos = V3 x y z
-- , _lsRad = rmax
-- , _lsCol = col
-- }
-- , _tlsUpdate = TimerTLS
-- , _tlsTime = t
-- }
--
--makeTlsTimeRadColPos :: Int -> Float -> Point3 -> Point3 -> World -> World
--makeTlsTimeRadColPos i rad (V3 r g b) p = cWorld . lWorld . tempLightSources .:~ tlsTimeRadColPos i rad (V3 r g b) p
destroyLS :: Int -> World -> World
destroyLS lsid w =
@@ -100,11 +100,13 @@ destroyLS lsid w =
destroyLSFlashAt :: Point3 -> World -> World
destroyLSFlashAt (V3 x' y' z') =
cWorld . lWorld . tempLightSources
.:~ tlsTimeRadFunPos
20
150
(TLSFade 1 10)
(addZ z' p)
cWorld . lWorld . worldEvents .:~ MakeTempLight
(LSParam (addZ z' p) 150 1) 20
-- cWorld . lWorld . tempLightSources
-- .:~ tlsTimeRadFunPos
-- 20
-- 150
-- (TLSFade 1 10)
-- (addZ z' p)
where
p = V2 x' y'
+19 -19
View File
@@ -4,22 +4,22 @@ import Control.Lens
import Dodge.Data.LightSource
import Geometry
updateTempLightSource :: TLSUpdate -> TempLightSource -> Maybe TempLightSource
updateTempLightSource tlsu = case tlsu of
DestroyTLS -> const Nothing
TimerTLS -> timerTLS
IntensityTLS ConstantIntensity -> updateTempLightSource TimerTLS
IntensityTLS (TLSFade startcol x) -> fadeTLS startcol x
fadeTLS :: Point3 -> Int -> TempLightSource -> Maybe TempLightSource
fadeTLS startcol x tls
| t < 1 = Nothing
| t < x = Just $ tls & tlsParam . lsCol .~ (1 / fromIntegral (x - t)) *.*.* startcol
| otherwise = Just $ tls & tlsParam . lsCol .~ startcol -- this is wasteful, should be set once at begining
where
t = _tlsTime tls
timerTLS :: TempLightSource -> Maybe TempLightSource
timerTLS t
| _tlsTime t <= 0 = Nothing
| otherwise = Just $ t & tlsTime -~ 1
--updateTempLightSource :: TLSUpdate -> TempLightSource -> Maybe TempLightSource
--updateTempLightSource tlsu = case tlsu of
-- DestroyTLS -> const Nothing
-- TimerTLS -> timerTLS
-- IntensityTLS ConstantIntensity -> updateTempLightSource TimerTLS
-- IntensityTLS (TLSFade startcol x) -> fadeTLS startcol x
--
--fadeTLS :: Point3 -> Int -> TempLightSource -> Maybe TempLightSource
--fadeTLS startcol x tls
-- | t < 1 = Nothing
-- | t < x = Just $ tls & tlsParam . lsCol .~ (1 / fromIntegral (x - t)) *.*.* startcol
-- | otherwise = Just $ tls & tlsParam . lsCol .~ startcol -- this is wasteful, should be set once at begining
-- where
-- t = _tlsTime tls
--
--timerTLS :: TempLightSource -> Maybe TempLightSource
--timerTLS t
-- | _tlsTime t <= 0 = Nothing
-- | otherwise = Just $ t & tlsTime -~ 1
+2 -2
View File
@@ -16,11 +16,11 @@ lightsToRender :: Configuration -> Camera -> LWorld -> [(Point3, Float, Point3)]
lightsToRender cfig campos w = take (fromEnum $ cfig ^. graphics_num_shadow_casters) $
sortOn (\(_,x,_) -> negate x) $
mapMaybe getLS (IM.elems $ w ^. lightSources)
++ mapMaybe getTLS (w ^. tempLightSources)
-- ++ mapMaybe getTLS (w ^. tempLightSources)
++ mapMaybe getlsparam (w ^. lights)
where
getLS = getlsparam . _lsParam
getTLS = getlsparam . _tlsParam
-- getTLS = getlsparam . _tlsParam
cbox = campos ^. camBoundBox
cpos = campos ^. camCenter
getlsparam ls
+4 -4
View File
@@ -163,7 +163,7 @@ updateUniverseMid u = case _uvScreenLayers u of
--updateParticles
(cWorld . lWorld . radarBlips .~ [])
-- . updateIMl _props _pjUpdate
. updateLightSources
-- . updateLightSources
. (cWorld . lWorld . lights .~ [])
. updateClouds
)
@@ -276,7 +276,7 @@ functionalUpdate u =
. over uvWorld (updateIMl' (_linearShockwaves . _lWorld . _cWorld) updateLinearShockwave)
. over uvWorld (updateIMl' (_props . _lWorld . _cWorld) updateProp)
. over uvWorld (updateIMl' (_projectiles . _lWorld . _cWorld) updateProjectile)
. over uvWorld updateLightSources
-- . over uvWorld updateLightSources
. over uvWorld updateClouds
. over uvWorld updateGusts
. over uvWorld (updateMIM (cWorld . lWorld . magnets) (doMagnetUpdate . _mgUpdate))
@@ -531,8 +531,8 @@ updateObjCatMaybes p f w = w' & cWorld . lWorld . p #~ catMaybes newxs
updateDistortions :: World -> World
updateDistortions = updateObjMapMaybe distortions updateDistortion
updateLightSources :: World -> World
updateLightSources = updateObjMapMaybe tempLightSources (\b -> updateTempLightSource (_tlsUpdate b) b)
--updateLightSources :: World -> World
--updateLightSources = updateObjMapMaybe tempLightSources (\b -> updateTempLightSource (_tlsUpdate b) b)
updateRadarBlips :: World -> World
updateRadarBlips = updateObjMapMaybe radarBlips updateRadarBlip
+4 -2
View File
@@ -76,10 +76,12 @@ makeExplosionAt p w =
w
& soundMultiFrom [Explosion 0, Explosion 1] p bangS Nothing
& addFlames
& cWorld . lWorld . tempLightSources .:~ theTLS
-- & cWorld . lWorld . tempLightSources .:~ theTLS
& cWorld . lWorld . worldEvents .:~ thels
& makeShockwaveAt [] p 50 50 1 white
where
theTLS = tlsTimeRadColPos 20 150 (V3 1 0.5 0) (addZ 20 p)
thels = MakeTempLight (LSParam (addZ 20 p) 150 (V3 1 0.5 0)) 20
-- theTLS = tlsTimeRadColPos 20 150 (V3 1 0.5 0) (addZ 20 p)
fVs = replicateM 100 (randInCirc 1) & evalState $ _randGen w
--fPs'' = replicateM 100 (fmap (15 *.*.*) randInHemisphere) & evalState $ _randGen w
fPs'' = replicateM 100 (fmap (15 *.*.*) randInHemisphere) & evalState $ _randGen w