Jazz2::Actors::Collectibles::CollectibleBase class

Base class of a collectible object.

Base for pickups that grant the player a bonus when collected on contact. It provides the behavior shared by all collectibles: the floating/bobbing animation, optional light emission when illuminated, and dispatching the collection logic to the deriving type.

Base classes

class Jazz2::Actors::ActorBase
Base class of an object.

Derived classes

class AmmoCollectible
Ammo (collectible).
class CarrotCollectible
Carrot (collectible).
class CarrotFlyCollectible
Fly carrot (collectible).
class CarrotInvincibleCollectible
Invincible carrot (collectible).
class CoinCollectible
Coin (collectible).
class FastFireCollectible
Fast fire (collectible).
class FoodCollectible
Food (collectible).
class GemCollectible
Gem (collectible).
class GemRing
Gem ring.
class OneUpCollectible
1up (collectible)
class Stopwatch
Stopwatch.

Public types

class IlluminateLights
Swarm of lights orbiting an illuminated collectible.

Constructors, destructors, conversion operators

CollectibleBase()
Creates a new instance.

Public functions

auto OnHandleCollision(ActorBase* other) -> bool override
Called when the object collides with another object.

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 OnSerializeState(Stream& dest) override
Serializes the live state of the object to a level state snapshot.
void OnDeserializeState(Stream& src) override
Restores the live state of the object from a level state snapshot.
void OnEmitLights(SmallVectorImpl<LightEmitter>& lights) override
Called when emitting lights.
void OnEmitRemotedLights(SmallVectorImpl<LightEmitter>& lights) override
Called when emitting lights that have to be replicated to remote peers.
auto IsIlluminatedStateRemoted() const -> bool override
Whether an observer reproduces this object's ActorState::Illuminated decoration itself.
void OnCollect(Player* player) virtual
Called when the collectible is collected.
void SetFacingDirection(bool inverse = false)
Sets facing direction.

Function documentation

void Jazz2::Actors::Collectibles::CollectibleBase::OnSerializeState(Stream& dest) override protected

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

Called only if IsSerializable() returns true. Anything that is initialized from the event parameters in OnActivatedAsync() doesn't need to be stored, because the object is spawned again with the same parameters before OnDeserializeState() is called. Derived classes must call the base implementation first and read the data back in the same order.

void Jazz2::Actors::Collectibles::CollectibleBase::OnDeserializeState(Stream& src) override protected

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

Called right after the object was spawned again (i.e., after OnActivatedAsync()) and before it's added to the level. Running transitions are not restored, because their callbacks cannot be serialized, so derived classes have to put the object into a state that doesn't wait for such a callback.

void Jazz2::Actors::Collectibles::CollectibleBase::OnEmitRemotedLights(SmallVectorImpl<LightEmitter>& lights) override protected

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

An object simulated on a multiplayer server is drawn on the clients by a stand-in that runs none of its logic, so the lights it emits have to be described to them explicitly. This defaults to OnEmitLights(), which is right for anything whose lighting belongs to the object itself.

Overriding it describes only the part that every observer must see. Lights that a client already produces on its own — decoration driven by a local preference, or an object whose stand-in replays the whole effect — are left out, so they aren't sent (and applied) twice.

bool Jazz2::Actors::Collectibles::CollectibleBase::IsIlluminatedStateRemoted() const override protected

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

ActorState::Illuminated is a generic per-event flag (see Events::EventMap::ReadEvents()), so it may only be remoted for an object that actually turns it into lights — an observer would otherwise glow for an event that emits nothing on the server. An object that answers true leaves those lights out of OnEmitRemotedLights() and lets every observer seed an equivalent swarm locally, which is far cheaper than describing two dozen constantly moving lights on every update.

Declared here rather than tested for by type in the packet builder, so adding another such object is a matter of overriding this and nothing else has to know the class exists.