Jazz2::Actors::ActorBase class

Base class of an object.

Shared lifecycle of every object in the game world: activation, update, movement, collisions, rendering, lights and health. Derived actors override the virtual callbacks.

Derived classes

class CollectibleBase
Base class of a collectible object.
class GemGiant
Giant gem.
class EnemyBase
Base class of an enemy.
class AirboardGenerator
Airboard generator.
class AmbientBubbles
Ambient bubbles.
class AmbientSound
Ambient sound.
class Bird
Bird.
class Bomb
Bomb.
class BonusWarp
Bonus warp.
class Checkpoint
Checkpoint.
class Copter
Copter.
class EndOfLevel
End of level sign.
class Eva
Eva.
class IceBlock
Ice block.
class Moth
Moth.
class Spring
Spring.
class SteamNote
Steam note.
class SwingingVine
Swinging vine.
class Explosion
Explosion effects.
class FlickerLight
Flickering light.
class PulsatingRadialLight
Pulsating radial light.
class StaticRadialLight
Static radial light.
class CtfBase
Capture The Flag base.
class Flag
Capture The Flag flag/base marker.
class GameModeObjectActor
Object of a game mode in the level.
class RemoteActor
Remote object in online session.
class Player
Represents a controllable player.
class PlayerCorpse
Represents a dead corpse of a player.
class Bridge
Bridge.
class Pole
Pole.
class SolidObjectBase
Base class of a (pushable) solid object.
class ShotBase
Base class of a shot from a player's weapon.
class TNT
TNT.
class Jazz2::Scripting::Legacy::ScriptEventObject
Object of an event the game has no object of (EventType::PassthroughEvent).
class Jazz2::Scripting::Legacy::ScriptSceneryObject
Destructible scenery as an object of the game, for a level script that drives it.
class Jazz2::Scripting::ScriptActorWrapper
Wraps a scripted actor, forwarding engine callbacks to the AngelScript object.

Public static functions

static auto HandleCollisionByOverride(ActorBase* a, ActorBase* b) -> bool
Lets the overrides of two colliding objects handle the collision, returns true if one did.

Constructors, destructors, conversion operators

ActorBase()
Creates a new instance.
~ActorBase() virtual

Public functions

auto IsFacingLeft() const -> bool
Returns true if the object is currently facing left.
auto IsGravityFlipped() const -> bool
Returns true if gravity pulls the object up, see SetGravityFlipped().
auto OnActivated(const ActorActivationDetails& details) -> Task<bool>
Called after the object is created.
auto OnHandleCollision(ActorBase* other) -> bool virtual
Called when the object collides with another object.
auto CanCauseDamage(ActorBase* collider) -> bool virtual
Called to check whether collider can cause damage to the object.
auto IsInvulnerable() -> bool
Returns true if the object is invulnerable.
auto IsFrozen() const -> bool
Returns true if the object is frozen.
auto GetHealth() -> std::int32_t
Returns current health.
void SetHealth(std::int32_t value)
Sets current health.
auto GetMaxHealth() -> std::int32_t
Returns maximum health.
void DecreaseHealth(std::int32_t amount = 1, ActorBase* collider = nullptr)
Decreases health by specified amount.
auto MoveInstantly(Vector2f pos, MoveType type, Tiles::TileCollisionParams& params) -> bool
Moves the object.
auto MoveInstantly(Vector2f pos, MoveType type) -> bool
void AddExternalForce(float x, float y)
Adds external force.
auto IsCollidingWith(ActorBase* other) -> bool
Returns true if this object is colliding with a given object.
auto IsCollidingWith(const AABBf& aabb) -> bool
Returns true if this object is colliding with a given AABB.
auto GetOverlappingPixelCount(ActorBase* other, std::int32_t limit) -> std::int32_t
Counts the opaque pixels the drawn frames of both objects share, up to limit.
auto HasCrossedOver(const ActorBase* other) const -> bool
Returns true if this object crossed over a given object during the current frame.
void UpdateAABB()
Updates AABB for current position, rotation and animation frame.
void UpdateRendererPosition() virtual
Re-applies the current position to the renderer.
auto GetPos() -> Vector2f
Returns current position.
auto GetSpeed() -> Vector2f
Returns current speed.
auto GetState() const -> ActorState constexpr noexcept
Returns actor state.
auto GetState(ActorState flag) const -> bool constexpr noexcept
auto GetSpawnEventType() const -> EventType noexcept
Returns event type the object was spawned from, or EventType::Empty if it wasn't created from an event.
auto GetSpawnEventParams() const -> const std::uint8_t* noexcept
Returns parameters of the event the object was spawned from, see GetSpawnEventType().
void SetUpdateOverride(std::unique_ptr<IActorUpdateOverride> value)
Hands the per-frame update over to an override, or takes it back with nullptr.
auto GetUpdateOverride() const -> IActorUpdateOverride*
Returns the update override, or nullptr.
void EmitLights(SmallVectorImpl<LightEmitter>& lights)
Adds the lights of the object and of its update override.

