Jazz2::Multiplayer::MpLevelHandler class

Level handler of an online multiplayer game session.

Base classes

class Jazz2::LevelHandler
Level handler of a local game session.

Public types

enum class LevelState { Unknown, InitialUpdatePending, PreGame, WaitingForMinPlayers, Countdown3, Countdown2, Countdown1, Running, Ending, Ended }
Level state.

Public static functions

static auto GetWeaponOwner(Actors::ActorBase* actor) -> Actors::Multiplayer::MpPlayer*
Returns owner of the specified object or the player itself.

Constructors, destructors, conversion operators

MpLevelHandler(IRootController* root, NetworkManager* networkManager, LevelState levelState, bool enableLedgeClimb)
~MpLevelHandler() override

Public functions

auto Initialize(const LevelInitialization& levelInit) -> bool override
Initializes the level handler from LevelInitialization.
auto IsLocalSession() const -> bool override
Returns true if the level handler is on a local session.
auto IsPausable() const -> bool override
Returns true if the level handler is pausable.
auto GetHurtInvulnerableTime() const -> float override
Returns default invulnerable time when a player is hurt.
auto GetDefaultAmbientLight() const -> float override
Returns default ambient light intensity.
void SetAmbientLight(Actors::Player* player, float value) override
Sets current ambient light intensity.
void OnBeginFrame() override
Called at the beginning of each frame.
void OnEndFrame() override
Called at the end of each frame.
void OnInitializeViewport(std::int32_t width, std::int32_t height) override
Called when the viewport needs to be initialized (e.g., when the resolution is changed)
auto OnConsoleCommand(StringView line) -> bool override
Called when a console command is entered.
void OnKeyPressed(const KeyboardEvent& event) override
Called when a key is pressed.
void OnKeyReleased(const KeyboardEvent& event) override
Called when a key is released.
void OnTouchEvent(const TouchEvent& event) override
Called when a touch event is triggered.
void AddActor(std::shared_ptr<Actors::ActorBase> actor) override
Adds an actor (object) to the level.
auto PlaySfx(Actors::ActorBase* self, StringView identifier, AudioBuffer* buffer, const Vector3f& pos, bool sourceRelative, float gain, float pitch) -> std::shared_ptr<AudioBufferPlayer> override
Plays a sound effect for a given actor (object)
auto PlayCommonSfx(StringView identifier, const Vector3f& pos, float gain = 1.0f, float pitch = 1.0f) -> std::shared_ptr<AudioBufferPlayer> override
Plays a common sound effect.
void WarpCameraToTarget(Actors::ActorBase* actor, bool fast = false) override
Warps a camera to its assigned target.
auto IsPositionEmpty(Actors::ActorBase* self, const AABBf& aabb, TileCollisionParams& params, Actors::ActorBase** collider) -> bool override
Returns true if a specified AABB is empty.
void FindCollisionActorsByAABB(const Actors::ActorBase* self, const AABBf& aabb, Function<bool(Actors::ActorBase*)>&& callback) override
Calls the callback function for all colliding objects with specified AABB.
void FindCollisionActorsByRadius(float x, float y, float radius, Function<bool(Actors::ActorBase*)>&& callback) override
Calls the callback function for all colliding objects with specified circle.
void GetCollidingPlayers(const AABBf& aabb, Function<bool(Actors::ActorBase*)>&& callback) override
Calls the callback function for all colliding players with specified AABB.
void BroadcastTriggeredEvent(Actors::ActorBase* initiator, EventType eventType, std::uint8_t* eventParams) override
Broadcasts specified event to all other actors.
void BeginLevelChange(Actors::ActorBase* initiator, ExitType exitType, StringView nextLevel = {}) override
Starts transition to change current level.
void HandleLevelChange(LevelInitialization&& levelInit) override
Called when the level is changed.
void HandleGameOver(Actors::Player* player) override
Called when the game is over.
auto HandlePlayerDied(Actors::Player* player) -> bool override
Called when a player dies.
void HandlePlayerWarped(Actors::Player* player, Vector2f prevPos, WarpFlags flags) override
Called when a player warps.
void HandlePlayerCoins(Actors::Player* player, std::int32_t prevCount, std::int32_t newCount) override
Called when a player collects or losts coins.
void HandlePlayerGems(Actors::Player* player, std::uint8_t gemType, std::int32_t prevCount, std::int32_t newCount) override
Called when a player collects or losts gems.
void SetCheckpoint(Actors::Player* player, Vector2f pos) override
Sets checkpoint for a given player.
void RollbackToCheckpoint(Actors::Player* player) override
Rolls back to the last checkpoint for a given player.
void HandleActivateSugarRush(Actors::Player* player) override
Called when a player activates sugar rush.
void ShowLevelText(StringView text, Actors::ActorBase* initiator = nullptr) override
Shows a text notification.
auto GetLevelText(std::uint32_t textId, std::int32_t index = -1, std::uint32_t delimiter = 0) -> StringView override
Returns a level text.
void OverrideLevelText(std::uint32_t textId, StringView value) override
Override specified level text.
void LimitCameraView(Actors::Player* player, std::int32_t left, std::int32_t width) override
Limits camera viewport for a given player.
void ShakeCameraView(Actors::Player* player, float duration) override
Shake camera for a given player.
void ShakeCameraViewNear(Vector2f pos, float duration) override
Shake camera for all players near a given position.
void SetTrigger(std::uint8_t triggerId, bool newState) override
Sets state of a given trigger in the tile map.
void SetWeather(WeatherType type, std::uint8_t intensity) override
Sets current level weather.
auto BeginPlayMusic(StringView path, bool setDefault = false, bool forceReload = false) -> bool override
Plays specified music.
auto PlayerActionPressed(Actors::Player* player, PlayerAction action, bool includeGamepads = true) -> bool override
Returns true if player action is pressed.
auto PlayerActionPressed(Actors::Player* player, PlayerAction action, bool includeGamepads, bool& isGamepad) -> bool override
auto PlayerActionHit(Actors::Player* player, PlayerAction action, bool includeGamepads = true) -> bool override
Returns true if player action is hit (newly pressed)
auto PlayerActionHit(Actors::Player* player, PlayerAction action, bool includeGamepads, bool& isGamepad) -> bool override
auto PlayerHorizontalMovement(Actors::Player* player) -> float override
Returns value of desired horizontal player movement.
auto PlayerVerticalMovement(Actors::Player* player) -> float override
Returns value of desired vertical player movement.
void PlayerExecuteRumble(Actors::Player* player, StringView rumbleEffect) override
Executes a rumble effect.
auto SerializeResumableToStream(Stream& dest) -> bool override
Serializes object state to a stream.
void OnAdvanceDestructibleTileAnimation(std::int32_t tx, std::int32_t ty, std::int32_t amount) override
Called when a destructible tile animation is advanced.
auto GetGameMode() const -> MpGameMode
Returns current game mode.
auto SetGameMode(MpGameMode value) -> bool
Sets current game mode.
auto ProcessCommand(const Peer& peer, StringView line, bool isAdmin) -> bool
Processes the specified server command.
void SendMessage(const Peer& peer, UI::MessageLevel level, StringView message)
Sends the message to the specified peer.
auto OnPeerDisconnected(const Peer& peer) -> bool
Called when a peer disconnects from the server, see INetworkHandler.
auto OnPacketReceived(const Peer& peer, std::uint8_t channelId, std::uint8_t packetType, ArrayView<const std::uint8_t> data) -> bool
Called when a packet is received, see INetworkHandler.

