Refactor items, suspect a leak

This commit is contained in:
2022-07-21 00:50:50 +01:00
parent e2ccf7296a
commit 22787abf8f
5 changed files with 165 additions and 136 deletions
+2 -104
View File
@@ -10,6 +10,7 @@ circular imports are probably not a good idea.
{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE DerivingStrategies #-}
module Dodge.Data module Dodge.Data
( module Dodge.Data ( module Dodge.Data
, module Dodge.Data.Item.Params
, module Dodge.Data.Beam , module Dodge.Data.Beam
, module Dodge.Data.Targeting , module Dodge.Data.Targeting
, module Dodge.Data.ItEffect , module Dodge.Data.ItEffect
@@ -67,6 +68,7 @@ module Dodge.Data
, module Dodge.Data.RadarBlip , module Dodge.Data.RadarBlip
, module Dodge.Data.PathGraph , module Dodge.Data.PathGraph
) where ) where
import Dodge.Data.Item.Params
import Dodge.Data.Beam import Dodge.Data.Beam
import Dodge.Data.Targeting import Dodge.Data.Targeting
import Dodge.Data.ItEffect import Dodge.Data.ItEffect
@@ -417,25 +419,6 @@ data PressPlate = PressPlate
} }
data FloorItem = FlIt { _flIt :: Item , _flItPos :: Point2 , _flItRot :: Float, _flItID :: Int} data FloorItem = FlIt { _flIt :: Item , _flItPos :: Point2 , _flItRot :: Float, _flItID :: Int}
data Item = Item
{ _itConsumption :: ItemConsumption
, _itUse :: ItemUse
, _itType :: ItemType
, _itAttachment :: ItAttachment
, _itID :: Maybe Int
, _itPos :: ItemPos
, _itIsHeld :: Bool
, _itEffect :: ItEffect
, _itInvSize :: Float
, _itInvColor :: Color
, _itTargeting :: Targeting
, _itDimension :: ItemDimension
, _itCurseStatus :: CurseStatus
, _itTweaks :: ItemTweaks
, _itScope :: Scope
, _itValue :: ItemValue
, _itParams :: ItemParams
}
data IntID a = IntID Int a data IntID a = IntID Int a
@@ -504,87 +487,6 @@ type HitEffect' = Flame
-> World -> World
-> (World,Maybe Flame) -> (World,Maybe Flame)
data ItemTweaks
= NoTweaks
| Tweakable
{ _tweakParams :: IM.IntMap TweakParam
, _tweakSel :: Int
}
data TweakParam = TweakParam
{ _doTweak :: Int -> Item -> Item
, _curTweak :: Int
, _maxTweak :: Int
, _showTweak :: Int -> String
, _nameTweak :: String
}
data Nozzle = Nozzle
{ _nzPressure :: Float
, _nzDir :: Float
, _nzMaxWalkAngle :: Float
, _nzCurrentWalkAngle :: Float
, _nzWalkSpeed :: Float
, _nzLength :: Float
}
data GunBarrels
= MultiBarrel
{ _brlSpread :: BarrelSpread
, _brlNum :: Int
, _brlInaccuracy :: Float
}
| RotBarrel
{ _brlNum :: Int
, _brlInaccuracy :: Float
}
| SingleBarrel {_brlInaccuracy :: Float}
data ItemParams
= NoParams
| ShellLauncher
{ _shellSpinDrag :: Int
, _shellSpinAmount :: Int
, _shellThrustDelay :: Int
}
| Refracting
{ _phaseV :: Float
, _lasColor :: Color
, _lasColor2 :: Color
, _lasCycle :: Int
, _lasDamage :: Int
}
| DualBeam
{ _phaseV :: Float
, _lasColor :: Color
, _lasColor2 :: Color
, _lasCycle :: Int
, _lasDamage :: Int
, _lasBeam :: BeamType
, _subParams :: Maybe ItemParams
, _dbGap :: Float
}
| Attracting {_attractionPower :: Point2}
| BulletShooter
{ _muzVel :: Float
, _rifling :: Float
, _bore :: Float
, _gunBarrels :: GunBarrels
, _recoil :: Float
, _torqueAfter :: Float
, _randomOffset :: Float
}
| Sprayer { _sprayNozzles :: [Nozzle] }
| AngleWalk
{ _maxWalkAngle :: Float
, _currentWalkAngle :: Float
, _walkSpeed :: Float
}
| Arcing
{ _currentArc :: Maybe [ArcStep]
, _arcSize :: Float
, _arcNumber :: Int
, _newArcStep :: NextArcStep --ItemParams -> World -> ArcStep -> State StdGen (Maybe ArcStep)
, _previousArcEffect :: PreviousArcEffect
}
| ParamMID {_paramMID :: Maybe Int}
data PreviousArcEffect = NoPreviousArcEffect | PerturbTillBreakPreviousArc
data Modification data Modification
= ModIDTimerPoint3Bool = ModIDTimerPoint3Bool
{ _mdID :: Int { _mdID :: Int
@@ -1175,9 +1077,7 @@ data InPlacement = InPlacement
makeLenses ''CreatureState makeLenses ''CreatureState
makeLenses ''World makeLenses ''World
makeLenses ''Creature makeLenses ''Creature
makeLenses ''Item
makeLenses ''FloorItem makeLenses ''FloorItem
makeLenses ''TweakParam
makeLenses ''Prop makeLenses ''Prop
makeLenses ''Proj makeLenses ''Proj
makeLenses ''Modification makeLenses ''Modification
@@ -1194,8 +1094,6 @@ makeLenses ''Terminal
makeLenses ''Machine makeLenses ''Machine
makeLenses ''MachineType makeLenses ''MachineType
makeLenses ''Universe makeLenses ''Universe
makeLenses ''ItemParams
makeLenses ''ItemTweaks
makeLenses ''Gust makeLenses ''Gust
makeLenses ''GunBarrels makeLenses ''GunBarrels
makeLenses ''Nozzle makeLenses ''Nozzle
+48 -25
View File
@@ -1,32 +1,55 @@
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-} {-# LANGUAGE StrictData #-}
module Dodge.Data.Item where module Dodge.Data.Item
( module Dodge.Data.Item
, module Dodge.Data.Item.Misc
) where
import Geometry.Data import Geometry.Data
import Control.Lens import Control.Lens
import Dodge.Data.Item.Misc
import Dodge.Data.Item.Consumption
import Dodge.Data.Item.Use
import Dodge.Data.Item.Params
import Dodge.Data.ItEffect
import Dodge.Data.Targeting
import Dodge.Item.Data
import Dodge.Combine.Data
import Dodge.Item.Attachment.Data
import Color
data ItemDimension = ItemDimension import qualified Data.IntMap.Strict as IM
{ _dimRad :: Float data Item = Item
, _dimCenter :: Point3 { _itConsumption :: ItemConsumption
, _dimAttachPos :: Point3 , _itUse :: ItemUse
, _itType :: ItemType
, _itAttachment :: ItAttachment
, _itID :: Maybe Int
, _itPos :: ItemPos
, _itIsHeld :: Bool
, _itEffect :: ItEffect
, _itInvSize :: Float
, _itInvColor :: Color
, _itTargeting :: Targeting
, _itDimension :: ItemDimension
, _itCurseStatus :: CurseStatus
, _itTweaks :: ItemTweaks
, _itScope :: Scope
, _itValue :: ItemValue
, _itParams :: ItemParams
} }
data ItemPortage data ItemTweaks
= HeldItem = NoTweaks
{ _handlePos :: Float | Tweakable
, _muzPos :: Float { _tweakParams :: IM.IntMap TweakParam
, _tweakSel :: Int
} }
| WornItem data TweakParam = TweakParam
| NoPortage { _doTweak :: Int -> Item -> Item
, _curTweak :: Int
data ItemValue = ItemValue , _maxTweak :: Int
{ _ivInt :: Int , _showTweak :: Int -> String
, _ivType :: ItemValueType , _nameTweak :: String
} }
data ItemValueType = MundaneItem | ArtefactItem makeLenses ''Item
data ItemPos makeLenses ''ItemTweaks
= InInv { _ipCrID :: Int , _ipInvID :: Int } makeLenses ''TweakParam
| OnFloor { _ipFlID :: Int }
| VoidItm
makeLenses ''ItemDimension
makeLenses ''ItemPortage
makeLenses ''ItemValue
makeLenses ''ItemPos
+32
View File
@@ -0,0 +1,32 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
module Dodge.Data.Item.Misc where
import Geometry.Data
import Control.Lens
data ItemDimension = ItemDimension
{ _dimRad :: Float
, _dimCenter :: Point3
, _dimAttachPos :: Point3
}
data ItemPortage
= HeldItem
{ _handlePos :: Float
, _muzPos :: Float
}
| WornItem
| NoPortage
data ItemValue = ItemValue
{ _ivInt :: Int
, _ivType :: ItemValueType
}
data ItemValueType = MundaneItem | ArtefactItem
data ItemPos
= InInv { _ipCrID :: Int , _ipInvID :: Int }
| OnFloor { _ipFlID :: Int }
| VoidItm
makeLenses ''ItemDimension
makeLenses ''ItemPortage
makeLenses ''ItemValue
makeLenses ''ItemPos
+81
View File
@@ -1,3 +1,84 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
module Dodge.Data.Item.Params where module Dodge.Data.Item.Params where
import Dodge.Data.Beam
import Dodge.Data.ArcStep
import Geometry.Data
import Color
import Control.Lens
data ItemParams
= NoParams
| ShellLauncher
{ _shellSpinDrag :: Int
, _shellSpinAmount :: Int
, _shellThrustDelay :: Int
}
| Refracting
{ _phaseV :: Float
, _lasColor :: Color
, _lasColor2 :: Color
, _lasCycle :: Int
, _lasDamage :: Int
}
| DualBeam
{ _phaseV :: Float
, _lasColor :: Color
, _lasColor2 :: Color
, _lasCycle :: Int
, _lasDamage :: Int
, _lasBeam :: BeamType
, _subParams :: Maybe ItemParams
, _dbGap :: Float
}
| Attracting {_attractionPower :: Point2}
| BulletShooter
{ _muzVel :: Float
, _rifling :: Float
, _bore :: Float
, _gunBarrels :: GunBarrels
, _recoil :: Float
, _torqueAfter :: Float
, _randomOffset :: Float
}
| Sprayer { _sprayNozzles :: [Nozzle] }
| AngleWalk
{ _maxWalkAngle :: Float
, _currentWalkAngle :: Float
, _walkSpeed :: Float
}
| Arcing
{ _currentArc :: Maybe [ArcStep]
, _arcSize :: Float
, _arcNumber :: Int
, _newArcStep :: NextArcStep --ItemParams -> World -> ArcStep -> State StdGen (Maybe ArcStep)
, _previousArcEffect :: PreviousArcEffect
}
| ParamMID {_paramMID :: Maybe Int}
data PreviousArcEffect = NoPreviousArcEffect | PerturbTillBreakPreviousArc
data GunBarrels
= MultiBarrel
{ _brlSpread :: BarrelSpread
, _brlNum :: Int
, _brlInaccuracy :: Float
}
| RotBarrel
{ _brlNum :: Int
, _brlInaccuracy :: Float
}
| SingleBarrel {_brlInaccuracy :: Float}
data Nozzle = Nozzle
{ _nzPressure :: Float
, _nzDir :: Float
, _nzMaxWalkAngle :: Float
, _nzCurrentWalkAngle :: Float
, _nzWalkSpeed :: Float
, _nzLength :: Float
}
data BarrelSpread
= AlignedBarrels
| SpreadBarrels {_spreadAngle :: Float}
| RotatingBarrels {_rotatingBarrelInaccuracy :: Float}
makeLenses ''BarrelSpread
makeLenses ''ItemParams
+2 -7
View File
@@ -1,13 +1,8 @@
{-# LANGUAGE StrictData #-} {-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-} --{-# LANGUAGE TemplateHaskell #-}
module Dodge.Item.Data where module Dodge.Item.Data where
import Control.Lens --import Control.Lens
data CurseStatus data CurseStatus
= Uncursed = Uncursed
| UndroppableIdentified | UndroppableIdentified
| UndroppableUnidentified | UndroppableUnidentified
data BarrelSpread
= AlignedBarrels
| SpreadBarrels {_spreadAngle :: Float}
| RotatingBarrels {_rotatingBarrelInaccuracy :: Float}
makeLenses ''BarrelSpread