EventMap class
#include <Jazz2/Events/EventMap.h>
Represents event map, spawns triggered objects.
Owns the per-tile event layout of a level, together with spawn points, warp targets and active generators. Activates, deactivates and respawns actors as the level is played, supports rollback checkpoints, and can be serialized to and restored from a stream.
Off-grid events — objects placed at any position, not aligned to the tiles — get a tile of their own in rows past the bottom of the event grid, one for each, so everything that refers to an event by its tile (an object deactivated or collected, a generator, a checkpoint, a snapshot) works for them too. Their object is spawned at their own position, and only queries by position in the level (GetEventByPosition() and the like) never see them. Starts and warp targets among them keep their exact position. The events that act through the tile they're in rather than through an object (modifiers, areas, warp origins and the like, see IsTileEffectEvent()) are applied to that tile, unless an event of the grid is there in any difficulty. Every off-grid event gets its tile before the events are filtered by the difficulty, so the tiles are the same in any difficulty, on a server and on its clients.
Public types
- struct EventTile
- Represents an event tile.
- struct DifficultyEventInfo
- Event meant only for the easy or only for the hard difficulty, see CollectEasyOrHardEvents().
Public static functions
- static auto IsTileEffectEvent(EventType type) -> bool
- Returns
trueif an event acts through the tile it's in rather than through an object.
Constructors, destructors, conversion operators
- EventMap(Vector2i layoutSize)
- Creates a new instance with the specified layout size.
Public functions
- void SetLevelHandler(ILevelHandler* levelHandler)
- Sets owner of the event map.
- auto HasLoadFailed() const -> bool
- Whether reading the events ran out of memory (the level cannot be played).
- auto GetSize() const -> Vector2i
- Returns size of event map in tiles.
- auto GetPitType() const -> PitType
- Returns pit type.
- void SetPitType(PitType value)
- Sets pit type.
- auto GetSpawnPosition(PlayerType type) -> Vector2f
- Returns spawn position for specified player type.
- void CreateCheckpointForRollback()
- Creates a checkpoint for eventual rollback.
- void RollbackToCheckpoint(bool respawnActors = true)
- Rolls back to the last checkpoint.
-
void StoreTileEvent(std::
int32_t x, std:: int32_t y, EventType eventType, Actors:: ActorState eventFlags = Actors::ActorState::None, std:: uint8_t* tileParams = nullptr) - Stores tile event description.
- void PreloadEventsAsync()
- Preloads assets of all contained events.
- void ProcessGenerators(float timeMult)
- Processes all generators.
-
void ActivateEvents(std::
int32_t tx1, std:: int32_t ty1, std:: int32_t tx2, std:: int32_t ty2, bool allowAsync) - Activates all inactive events in specified tile restangle.
- auto TakeActivationChanges(AABBi& bounds) -> bool
- Returns
trueif an event was deactivated or put in a tile since the last call. -
void Deactivate(std::
int32_t x, std:: int32_t y) - Deactivates event on specified tile position.
-
void ResetGenerator(std::
int32_t tx, std:: int32_t ty) - Resets generator on specified tile position.
-
void Activate(std::
int32_t x, std:: int32_t y) - Marks event on specified tile position as active, i.e., its object already exists.
-
void AttachGeneratorActor(std::
int32_t tx, std:: int32_t ty, std:: shared_ptr<Actors:: ActorBase> actor) - Links an object restored from a snapshot to the generator on specified tile position.
-
auto GetEventTile(std::
int32_t x, std:: int32_t y) const -> const EventTile& - Returns event description of specified tile position, or of the tile of an off-grid event.
-
auto GetGeneratorEvent(std::
int32_t x, std:: int32_t y, EventType& type, const std:: uint8_t*& params, std:: uint8_t& delay) const -> bool - Returns the event a generator on specified tile position spawns, its parameters and its delay in seconds.
-
auto GetEventDifficulty(std::
int32_t x, std:: int32_t y) const -> std:: uint8_t - Returns the difficulty of the event of the level on specified tile position as the original game has it.
- void CollectEasyOrHardEvents(SmallVectorImpl<DifficultyEventInfo>& events) const
- Collects all events meant only for the easy or only for the hard difficulty.
-
void ActivateSkippedDifficultyEvents(Tiles::
TileMap& tileMap) - Puts the easy-only and hard-only events left out in the current difficulty back into the level.
-
auto GetStartOrWarpTarget(std::
int32_t x, std:: int32_t y, std:: uint8_t* params) const -> EventType - Returns the start or the warp target on specified tile position, which aren't kept in the tiles.
-
auto GetEventPosition(std::
int32_t x, std:: int32_t y) const -> Vector2i - Returns the position in pixels the object of the event of a tile is spawned at.
- auto GetOriginTile(Vector2i pos, EventType type) -> Vector2i
- Returns the tile of the event an object spawned from the event map at a position comes from.
-
auto GetOffGridEventCount() const -> std::
int32_t - Returns the number of off-grid events.
-
auto GetEventByPosition(float x,
float y,
std::
uint8_t** eventParams) -> EventType - Returns event type on specified position.
-
auto GetEventByPosition(std::
int32_t x, std:: int32_t y, std:: uint8_t** eventParams) -> EventType -
auto HasEventByPosition(std::
int32_t x, std:: int32_t y) const -> bool - Returns
trueif specified tile position contains an event. -
void ForEachEvent(Function<bool(EventTile&, std::
int32_t, std:: int32_t)>&& forEachCallback, bool includeOffGrid = false) const - Calls specified callback function for each event, until it returns
false. - auto IsHurting(float x, float y, Direction dir) -> bool
- Returns
trueif specified position contains hurt event. -
auto IsHurting(std::
int32_t x, std:: int32_t y, Direction dir) -> bool -
auto GetWarpByPosition(float x,
float y) -> std::
int32_t - Returns ID of warp on specified position.
-
auto GetWarpTarget(std::
uint32_t id) -> Vector2f - Returns target position for specified warp.
-
auto IsNearWarpTarget(std::
uint32_t id, Vector2f pos, float distance) const -> bool - Returns
trueif any target of specified warp lies withindistanceofpos. -
void LoadEvents(Formats::
LevelReader& reader, Tiles:: TileMap& tileMap, const LevelLoadOptions& options) - Reads the events of a level.
-
void AddWarpTarget(std::
uint16_t id, std:: int32_t x, std:: int32_t y, const std:: uint8_t* eventParams = nullptr) - Adds target position for specified warp, and the last bytes of the parameters of its event, see GetStartOrWarpTarget().
-
void AddSpawnPosition(std::
uint8_t typeMask, std:: int32_t x, std:: int32_t y, const std:: uint8_t* eventParams = nullptr) - Adds spawn position with specified player type mask, and the last bytes of the parameters of its event, see GetStartOrWarpTarget().
- auto InitializeFromStream(Stream& src) -> bool
- Initializes event map state from a stream.
- void SerializeResumableToStream(Stream& dest, bool fromCheckpoint = false)
- Serializes event map state to a stream.
- auto InitializeActiveStateFromStream(Stream& src) -> bool
- Initializes active state of all events from a stream.
- void SerializeActiveStateToStream(Stream& dest, bool fromCheckpoint = false)
- Serializes active state of all events (the current one or at the last checkpoint) to a stream.
- auto InitializeSnapshotFromStream(Stream& src) -> bool
- Restores complete live state of the event map (including the last checkpoint) from a snapshot.
- void SerializeSnapshotToStream(Stream& dest)
- Serializes complete live state of the event map (including the last checkpoint) to a snapshot.
Function documentation
static bool Jazz2:: Events:: EventMap:: IsTileEffectEvent(EventType type)
Returns true if an event acts through the tile it's in rather than through an object.
Modifiers, areas, warp origins and the like, which are looked up by position in the level. An off-grid one is applied to the tile its position is in (see EventMap).
void Jazz2:: Events:: EventMap:: RollbackToCheckpoint(bool respawnActors = true)
Rolls back to the last checkpoint.
| Parameters | |
|---|---|
| respawnActors | Spawn again all objects that were active at the checkpoint but aren't anymore, pass false if the objects are restored from a snapshot instead |
bool Jazz2:: Events:: EventMap:: TakeActivationChanges(AABBi& bounds)
Returns true if an event was deactivated or put in a tile since the last call.
bounds are the tiles around those events. A rectangle searched by ActivateEvents() doesn't have to be searched again until a change in it is reported here.
bool Jazz2:: Events:: EventMap:: GetGeneratorEvent(std:: int32_t x,
std:: int32_t y,
EventType& type,
const std:: uint8_t*& params,
std:: uint8_t& delay) const
Returns the event a generator on specified tile position spawns, its parameters and its delay in seconds.
Returns false if there's no generator on the tile.
std:: uint8_t Jazz2:: Events:: EventMap:: GetEventDifficulty(std:: int32_t x,
std:: int32_t y) const
Returns the difficulty of the event of the level on specified tile position as the original game has it.
0 for an event of every difficulty, 1 for an easy one, 2 for a hard one and 3 for a multiplayer-only one. An event left out in this difficulty isn't in the tile at all, as in JJ2+. Scripts of JJ2+ read it as the event's parameter.
void Jazz2:: Events:: EventMap:: CollectEasyOrHardEvents(SmallVectorImpl<DifficultyEventInfo>& events) const
Collects all events meant only for the easy or only for the hard difficulty.
Includes those left out in the current difficulty, multiplayer modes use them as control points.
void Jazz2:: Events:: EventMap:: ActivateSkippedDifficultyEvents(Tiles:: TileMap& tileMap)
Puts the easy-only and hard-only events left out in the current difficulty back into the level.
Every multiplayer mode but Cooperation keeps these events working, the level may rely on them (e.g., a warp out of the room of a capture point).
EventType Jazz2:: Events:: EventMap:: GetStartOrWarpTarget(std:: int32_t x,
std:: int32_t y,
std:: uint8_t* params) const
Returns the start or the warp target on specified tile position, which aren't kept in the tiles.
Returns EventType::params gets the parameters of the event as far as they're kept, the player types or the ID and the last bytes (see Formats::
Vector2i Jazz2:: Events:: EventMap:: GetEventPosition(std:: int32_t x,
std:: int32_t y) const
Returns the position in pixels the object of the event of a tile is spawned at.
The center of the tile, or the position of an off-grid event if the tile is one of theirs.
Vector2i Jazz2:: Events:: EventMap:: GetOriginTile(Vector2i pos,
EventType type)
Returns the tile of the event an object spawned from the event map at a position comes from.
The tile of an off-grid event of the type at exactly that position — or of an off-grid generator of it — otherwise the tile the position is in. The object being spawned from a tile right now gets that tile, only the first lookup that matches it does, an object of the same type it spawns there isn't from the tile.
EventType Jazz2:: Events:: EventMap:: GetEventByPosition(std:: int32_t x,
std:: int32_t y,
std:: uint8_t** eventParams)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void Jazz2:: Events:: EventMap:: ForEachEvent(Function<bool(EventTile&, std:: int32_t, std:: int32_t)>&& forEachCallback,
bool includeOffGrid = false) const
Calls specified callback function for each event, until it returns false.
The events of the grid come row by row. With includeOffGrid the off-grid events come after them, with the coordinates of the tile their position is in, which can lie outside of the level (their own tile is past the grid, see EventMap).
bool Jazz2:: Events:: EventMap:: IsHurting(std:: int32_t x,
std:: int32_t y,
Direction dir)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void Jazz2:: Events:: EventMap:: LoadEvents(Formats:: LevelReader& reader,
Tiles:: TileMap& tileMap,
const LevelLoadOptions& options)
Reads the events of a level.
Only the events present in the difficulty of options are added (and the multiplayer-only ones only in multiplayer). The tile modifiers among them are also applied to the sprite layer of tileMap.
bool Jazz2:: Events:: EventMap:: InitializeFromStream(Stream& src)
Initializes event map state from a stream.
Returns false if the state belongs to a layout of another size, such as of a level changed since, nothing is changed then and the rest of the state in the stream can't be read either.
bool Jazz2:: Events:: EventMap:: InitializeActiveStateFromStream(Stream& src)
Initializes active state of all events from a stream.
Returns false if the state belongs to a layout of another size, nothing is changed then.