Protected functions

void AttachComponents(LevelDescriptor&& descriptor) override
Attaches all required level components to the handler.
auto CreateHUD() -> std::unique_ptr<UI::HUD> override
Creates HUD.
void SpawnPlayers(const LevelInitialization& levelInit) override
Spawns all players.
auto IsCheatingAllowed() -> bool override
Returns true if cheats are enabled.
void BeforeActorDestroyed(Actors::ActorBase* actor) override
Called before an actor (object) is destroyed.
void ProcessEvents(float timeMult) override
Processes events.
void HandlePlayerLevelChanging(Actors::Player* player, ExitType exitType)
Called when a player entered a transition to change the level.
auto HandlePlayerSpring(Actors::Player* player, Vector2f pos, Vector2f force, bool keepSpeedX, bool keepSpeedY) -> bool
Called when a player interacts with a spring.
void HandlePlayerBeforeWarp(Actors::Player* player, Vector2f pos, WarpFlags flags)
Called when a player is going to warp.
void HandlePlayerSetModifier(Actors::Player* player, Actors::Player::Modifier modifier, const std::shared_ptr<Actors::ActorBase>& decor)
Called when a player changed modifier.
void HandlePlayerTakeDamage(Actors::Player* player, std::int32_t amount, float pushForce)
Called when a player takes a damage.
void HandlePlayerRefreshAmmo(Actors::Player* player, WeaponType weaponType)
Called when a player requests to synchronize weapon ammo.
void HandlePlayerRefreshWeaponUpgrades(Actors::Player* player, WeaponType weaponType)
Called when a player requests to synchronize weapon upgrades.
void HandlePlayerSetDizzyTime(Actors::Player* player, float timeLeft)
Called when a player changed dizzy duration.
void HandlePlayerEmitWeaponFlare(Actors::Player* player)
Called when a player emits a weapon flare.
void HandlePlayerWeaponChanged(Actors::Player* player)
Called when a player changes their current weapon.

Enum documentation

enum class Jazz2::Multiplayer::MpLevelHandler::LevelState

Level state.

Enumerators
Unknown

Unknown

InitialUpdatePending

Level was just created and initial update needs to be sent

PreGame

Pre-game is active

WaitingForMinPlayers

Pre-game ended, but not enough players connected yet

Countdown3

Countdown started (3)

Countdown2

Countdown continues (2)

Countdown1

Countdown continues (1)

Running

Round started

Ending

Round is ending

Ended

Round ended

Function documentation

bool Jazz2::Multiplayer::MpLevelHandler::PlayerActionPressed(Actors::Player* player, PlayerAction action, bool includeGamepads, bool& isGamepad) override

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool Jazz2::Multiplayer::MpLevelHandler::PlayerActionHit(Actors::Player* player, PlayerAction action, bool includeGamepads, bool& isGamepad) override

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.