RemotePlayerOnServer class
Remote player in online session.
A connected client's player as simulated and shadowed on the server. Its input (pressed keys) and state are received from the owning client and applied here, with the reported position buffered and interpolated to smooth out network delay.
Base classes
- class PlayerOnServer
- Player on the server in online session.
Public types
- enum class PlayerFlags { None = 0, SpecialMoveMask = 0x07, IsFacingLeft = 0x10, IsVisible = 0x20, IsActivelyPushing = 0x40, JustWarped = 0x100, EnableContinuousJump = 0x200, InMenu = 0x1000, InConsole = 0x2000 }
- State flags of the remote player.
Constructors, destructors, conversion operators
-
RemotePlayerOnServer(std::
shared_ptr<PeerDescriptor> peerDesc) - Creates a new instance.
Public functions
- auto IsContinuousJumpAllowed() const -> bool override
- Returns
trueif continuous jump is allowed. - auto IsLedgeClimbAllowed() const -> bool override
- Returns
trueif ledge climbing is allowed. - auto OnHandleCollision(ActorBase* other) -> bool override
- Called when the object collides with another object.
-
auto OnLevelChanging(Actors::
ActorBase* initiator, ExitType exitType) -> bool override - Called when the level is about to change.
- auto PrepareLevelCarryOver() -> PlayerCarryOver override
- Returns current carry over information.
- void WarpToPosition(Vector2f pos, WarpFlags flags) override
- Warps to a given position.
- void EnableFlyCheat(bool active) override
- Enables or disables fly cheat behavior, enabling it applies to the next cheat flight activation.
- auto Freeze(float timeLeft) -> bool override
- Freezes the player for specified time.
- void SetInvulnerability(float timeLeft, InvulnerableType type) override
- Sets invulnerability to exactly
timeLeftoftype, replacing whatever is running. -
void AddScore(std::
int32_t amount) override - Adds score.
-
auto AddHealth(std::
int32_t amount) -> bool override - Adds health.
-
auto AddLives(std::
int32_t count) -> bool override - Adds lives.
-
auto AddAmmo(WeaponType weaponType,
std::
int16_t count) -> bool override - Adds weapon ammo.
-
void AddWeaponUpgrade(WeaponType weaponType,
std::
uint8_t upgrade) override - Adds weapon upgrade.
- auto SetDizzy(float timeLeft) -> bool override
- Sets duration of dizziness.
- auto FireCurrentWeapon(WeaponType weaponType) -> bool override
- Fires currently equipped weapon.
- void EmitWeaponFlare() override
- Emits weapon flare after firing.
- void SetCurrentWeapon(WeaponType weaponType, SetCurrentWeaponReason reason) override
- Sets current weapon.
- void SyncWithServer(Vector2f pos, Vector2f speed, PlayerFlags flags)
- Synchronizes the player with server.
- void ForceResyncWithServer(Vector2f pos, Vector2f speed)
- Forcefully resynchronizes the player with server (e.g., after respawning or warping).
- void UpdateRendererPosition() override
- Re-applies the current position to the renderer.
Public variables
- PlayerFlags Flags
- State flags.
-
std::
uint64_t PressedKeys - Pressed keys.
-
std::
uint64_t PressedKeysLast - Previously pressed keys.
-
std::
uint32_t UpdatedFrame - Last frame when pressed keys were updated.
Protected functions
- auto OnActivatedAsync(const ActorActivationDetails& details) -> Task<bool> override
- Called when the object is created and activated.
- void OnUpdate(float timeMult) override
- Called every frame to update the object state.
- void OnPushSolidObject(float timeMult, float pushSpeedX) override
- Called when a solid object is pushed.
- void OnHitSpring(Vector2f pos, Vector2f force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove) override
- Called when a spring is hit.
Enum documentation
enum class Jazz2:: Actors:: Multiplayer:: RemotePlayerOnServer:: PlayerFlags
State flags of the remote player.
| Enumerators | |
|---|---|
| None |
None |
| SpecialMoveMask |
Mask of the current special move |
| IsFacingLeft |
Player is facing left |
| IsVisible |
Player is visible |
| IsActivelyPushing |
Player is actively pushing against something |
| JustWarped |
Player has just warped |
| EnableContinuousJump |
Continuous jump is enabled |
| InMenu |
Player has a menu open |
| InConsole |
Player has the console open |
Function documentation
Jazz2:: Actors:: Multiplayer:: RemotePlayerOnServer:: RemotePlayerOnServer(std:: shared_ptr<PeerDescriptor> peerDesc)
Creates a new instance.
| Parameters | |
|---|---|
| peerDesc | Descriptor of the peer this player belongs to |
void Jazz2:: Actors:: Multiplayer:: RemotePlayerOnServer:: SetInvulnerability(float timeLeft,
InvulnerableType type) override
Sets invulnerability to exactly timeLeft of type, replacing whatever is running.
The unconditional setter, and the one a server's authoritative state is applied through - so it has to be able to LOWER the value and to swap a stronger effect for a weaker one, otherwise a correction can never arrive. timeLeft <= 0 clears it.
Gameplay wants GrantInvulnerability() instead: picking something up should not be able to cut short an invulnerability that is already running.
void Jazz2:: Actors:: Multiplayer:: RemotePlayerOnServer:: UpdateRendererPosition() override
Re-applies the current position to the renderer.
Called automatically after the object updates itself. It has to be called again for an object that is moved by something else afterwards (a platform carrying it, for instance), otherwise it would be drawn where it was before that move for one frame. An object that is drawn somewhere else than where it is simulated (a server-side shadow of a remote player showing its interpolated position) overrides this instead of assigning the position to the renderer on its own.