SuperTuxKart
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
Flyable Class Reference
Inheritance diagram for Flyable:
Inheritance graph
[legend]

Public Member Functions

 Flyable (AbstractKart *kart, PowerupManager::PowerupType type, float mass=1.0f)
 
void updateGraphics (float dt) OVERRIDE
 Called once per rendered frame. More...
 
virtual bool updateAndDelete (int ticks)
 Updates this flyable. More...
 
virtual void setAnimation (AbstractKartAnimation *animation)
 
virtual HitEffectgetHitEffect () const
 Returns the hit effect object to use when this objects hits something. More...
 
bool isOwnerImmunity (const AbstractKart *kart_hit) const
 Returns true if the item hit the kart who shot it (to avoid that an item that's too close to the shooter hits the shooter). More...
 
virtual bool hit (AbstractKart *kart, PhysicalObject *obj=NULL)
 Callback from the physics in case that a kart or physical object is hit. More...
 
void explode (AbstractKart *kart, PhysicalObject *obj=NULL, bool secondary_hits=true)
 Creates the explosion physical effect, i.e. More...
 
unsigned int getOwnerId ()
 
bool hasAnimation () const
 Returns if this flyable has an animation playing (e.g. More...
 
void setAdjustUpVelocity (bool f)
 If true the up velocity of the flyable will be adjust so that the flyable stays at a height close to the average height. More...
 
void setPositionOffset (const Vec3 &o)
 Sets the offset to be used when determining the terrain under the flyable. More...
 
virtual void hitTrack ()
 Called when this flyable hits the track. More...
 
bool hasHit ()
 Enables/disables adjusting ov velocity depending on height above terrain. More...
 
void setHasHit ()
 Indicates that something was hit and that this object must be removed. More...
 
void reset () OVERRIDE
 Resets this flyable. More...
 
PowerupManager::PowerupType getType () const
 Returns the type of flyable. More...
 
AbstractKartgetOwner () const
 Returns the owner's kart.
 
void setDoTerrainInfo (bool d)
 Sets wether Flyable should update TerrainInfo as part of its update call, or if the inheriting object will update TerrainInfo itself (or perhaps not at all if it is not needed). More...
 
const Vec3getExtend () const
 Returns the size (extend) of the mesh. More...
 
void addForRewind (const std::string &uid)
 
virtual void undoEvent (BareNetworkString *buffer) OVERRIDE
 Called when an event needs to be undone. More...
 
virtual void rewindToEvent (BareNetworkString *buffer) OVERRIDE
 Called when an event needs to be replayed. More...
 
virtual void undoState (BareNetworkString *buffer) OVERRIDE
 Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo). More...
 
virtual void saveTransform () OVERRIDE
 Called before a rewind. More...
 
virtual void computeError () OVERRIDE
 Called when a rewind is finished, and is used to compute the error caused by the rewind (which is then visually smoothed over time). More...
 
virtual BareNetworkStringsaveState (std::vector< std::string > *ru) OVERRIDE
 Provides a copy of the state of the object in one memory buffer. More...
 
virtual void restoreState (BareNetworkString *buffer, int count) OVERRIDE
 Called when a state needs to be replayed. More...
 
bool hasServerState () const
 
virtual void onFireFlyable ()
 Call when the item is (re-)fired (during rewind if needed) by projectile_manager. More...
 
virtual void onDeleteFlyable ()
 
void setCreatedTicks (int ticks)
 
- Public Member Functions inherited from Moveable
scene::ISceneNode * getNode () const
 Returns the scene node of this moveable. More...
 
void setNode (scene::ISceneNode *n)
 Sets the mesh for this model. More...
 
virtual const btVector3 & getVelocity () const
 
const btVector3 & getVelocityLC () const
 
virtual void setVelocity (const btVector3 &v)
 
const Vec3getXYZ () const
 
float getHeading () const
 Returns the heading between -pi and pi. More...
 
float getPitch () const
 Returns the pitch of the kart, restricted to between -pi/2 and pi/2. More...
 
float getRoll () const
 Returns the roll of the kart between -pi and pi. More...
 
const btQuaternion getRotation () const
 
virtual void flyUp ()
 Enter flying mode.
 
virtual void flyDown ()
 
virtual void stopFlying ()
 
virtual void setXYZ (const Vec3 &a)
 Sets the XYZ coordinates of the moveable. More...
 
void setRotation (const btMatrix3x3 &m)
 Sets the rotation of the physical body this moveable. More...
 
void setRotation (const btQuaternion &q)
 Sets the rotation of the physical body this moveable. More...
 
virtual void update (int ticks)
 Updates the current position and rotation from the corresponding physics body, and then calls updateGraphics to position the model correctly. More...
 
btRigidBody * getBody () const
 
void createBody (float mass, btTransform &trans, btCollisionShape *shape, float restitution)
 Creates the bullet rigid body for this moveable. More...
 
const btTransform & getTrans () const
 
void setTrans (const btTransform &t)
 Places this moveable at a certain location and stores this transform in this Moveable, so that it can be accessed easily. More...
 
void updatePosition ()
 Updates the current position and rotation. More...
 
void prepareSmoothing ()
 
void checkSmoothing ()
 
const btTransform & getSmoothedTrans () const
 
const Vec3getSmoothedXYZ () const
 
virtual const std::string & getIdent () const
 
- Public Member Functions inherited from SmoothNetworkBody
 SmoothNetworkBody (bool enable=false)
 
void reset ()
 
void setEnable (bool val)
 
bool isEnabled () const
 
void setSmoothRotation (bool val)
 
void setAdjustVerticalOffset (bool val)
 
void prepareSmoothing (const btTransform &current_transform, const Vec3 &current_velocity)
 
void checkSmoothing (const btTransform &current_transform, const Vec3 &current_velocity)
 Adds a new error between graphical and physical position/rotation. More...
 
void updateSmoothedGraphics (const btTransform &current_transform, const Vec3 &current_velocity, float dt)
 
void setSmoothedTransform (const btTransform &t)
 
const btTransform & getSmoothedTrans () const
 
const Vec3getSmoothedXYZ () const
 
void setMinAdjustLength (float val)
 
void setMaxAdjustLength (float val)
 
void setMinAdjustSpeed (float val)
 
void setMaxAdjustTime (float val)
 
void setAdjustLengthThreshold (float val)
 
- Public Member Functions inherited from TerrainInfo
 TerrainInfo ()
 Constructor to initialise terrain data.
 
 TerrainInfo (const Vec3 &pos)
 Constructor to initialise terrain data at a given position. More...
 
bool getSurfaceInfo (const Vec3 &from, Vec3 *position, const Material **m)
 Does a raycast upwards from the given position If the raycast indicated that the kart is 'under something' (i.e. More...
 
virtual void update (const btMatrix3x3 &rotation, const Vec3 &from)
 Update the terrain information based on the latest position. More...
 
virtual void update (const Vec3 &from)
 Update the terrain information based on the latest position. More...
 
virtual void update (const Vec3 &from, const Vec3 &towards)
 Update the terrain information based on the latest position. More...
 
virtual void update (const btMatrix3x3 &rotation)
 Simple wrapper with no offset. More...
 
float getHoT () const
 Returns the height of the terrain. More...
 
const MaterialgetMaterial () const
 Returns the current material the kart is on. More...
 
const MaterialgetLastMaterial () const
 Returns the previous material the kart was one (which might be the same as getMaterial() ). More...
 
const Vec3getNormal () const
 Returns the normal of the terrain the kart is on. More...
 
float getTerrainPitch (float heading) const
 Returns the pitch of the terrain depending on the heading. More...
 
const btVector3 & getHitPoint () const
 Returns the hit point of the raycast. More...
 
const Vec3getOrigin () const
 
- Public Member Functions inherited from Rewinder
 Rewinder (const std::string &ui="")
 
virtual std::function< void()> getLocalStateRestoreFunction ()
 
const std::string & getUniqueIdentity () const
 
bool rewinderAdd ()
 Add this object to the list of all rewindable objects in the rewind manager.
 
template<typename T >
std::shared_ptr< T > getShared ()
 

Static Public Member Functions

static void init (const XMLNode &node, scene::IMesh *model, PowerupManager::PowerupType type)
 Initialises the static members of this class for a certain type with default values and with settings from powerup.xml. More...
 

Protected Member Functions

void getClosestKart (const AbstractKart **minKart, float *minDistSquared, Vec3 *minDelta, const AbstractKart *inFrontOf=NULL, const bool backwards=false) const
 Returns information on what is the closest kart and at what distance it is. More...
 
void getLinearKartItemIntersection (const Vec3 &origin, const AbstractKart *target_kart, float item_XY_velocity, float gravity, float forw_offset, float *fire_angle, float *up_velocity)
 Returns information on the parameters needed to hit a target kart moving at constant velocity and direction for a given speed in the XZ-plane. More...
 
void createPhysics (float y_offset, const Vec3 &velocity, btCollisionShape *shape, float restitution, const btVector3 &gravity=btVector3(0.0f, 0.0f, 0.0f), const bool rotates=false, const bool turn_around=false, const btTransform *customDirection=NULL)
 init bullet for moving objects like projectiles More...
 
void moveToInfinity (bool set_moveable_trans=true)
 It's called when undoing the creation or destruction of flyables, so that it will not affected the current game, and it will be deleted in computeError. More...
 
void removePhysics ()
 
- Protected Member Functions inherited from Moveable
void updateSmoothedGraphics (float dt)
 
virtual void updateGraphics (const Vec3 &off_xyz=Vec3(0.0f, 0.0f, 0.0f), const btQuaternion &off_rotation=btQuaternion(0.0f, 0.0f, 0.0f, 1.0f))
 Updates the graphics model. More...
 
- Protected Member Functions inherited from Rewinder
void setUniqueIdentity (const std::string &uid)
 

Protected Attributes

AbstractKartm_owner
 Kart which shot this flyable. More...
 
PowerupManager::PowerupType m_type
 Type of the powerup. More...
 
btCollisionShape * m_shape
 Collision shape of this Flyable. More...
 
float m_max_height
 Maximum height above terrain. More...
 
float m_min_height
 Minimum height above terrain. More...
 
float m_average_height
 Average of average of m_{min,ax}_height. More...
 
float m_force_updown
 Force pushing the Flyable up. More...
 
float m_speed
 Speed of this Flyable. More...
 
const float m_mass
 Mass of this Flyable. More...
 
Vec3 m_extend
 Size of this flyable. More...
 
uint16_t m_ticks_since_thrown
 Time since thrown. More...
 
bool m_has_server_state
 
bool m_owner_has_temporary_immunity
 If set to true, the kart that throwns this flyable can't collide with it for a short time. More...
 
bool m_deleted_once
 
int m_last_deleted_ticks
 
int m_max_lifespan
 Set to something > -1 if this flyable should auto-destrcut after that may ticks. More...
 
int m_created_ticks
 
- Protected Attributes inherited from Moveable
btTransform m_transform
 The bullet transform of this rigid body. More...
 
UserPointer m_user_pointer
 
scene::ISceneNode * m_node
 
std::unique_ptr< btRigidBody > m_body
 
std::unique_ptr< KartMotionStatem_motion_state
 

Static Protected Attributes

static float m_st_speed [PowerupManager::POWERUP_MAX]
 Speed of the projectile. More...
 
static scene::IMesh * m_st_model [PowerupManager::POWERUP_MAX]
 The mesh of this Flyable. More...
 
static float m_st_min_height [PowerupManager::POWERUP_MAX]
 Minimum height above track. More...
 
static float m_st_max_height [PowerupManager::POWERUP_MAX]
 Max height above track. More...
 
static float m_st_force_updown [PowerupManager::POWERUP_MAX]
 Force pushing up/down. More...
 
static Vec3 m_st_extend [PowerupManager::POWERUP_MAX]
 Size of the model. More...
 

Private Attributes

bool m_has_hit_something
 
bool m_adjust_up_velocity
 If this flag is set, the up velocity of the kart will not be adjusted in case that the objects is too high or too low above the terrain. More...
 
Vec3 m_position_offset
 An offset that is added when doing the raycast for terrain. More...
 
bool m_do_terrain_info
 If this variable is set to true (which is the default) flyable will update the height of terrain when its updateAndDelete function is called. More...
 
uint32_t m_compressed_gravity_vector
 
AbstractKartAnimationm_animation
 If the flyable is in a cannon, this is the pointer to the cannon animation. More...
 

Member Function Documentation

◆ computeError()

void Flyable::computeError ( )
virtual

Called when a rewind is finished, and is used to compute the error caused by the rewind (which is then visually smoothed over time).

Implements Rewinder.

◆ createPhysics()

void Flyable::createPhysics ( float  forw_offset,
const Vec3 velocity,
btCollisionShape *  shape,
float  restitution,
const btVector3 &  gravity = btVector3(0.0f,0.0f,0.0f),
const bool  rotates = false,
const bool  turn_around = false,
const btTransform *  custom_direction = NULL 
)
protected

init bullet for moving objects like projectiles

Creates a bullet physics body for the flyable item.

Parameters
forw_offsetHow far ahead of the kart the flyable should be positioned. Necessary to avoid exploding a rocket inside of the firing kart.
velocityInitial velocity of the flyable.
shapeCollision shape of the flyable.
gravityGravity to use for this flyable.
rotatesTrue if the item should rotate, otherwise the angular factor is set to 0 preventing rotations from happening.
turn_aroundTrue if the item is fired backwards.
custom_directionIf defined the initial heading for this item, otherwise the kart's heading will be used.

◆ explode()

void Flyable::explode ( AbstractKart kart_hit,
PhysicalObject object = NULL,
bool  secondary_hits = true 
)

Creates the explosion physical effect, i.e.

pushes the karts and ph appropriately. The corresponding visual/sfx needs to be added manually!

Parameters
kart_hitIf non-NULL a kart that was directly hit.
objectIf non-NULL a physical item that was hit directly.
secondary_hitsTrue if items that are not directly hit should also be affected.

◆ getClosestKart()

void Flyable::getClosestKart ( const AbstractKart **  minKart,
float *  minDistSquared,
Vec3 minDelta,
const AbstractKart inFrontOf = NULL,
const bool  backwards = false 
) const
protected

Returns information on what is the closest kart and at what distance it is.

All 3 parameters first are of type 'out'. 'inFrontOf' can be set if you wish to know the closest kart in front of some karts (will ignore those behind). Useful e.g. for throwing projectiles in front only.

◆ getExtend()

const Vec3& Flyable::getExtend ( ) const
inline

Returns the size (extend) of the mesh.

◆ getHitEffect()

HitEffect * Flyable::getHitEffect ( ) const
virtual

Returns the hit effect object to use when this objects hits something.

Returns
The hit effect object, or NULL if no hit effect should be played.

Reimplemented in Plunger, and Bowling.

◆ getLinearKartItemIntersection()

void Flyable::getLinearKartItemIntersection ( const Vec3 origin,
const AbstractKart target_kart,
float  item_XZ_speed,
float  gravity,
float  forw_offset,
float *  fire_angle,
float *  up_velocity 
)
protected

Returns information on the parameters needed to hit a target kart moving at constant velocity and direction for a given speed in the XZ-plane.

Parameters
originLocation of the kart shooting the item.
target_kartWhich kart to target.
item_xz_speedSpeed of the item projected in XZ plane.
gravityThe gravity used for this item.
forw_offsetHow far ahead of the kart the item is shot (so that the item does not originate inside of the shooting kart.
fire_angleReturns the angle to fire the item at.
up_velocityReturns the upwards velocity to use for the item.

◆ getType()

PowerupManager::PowerupType Flyable::getType ( ) const
inline

Returns the type of flyable.

◆ hasAnimation()

bool Flyable::hasAnimation ( ) const
inline

Returns if this flyable has an animation playing (e.g.

cannon).

◆ hasHit()

bool Flyable::hasHit ( )
inline

Enables/disables adjusting ov velocity depending on height above terrain.

Missiles can 'follow the terrain' with this adjustment, but gravity will basically be disabled.

◆ hit()

bool Flyable::hit ( AbstractKart kart_hit,
PhysicalObject object = NULL 
)
virtual

Callback from the physics in case that a kart or physical object is hit.

Parameters
kartThe kart hit (NULL if no kart was hit).
objectThe object that was hit (NULL if none).
Returns
True if there was actually a hit (i.e. not owner, and target is not immune), false otherwise.

Reimplemented in RubberBall, Bowling, Plunger, and Cake.

◆ hitTrack()

virtual void Flyable::hitTrack ( )
inlinevirtual

Called when this flyable hits the track.

Reimplemented in Plunger, and Cake.

◆ init()

void Flyable::init ( const XMLNode node,
scene::IMesh *  model,
PowerupManager::PowerupType  type 
)
static

Initialises the static members of this class for a certain type with default values and with settings from powerup.xml.

Parameters
Thexml node containing settings.
modelThe mesh to use.
typeThe type of flyable.

◆ isOwnerImmunity()

bool Flyable::isOwnerImmunity ( const AbstractKart kart_hit) const

Returns true if the item hit the kart who shot it (to avoid that an item that's too close to the shooter hits the shooter).

Parameters
kartKart who was hit.

◆ moveToInfinity()

void Flyable::moveToInfinity ( bool  set_moveable_trans = true)
protected

It's called when undoing the creation or destruction of flyables, so that it will not affected the current game, and it will be deleted in computeError.

Parameters
set_moveable_transIf true, set m_transform in moveable, so the graphical node will have the same transform, otherwise only the physical body will be moved to infinity

◆ onFireFlyable()

void Flyable::onFireFlyable ( )
virtual

Call when the item is (re-)fired (during rewind if needed) by projectile_manager.

Reimplemented in RubberBall, Cake, Plunger, and Bowling.

◆ reset()

void Flyable::reset ( )
inlinevirtual

Resets this flyable.

Reimplemented from Moveable.

◆ restoreState()

void Flyable::restoreState ( BareNetworkString buffer,
int  count 
)
virtual

Called when a state needs to be replayed.

This is called during rewind, i.e. when going forward in time again, and only for confirmed states.

Implements Rewinder.

Reimplemented in RubberBall, and Plunger.

◆ rewindToEvent()

virtual void Flyable::rewindToEvent ( BareNetworkString buffer)
inlinevirtual

Called when an event needs to be replayed.

This is called during rewind, i.e. when going forward in time again.

Implements Rewinder.

◆ saveState()

BareNetworkString * Flyable::saveState ( std::vector< std::string > *  ru)
virtual

Provides a copy of the state of the object in one memory buffer.

The memory is managed by the RewindManager.

Parameters
[out]ruThe unique identity of rewinder writing to.
Returns
The address of the memory buffer with the state.

Implements Rewinder.

Reimplemented in RubberBall, and Plunger.

◆ saveTransform()

void Flyable::saveTransform ( )
virtual

Called before a rewind.

Is used to save the previous position of an object before a rewind, so that the error due to a rewind can be computed.

Implements Rewinder.

◆ setAdjustUpVelocity()

void Flyable::setAdjustUpVelocity ( bool  f)
inline

If true the up velocity of the flyable will be adjust so that the flyable stays at a height close to the average height.

Parameters
fTrue if the up velocity should be adjusted.

◆ setDoTerrainInfo()

void Flyable::setDoTerrainInfo ( bool  d)
inline

Sets wether Flyable should update TerrainInfo as part of its update call, or if the inheriting object will update TerrainInfo itself (or perhaps not at all if it is not needed).

◆ setHasHit()

void Flyable::setHasHit ( )
inline

Indicates that something was hit and that this object must be removed.

◆ setPositionOffset()

void Flyable::setPositionOffset ( const Vec3 o)
inline

Sets the offset to be used when determining the terrain under the flyable.

This needs to be used in case that an object might be just under the actual terrain (e.g. rubber ball on a steep uphill slope).

◆ undoEvent()

virtual void Flyable::undoEvent ( BareNetworkString buffer)
inlinevirtual

Called when an event needs to be undone.

This is called while going backwards for rewinding - all stored events will get an 'undo' call.

Implements Rewinder.

◆ undoState()

virtual void Flyable::undoState ( BareNetworkString buffer)
inlinevirtual

Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo).

This is called while going backwards for rewinding - all stored events will get an 'undo' call.

Implements Rewinder.

◆ updateAndDelete()

bool Flyable::updateAndDelete ( int  ticks)
virtual

Updates this flyable.

It calls Moveable::update. If this function returns true, the flyable will be deleted by the projectile manager.

Parameters
dtTime step size.
Returns
True if this object can be deleted.

Reimplemented in RubberBall, Bowling, and Plunger.

◆ updateGraphics()

void Flyable::updateGraphics ( float  dt)
virtual

Called once per rendered frame.

It is used to only update any graphical effects.

Parameters
dtTime step size (since last call).

Implements Moveable.

Reimplemented in Plunger.

Member Data Documentation

◆ m_adjust_up_velocity

bool Flyable::m_adjust_up_velocity
private

If this flag is set, the up velocity of the kart will not be adjusted in case that the objects is too high or too low above the terrain.

Otherwise gravity will not work correctly on this object.

◆ m_animation

AbstractKartAnimation* Flyable::m_animation
private

If the flyable is in a cannon, this is the pointer to the cannon animation.

NULL otherwise.

◆ m_average_height

float Flyable::m_average_height
protected

Average of average of m_{min,ax}_height.

◆ m_do_terrain_info

bool Flyable::m_do_terrain_info
private

If this variable is set to true (which is the default) flyable will update the height of terrain when its updateAndDelete function is called.

If it's necessary to update the height of terrain yourself (e.g. order of operations is important) set this to false with a call do setDoTerrainInfo().

◆ m_extend

Vec3 Flyable::m_extend
protected

Size of this flyable.

◆ m_force_updown

float Flyable::m_force_updown
protected

Force pushing the Flyable up.

◆ m_mass

const float Flyable::m_mass
protected

Mass of this Flyable.

◆ m_max_height

float Flyable::m_max_height
protected

Maximum height above terrain.

◆ m_max_lifespan

int Flyable::m_max_lifespan
protected

Set to something > -1 if this flyable should auto-destrcut after that may ticks.

◆ m_min_height

float Flyable::m_min_height
protected

Minimum height above terrain.

◆ m_owner

AbstractKart* Flyable::m_owner
protected

Kart which shot this flyable.

◆ m_owner_has_temporary_immunity

bool Flyable::m_owner_has_temporary_immunity
protected

If set to true, the kart that throwns this flyable can't collide with it for a short time.

◆ m_position_offset

Vec3 Flyable::m_position_offset
private

An offset that is added when doing the raycast for terrain.

This is useful in case that the position of the object is just under the terrain (perhaps due to floating point errors), and would otherwise result in an invalid terrain.

◆ m_shape

btCollisionShape* Flyable::m_shape
protected

Collision shape of this Flyable.

◆ m_speed

float Flyable::m_speed
protected

Speed of this Flyable.

◆ m_st_extend

Vec3 Flyable::m_st_extend
staticprotected

Size of the model.

◆ m_st_force_updown

float Flyable::m_st_force_updown
staticprotected

Force pushing up/down.

◆ m_st_max_height

float Flyable::m_st_max_height
staticprotected

Max height above track.

◆ m_st_min_height

float Flyable::m_st_min_height
staticprotected

Minimum height above track.

◆ m_st_model

scene::IMesh * Flyable::m_st_model
staticprotected

The mesh of this Flyable.

◆ m_st_speed

float Flyable::m_st_speed
staticprotected

Speed of the projectile.

◆ m_ticks_since_thrown

uint16_t Flyable::m_ticks_since_thrown
protected

Time since thrown.

used so a kart can't hit himself when trying something, and also to put some time limit to some collectibles

◆ m_type

PowerupManager::PowerupType Flyable::m_type
protected

Type of the powerup.


The documentation for this class was generated from the following files: