Optimize plunger state saving
This commit is contained in:
parent
f1c164ca6e
commit
45a1190374
@ -262,8 +262,6 @@ public:
|
|||||||
/** Returns true if the kart has a plunger attached to its face. */
|
/** Returns true if the kart has a plunger attached to its face. */
|
||||||
virtual int getBlockedByPlungerTicks() const = 0;
|
virtual int getBlockedByPlungerTicks() const = 0;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual float getGraphicalViewBlockedByPlunger() const = 0;
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
/** Sets that the view is blocked by a plunger. The duration depends on
|
/** Sets that the view is blocked by a plunger. The duration depends on
|
||||||
* the difficulty, see KartPorperties getPlungerInFaceTime. */
|
* the difficulty, see KartPorperties getPlungerInFaceTime. */
|
||||||
virtual void blockViewWithPlunger() = 0;
|
virtual void blockViewWithPlunger() = 0;
|
||||||
|
@ -185,7 +185,6 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
|
|||||||
m_terrain_sound = NULL;
|
m_terrain_sound = NULL;
|
||||||
m_last_sound_material = NULL;
|
m_last_sound_material = NULL;
|
||||||
m_previous_terrain_sound = NULL;
|
m_previous_terrain_sound = NULL;
|
||||||
m_graphical_view_blocked_by_plunger = 0.0f;
|
|
||||||
} // Kart
|
} // Kart
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -369,7 +368,6 @@ void Kart::reset()
|
|||||||
m_current_lean = 0.0f;
|
m_current_lean = 0.0f;
|
||||||
m_falling_time = 0.0f;
|
m_falling_time = 0.0f;
|
||||||
m_view_blocked_by_plunger = 0;
|
m_view_blocked_by_plunger = 0;
|
||||||
m_graphical_view_blocked_by_plunger = 0.0f;
|
|
||||||
m_has_caught_nolok_bubblegum = false;
|
m_has_caught_nolok_bubblegum = false;
|
||||||
m_is_jumping = false;
|
m_is_jumping = false;
|
||||||
m_flying = false;
|
m_flying = false;
|
||||||
@ -591,13 +589,8 @@ void Kart::blockViewWithPlunger()
|
|||||||
// Avoid that a plunger extends the plunger time
|
// Avoid that a plunger extends the plunger time
|
||||||
if(m_view_blocked_by_plunger<=0 && !isShielded())
|
if(m_view_blocked_by_plunger<=0 && !isShielded())
|
||||||
{
|
{
|
||||||
m_view_blocked_by_plunger =
|
m_view_blocked_by_plunger = (int16_t)
|
||||||
stk_config->time2Ticks(m_kart_properties->getPlungerInFaceTime());
|
stk_config->time2Ticks(m_kart_properties->getPlungerInFaceTime());
|
||||||
if (m_graphical_view_blocked_by_plunger == 0.0f)
|
|
||||||
{
|
|
||||||
m_graphical_view_blocked_by_plunger =
|
|
||||||
m_kart_properties->getPlungerInFaceTime();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(isShielded())
|
if(isShielded())
|
||||||
{
|
{
|
||||||
@ -1454,7 +1447,6 @@ void Kart::update(int ticks)
|
|||||||
if(isShielded())
|
if(isShielded())
|
||||||
{
|
{
|
||||||
m_view_blocked_by_plunger = 0;
|
m_view_blocked_by_plunger = 0;
|
||||||
m_graphical_view_blocked_by_plunger = 0.0f;
|
|
||||||
}
|
}
|
||||||
// Decrease remaining invulnerability time
|
// Decrease remaining invulnerability time
|
||||||
if(m_invulnerable_ticks>0)
|
if(m_invulnerable_ticks>0)
|
||||||
@ -1698,7 +1690,6 @@ void Kart::update(int ticks)
|
|||||||
if (emergency)
|
if (emergency)
|
||||||
{
|
{
|
||||||
m_view_blocked_by_plunger = 0;
|
m_view_blocked_by_plunger = 0;
|
||||||
m_graphical_view_blocked_by_plunger = 0.0f;
|
|
||||||
if (m_flying)
|
if (m_flying)
|
||||||
{
|
{
|
||||||
stopFlying();
|
stopFlying();
|
||||||
@ -3143,12 +3134,6 @@ void Kart::updateGraphics(float dt)
|
|||||||
else if (!isSquashed() &&
|
else if (!isSquashed() &&
|
||||||
m_node->getScale() != core::vector3df(1.0f, 1.0f, 1.0f))
|
m_node->getScale() != core::vector3df(1.0f, 1.0f, 1.0f))
|
||||||
unsetSquash();
|
unsetSquash();
|
||||||
|
|
||||||
if (m_graphical_view_blocked_by_plunger > 0.0f)
|
|
||||||
m_graphical_view_blocked_by_plunger -= dt;
|
|
||||||
if (m_graphical_view_blocked_by_plunger < 0.0f ||
|
|
||||||
m_view_blocked_by_plunger == 0)
|
|
||||||
m_graphical_view_blocked_by_plunger = 0.0f;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < EMITTER_COUNT; i++)
|
for (int i = 0; i < EMITTER_COUNT; i++)
|
||||||
|
@ -220,8 +220,6 @@ protected:
|
|||||||
* > 0 the number it contains is the time left before removing plunger. */
|
* > 0 the number it contains is the time left before removing plunger. */
|
||||||
int16_t m_view_blocked_by_plunger;
|
int16_t m_view_blocked_by_plunger;
|
||||||
|
|
||||||
float m_graphical_view_blocked_by_plunger;
|
|
||||||
|
|
||||||
/** The current speed (i.e. length of velocity vector) of this kart. */
|
/** The current speed (i.e. length of velocity vector) of this kart. */
|
||||||
float m_speed;
|
float m_speed;
|
||||||
|
|
||||||
@ -395,9 +393,6 @@ public:
|
|||||||
virtual int getBlockedByPlungerTicks() const OVERRIDE
|
virtual int getBlockedByPlungerTicks() const OVERRIDE
|
||||||
{ return m_view_blocked_by_plunger; }
|
{ return m_view_blocked_by_plunger; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual float getGraphicalViewBlockedByPlunger() const OVERRIDE
|
|
||||||
{ return m_graphical_view_blocked_by_plunger; }
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
/** Sets that the view is blocked by a plunger. The duration depends on
|
/** Sets that the view is blocked by a plunger. The duration depends on
|
||||||
* the difficulty, see KartPorperties getPlungerInFaceTime. */
|
* the difficulty, see KartPorperties getPlungerInFaceTime. */
|
||||||
virtual void blockViewWithPlunger() OVERRIDE;
|
virtual void blockViewWithPlunger() OVERRIDE;
|
||||||
@ -475,10 +470,10 @@ public:
|
|||||||
/** Makes a kart invulnerable for a certain amount of time. */
|
/** Makes a kart invulnerable for a certain amount of time. */
|
||||||
virtual void setInvulnerableTicks(int ticks) OVERRIDE
|
virtual void setInvulnerableTicks(int ticks) OVERRIDE
|
||||||
{
|
{
|
||||||
// The rest 2 bits are saving fire clicked and animation status for
|
// The last 3 bits are saving fire clicked, kart animation status and
|
||||||
// rewind
|
// plunger state for rewind
|
||||||
if (ticks > 16383)
|
if (ticks > 8191)
|
||||||
ticks = 16383;
|
ticks = 8191;
|
||||||
m_invulnerable_ticks = ticks;
|
m_invulnerable_ticks = ticks;
|
||||||
} // setInvulnerableTicks
|
} // setInvulnerableTicks
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@ -122,13 +122,16 @@ BareNetworkString* KartRewinder::saveState(std::vector<std::string>* ru)
|
|||||||
// 1) Firing and related handling
|
// 1) Firing and related handling
|
||||||
// -----------
|
// -----------
|
||||||
buffer->addUInt16(m_bubblegum_ticks);
|
buffer->addUInt16(m_bubblegum_ticks);
|
||||||
buffer->addUInt16(m_view_blocked_by_plunger);
|
bool plunger_on = m_view_blocked_by_plunger != 0;
|
||||||
// m_invulnerable_ticks will not be negative
|
// m_invulnerable_ticks will not be negative
|
||||||
AbstractKartAnimation* ka = getKartAnimation();
|
AbstractKartAnimation* ka = getKartAnimation();
|
||||||
bool has_animation = ka != NULL && ka->usePredefinedEndTransform();
|
bool has_animation = ka != NULL && ka->usePredefinedEndTransform();
|
||||||
uint16_t fire_and_invulnerable = (m_fire_clicked ? 1 << 15 : 0) |
|
uint16_t fire_and_invulnerable = (m_fire_clicked ? 1 << 15 : 0) |
|
||||||
(has_animation ? 1 << 14 : 0) | m_invulnerable_ticks;
|
(has_animation ? 1 << 14 : 0) | (plunger_on ? 1 << 13 : 0) |
|
||||||
|
m_invulnerable_ticks;
|
||||||
buffer->addUInt16(fire_and_invulnerable);
|
buffer->addUInt16(fire_and_invulnerable);
|
||||||
|
if (plunger_on)
|
||||||
|
buffer->addUInt16(m_view_blocked_by_plunger);
|
||||||
|
|
||||||
// 2) Kart animation status (tells the end transformation) or
|
// 2) Kart animation status (tells the end transformation) or
|
||||||
// physics values (transform and velocities)
|
// physics values (transform and velocities)
|
||||||
@ -196,11 +199,16 @@ void KartRewinder::restoreState(BareNetworkString *buffer, int count)
|
|||||||
// 1) Firing and related handling
|
// 1) Firing and related handling
|
||||||
// -----------
|
// -----------
|
||||||
m_bubblegum_ticks = buffer->getUInt16();
|
m_bubblegum_ticks = buffer->getUInt16();
|
||||||
m_view_blocked_by_plunger = buffer->getUInt16();
|
|
||||||
uint16_t fire_and_invulnerable = buffer->getUInt16();
|
uint16_t fire_and_invulnerable = buffer->getUInt16();
|
||||||
m_fire_clicked = ((fire_and_invulnerable >> 15) & 1) == 1;
|
m_fire_clicked = ((fire_and_invulnerable >> 15) & 1) == 1;
|
||||||
bool has_animation = ((fire_and_invulnerable >> 14) & 1) == 1;
|
bool has_animation = ((fire_and_invulnerable >> 14) & 1) == 1;
|
||||||
m_invulnerable_ticks = fire_and_invulnerable & ~(1 << 14);
|
bool has_plunger = ((fire_and_invulnerable >> 13) & 1) == 1;
|
||||||
|
if (has_plunger)
|
||||||
|
m_view_blocked_by_plunger = buffer->getUInt16();
|
||||||
|
else
|
||||||
|
m_view_blocked_by_plunger = 0;
|
||||||
|
|
||||||
|
m_invulnerable_ticks = fire_and_invulnerable & ~(1 << 13);
|
||||||
|
|
||||||
// 2) Kart animation status or transform and velocities
|
// 2) Kart animation status or transform and velocities
|
||||||
// -----------
|
// -----------
|
||||||
|
Loading…
Reference in New Issue
Block a user