Public variables

AABBf AABB
Outer AABB hitbox.
AABBf AABBInner
Inner AABB hitbox.

Protected types

class ActorRenderer
Actor renderer.

Protected static functions

static void PreloadMetadataAsync(StringView path)
Preloads specified metadata and its linked assets to cache.

Protected functions

void SetParent(SceneNode* parent)
Sets internal parent node.
void SetFacingLeft(bool value)
Sets whether the object is facing left.
void SetGravityFlipped(bool value) virtual
Sets whether gravity pulls the object up.
auto ToGravitySpace(const AABBf& box) const -> AABBf
Converts a box between the world and the space where down is along the object's gravity.
auto ToGravitySpace(Vector2f move) const -> Vector2f
Converts a move between the world and the space where down is along the object's gravity.
auto MoveAlongGravity(Vector2f move, MoveType type, Tiles::TileCollisionParams& params) -> bool
Moves the object relatively in the space of its gravity, see ToGravitySpace().
auto OnActivatedAsync(const ActorActivationDetails& details) -> Task<bool> virtual
Called when the object is created and activated.
auto OnTileDeactivated() -> bool virtual
Called when corresponding tile should be deactivated.
auto IsSerializable() const -> bool virtual
Returns true if the live state of the object can be stored in a level state snapshot.
void OnSerializeState(Stream& dest) virtual
Serializes the live state of the object to a level state snapshot.
void OnDeserializeState(Stream& src) virtual
Restores the live state of the object from a level state snapshot.
void OnAttach(ActorBase* parent) virtual
Called when the object is attached to an another object.
void OnDetach(ActorBase* parent) virtual
Called when the object is detached from the previously attached object.
void OnHealthChanged(ActorBase* collider) virtual
Called when health of the object changed.
auto OnPerish(ActorBase* collider) -> bool virtual
Called when the object has no health left and should perish.
void OnUpdate(float timeMult) virtual
Called every frame to update the object state.
void OnUpdateHitbox() virtual
Called when the hitbox needs to be updated.
auto OnDraw(RenderQueue& renderQueue) -> bool virtual
Called when the object needs to be drawn.
void OnEmitLights(SmallVectorImpl<LightEmitter>& lights) virtual
Called when emitting lights.
void OnEmitRemotedLights(SmallVectorImpl<LightEmitter>& lights) virtual
Called when emitting lights that have to be replicated to remote peers.
auto IsIlluminatedStateRemoted() const -> bool virtual
Whether an observer reproduces this object's ActorState::Illuminated decoration itself.
auto GetFrozenMomentumX() const -> float
Returns how fast the object slides while frozen, see ActorState::KeepsMomentumWhenFrozen.
void OnHitFloor(float timeMult) virtual
Called when the object hits a floor.
void OnHitCeiling(float timeMult) virtual
Called when the object hits a ceiling.
void OnHitWall(float timeMult) virtual
Called when the object hits a wall.
auto GetGravityModifier(float baseGravity, bool isRising) const -> float virtual
Returns the gravity applied this frame, may depend on direction (e.g., the player's jump arc).
void SetAnimationTicks(float ticks)
Sets how long the animation or transition just started lasts, in ticks of the original game (70 a second).
void ChangeAnimationTicks(float ticks)
Like SetAnimationTicks(), but keeps how far through the animation it is.
void SetAnimationTimeTicks(float ticks)
Sets how far into the current animation it is, in ticks of the original game.
auto ReplaceLevelGravity(float gravity, float baseGravity) const -> float
Returns baseGravity with the gravity of the level replaced by the given one, for an override of GetGravityModifier().
void OnTriggeredEvent(EventType eventType, std::uint8_t* eventParams) virtual
Called when an event is triggered.
void TryStandardMovement(float timeMult, Tiles::TileCollisionParams& params)
Performs standard movement behavior.
void ResetPathTracking()
Discards the path the object travelled so far during the current frame.
auto TryUnstuck() -> bool
Tries to push the actor out of solid geometry it ended up inside of.
void UpdateHitbox(std::int32_t w, std::int32_t h)
Updates hitbox to a given size.
auto UpdateFrozenState(float timeMult, bool frictionApplied = false) -> bool
Updates frozen state of the object, returns true if it thawed in this frame.
void ApplyFrozenFriction(float timeMult)
Slows a frozen object that keeps its momentum by one frame's friction.
void ThawOnNextUpdate()
Ends the freeze at once, the ice breaks in the next UpdateFrozenState().
void HandleFrozenStateChange(ActorBase* shot)
Handles change of frozen state after collision with other object.
void CreateParticleDebrisOnPerish(ActorBase* collider)
Creates a particle debris from a sprite when the object is going to perish.
void CreateParticleDebrisOnPerish(ParticleDebrisEffect effect, Vector2f speed)
void CreateSpriteDebris(AnimState state, std::int32_t count, float elasticity = 0.8f)
Creates a sprite debris, its pieces keep elasticity of their speed on bounce.
auto GetIceShrapnelScale() const -> float virtual
Returns scale of ice shrapnels.
auto PlaySfx(StringView identifier, float gain = 1.0f, float pitch = 1.0f, SfxFlags flags = SfxFlags::None) -> std::shared_ptr<AudioBufferPlayer>
Plays a sound effect for the object.
auto SetAnimation(AnimState state, bool skipAnimation = false) -> bool
Sets an animation of the object.
void SetAnimationFrame(std::int32_t frame)
Pauses the current animation on the specified frame, for objects that count their frames themselves.
auto SetTransition(AnimState state, bool cancellable, Function<void()>&& callback = {}) -> bool
Sets a transition animation of the object.
void CancelTransition()
Cancels a cancellable transition.
void ForceCancelTransition()
Cancels any transition.
void OnAnimationStarted() virtual
Called when an animation started.
void OnAnimationFinished() virtual
Called when an animation finished.
void OnPacketReceived(MemoryStream& packet) virtual
Called when the object receives a network packet.
void SendPacket(ArrayView<const std::uint8_t> data)
Sends a packet to the other side of a non-local session.
void RequestMetadata(StringView path, bool forceIndexed = false)
Loads specified metadata and its linked assets.
void RequestMetadataAsync(StringView path, bool forceIndexed = false)
Loads specified metadata and its linked assets asynchronously if supported.
void SetState(ActorState flags) constexpr noexcept
Sets actor state.
void SetState(ActorState flag, bool value) constexpr noexcept

Constants

static std::uint8_t AlphaThreshold protected constexpr
Alpha transparency threshold, same as the collision masks.
static float CollisionCheckStep protected constexpr
Step for collision checking.
static float AirFloorSnapMinStepX protected constexpr
static float LandingStepHeight protected constexpr
static float MaxMovementStep protected constexpr
Longest single collision sub-step of TryStandardMovement().
static std::int32_t MaxMovementSubsteps protected constexpr
Most collision sub-steps of TryStandardMovement() per frame.
static float MaxUnstuckDistance protected constexpr
Farthest TryUnstuck() moves an actor out of solid geometry.
static float UnstuckRetryNotStuck protected constexpr
Frames before TryUnstuck() probes again for an actor that wasn't stuck.
static float UnstuckRetryTrapped protected constexpr
Frames before TryUnstuck() searches again for a trapped actor.
static float UnstuckCooldown protected constexpr
Frames before TryUnstuck() runs again for an actor it successfully freed.
static std::int32_t PerPixelCollisionStep protected constexpr
Step for per-pixel collisions.
static std::int32_t AnimationCandidatesCount protected constexpr
Maximum number of animation candidates.
static std::int32_t SpawnParamsSize protected constexpr
Size of spawn event parameters, same as Events::EventSpawner::SpawnParamsSize.

Function documentation

bool Jazz2::Actors::ActorBase::MoveInstantly(Vector2f pos, MoveType type)

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

bool Jazz2::Actors::ActorBase::HasCrossedOver(const ActorBase* other) const

Returns true if this object crossed over a given object during the current frame.

Tests the path taken, so it catches a fast object passing a small one between frames, which IsCollidingWith() misses.

void Jazz2::Actors::ActorBase::UpdateRendererPosition() virtual

Re-applies the current position to the renderer.

Called after the object updates itself, call it again if something else moves the object afterwards. An object drawn elsewhere than it is simulated overrides it.

bool Jazz2::Actors::ActorBase::GetState(ActorState flag) const constexpr noexcept

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

void Jazz2::Actors::ActorBase::SetUpdateOverride(std::unique_ptr<IActorUpdateOverride> value)

Hands the per-frame update over to an override, or takes it back with nullptr.

The override then decides when the object updates, see IActorUpdateOverride.

void Jazz2::Actors::ActorBase::SetGravityFlipped(bool value) virtual protected

Sets whether gravity pulls the object up.

The object is drawn upside down and the standard movement treats the ceiling as its floor. Its vertical speed and forces point along its gravity, so they're negated by the change and the motion is kept.

bool Jazz2::Actors::ActorBase::IsSerializable() const virtual protected

Returns true if the live state of the object can be stored in a level state snapshot.

Only for objects spawned from an event registered in Events::EventSpawner. Short-lived objects can opt out by overriding it.

void Jazz2::Actors::ActorBase::OnSerializeState(Stream& dest) virtual protected

Serializes the live state of the object to a level state snapshot.

State set from the event parameters needn't be stored, the object is spawned again with them. Derived classes call the base first and read the data back in the same order.

void Jazz2::Actors::ActorBase::OnDeserializeState(Stream& src) virtual protected

Restores the live state of the object from a level state snapshot.

Called after OnActivatedAsync(), before the object is added to the level. Running transitions aren't restored, so the restored state must not wait for a transition callback.

void Jazz2::Actors::ActorBase::OnEmitRemotedLights(SmallVectorImpl<LightEmitter>& lights) virtual protected

Called when emitting lights that have to be replicated to remote peers.

Defaults to OnEmitLights(). Override it to leave out lights that clients produce on their own.

bool Jazz2::Actors::ActorBase::IsIlluminatedStateRemoted() const virtual protected

Whether an observer reproduces this object's ActorState::Illuminated decoration itself.

Only for objects that turn the flag into lights. They leave those lights out of OnEmitRemotedLights() and every observer spawns its own.

void Jazz2::Actors::ActorBase::ResetPathTracking() protected

Discards the path the object travelled so far during the current frame.

Call it after assigning the position directly for a warp, respawn or re-sync, otherwise HasCrossedOver() hits everything on the way. MoveInstantly() does it for absolute moves.

bool Jazz2::Actors::ActorBase::TryUnstuck() protected

Tries to push the actor out of solid geometry it ended up inside of.

Returns true if the actor was moved to a free position

Probes are non-destructive, so they never destroy a tile or count as a weapon hit.

void Jazz2::Actors::ActorBase::CreateParticleDebrisOnPerish(ParticleDebrisEffect effect, Vector2f speed) protected

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

void Jazz2::Actors::ActorBase::RequestMetadata(StringView path, bool forceIndexed = false) protected

Loads specified metadata and its linked assets.

Parameters
path Relative path to the metadata asset
forceIndexed Load linked graphics as indexed for recoloring (e.g., the player)

void Jazz2::Actors::ActorBase::SetState(ActorState flag, bool value) protected constexpr noexcept

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