License | BSD-3-Clause |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Swarm.Game.Scenario.Topography.Structure.Recognition.Registry
Description
Registry of found structures. This datatype contains two maps that must be kept in sync. Uses smart constructors to maintain this invariant.
Synopsis
- data FoundRegistry b a
- emptyFoundStructures :: FoundRegistry b a
- populateStaticFoundStructures :: (Eq a, Eq b) => [FoundStructure b a] -> FoundRegistry b a
- foundByName :: FoundRegistry b a -> Map StructureName (NEMap (Cosmic Location, AbsoluteDir) (StructureWithGrid b a))
- foundByLocation :: FoundRegistry b a -> Map (Cosmic Location) (FoundStructure b a)
- addFound :: FoundStructure b a -> FoundRegistry b a -> FoundRegistry b a
- removeStructure :: FoundStructure b a -> FoundRegistry b a -> FoundRegistry b a
Documentation
data FoundRegistry b a Source #
The authoritative source of which built structures currently exist.
The two type parameters, b
and a
, correspond
to Cell
and Entity
, respectively.
Instantiation
emptyFoundStructures :: FoundRegistry b a Source #
populateStaticFoundStructures :: (Eq a, Eq b) => [FoundStructure b a] -> FoundRegistry b a Source #
Bulk insertion of structures statically placed in the scenario definition.
See the docs for initializeRecognition
for more context.
Note that if any of these pre-placed structures overlap, we can't be sure of the author's intent as to which member of the overlap should take precedence, so perhaps it would be ideal to throw an error at scenario parse time.
However, determining whether a structure is all three of:
1. placed
2. still recognizable
3. overlapping with another recognized structure
occurs at a later phase than scenario parse; it requires access to the GameState
.
So we just use the same sorting criteria as the one used to resolve recognition conflicts at entity placement time (see [STRUCTURE RECOGNIZER CONFLICT RESOLUTION]).
Read-only accessors
foundByName :: FoundRegistry b a -> Map StructureName (NEMap (Cosmic Location, AbsoluteDir) (StructureWithGrid b a)) Source #
We use a NEMap
here so that we can use the
safe-indexing function indexWrapNonEmpty
in the implementation
of the structure
command.
foundByLocation :: FoundRegistry b a -> Map (Cosmic Location) (FoundStructure b a) Source #
This is a worldwide "mask" that prevents members of placed structures from participating in new structures and facilitates deletion of structures when their elements are removed from the world.
Each recognized structure instance will have MxN
entries in this map.
Mutation
addFound :: FoundStructure b a -> FoundRegistry b a -> FoundRegistry b a Source #
removeStructure :: FoundStructure b a -> FoundRegistry b a -> FoundRegistry b a Source #