Make a better class for kart animation creation exception
This commit is contained in:
parent
d990bcb2a1
commit
05fad217e3
@ -689,7 +689,19 @@ void Flyable::restoreState(BareNetworkString *buffer, int count)
|
|||||||
{
|
{
|
||||||
// At the moment we only have cannon animation for rubber ball
|
// At the moment we only have cannon animation for rubber ball
|
||||||
if (!m_animation)
|
if (!m_animation)
|
||||||
setAnimation(new CannonAnimation(this, buffer));
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CannonAnimation* ca = new CannonAnimation(this, buffer);
|
||||||
|
setAnimation(ca);
|
||||||
|
}
|
||||||
|
catch (const KartAnimationCreationException& kace)
|
||||||
|
{
|
||||||
|
Log::error("Flyable", "Kart animation creation error: %s",
|
||||||
|
kace.what());
|
||||||
|
buffer->skip(kace.getSkippingOffset());
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
m_animation->restoreState(buffer);
|
m_animation->restoreState(buffer);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "utils/no_copy.hpp"
|
#include "utils/no_copy.hpp"
|
||||||
#include "utils/vec3.hpp"
|
#include "utils/vec3.hpp"
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -38,6 +39,14 @@ enum KartAnimationType : uint8_t
|
|||||||
KAT_CANNON = 2
|
KAT_CANNON = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Exception for kart animation creation in networking, so if thrown it will
|
||||||
|
* tell the num of bytes skipping in the game state. */
|
||||||
|
class KartAnimationCreationException : public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual int getSkippingOffset() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/** The base class for all kart animation, like rescue, explosion, or cannon.
|
/** The base class for all kart animation, like rescue, explosion, or cannon.
|
||||||
* Kart animations are done by removing the physics body from the physics
|
* Kart animations are done by removing the physics body from the physics
|
||||||
* world, and instead modifying the rotation and position of the kart
|
* world, and instead modifying the rotation and position of the kart
|
||||||
|
@ -380,18 +380,36 @@ void CannonAnimation::restoreState(BareNetworkString* buffer)
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void CannonAnimation::restoreData(BareNetworkString* buffer)
|
void CannonAnimation::restoreData(BareNetworkString* buffer)
|
||||||
{
|
{
|
||||||
|
// Kart cannon has 2 floats + 1 compressed quaternion
|
||||||
|
// Flyable has 1 float (delta)
|
||||||
|
const int skipping_offset = m_kart ? 12 : 4;
|
||||||
|
class CannonCreationException : public KartAnimationCreationException
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const std::string m_error;
|
||||||
|
|
||||||
|
const int m_skipping_offset;
|
||||||
|
public:
|
||||||
|
CannonCreationException(const std::string& error, int skipping_offset)
|
||||||
|
: m_error(error), m_skipping_offset(skipping_offset) {}
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
virtual int getSkippingOffset() const { return m_skipping_offset; }
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
virtual const char* what() const throw() { return m_error.c_str(); }
|
||||||
|
};
|
||||||
|
|
||||||
int cc_idx = buffer->getInt8();
|
int cc_idx = buffer->getInt8();
|
||||||
if ((unsigned)cc_idx > CheckManager::get()->getCheckStructureCount())
|
if ((unsigned)cc_idx > CheckManager::get()->getCheckStructureCount())
|
||||||
{
|
{
|
||||||
throw std::invalid_argument(
|
throw CannonCreationException(
|
||||||
"Server has different check structure size.");
|
"Server has different check structure size.", skipping_offset);
|
||||||
}
|
}
|
||||||
CheckCannon* cc = dynamic_cast<CheckCannon*>
|
CheckCannon* cc = dynamic_cast<CheckCannon*>
|
||||||
(CheckManager::get()->getCheckStructure(cc_idx));
|
(CheckManager::get()->getCheckStructure(cc_idx));
|
||||||
if (!cc)
|
if (!cc)
|
||||||
{
|
{
|
||||||
throw std::invalid_argument(
|
throw CannonCreationException(
|
||||||
"Server has different check cannon index.");
|
"Server has different check cannon index.", skipping_offset);
|
||||||
}
|
}
|
||||||
float skid_rot = 0.0f;
|
float skid_rot = 0.0f;
|
||||||
float fraction_of_line = 0.0f;
|
float fraction_of_line = 0.0f;
|
||||||
|
@ -30,7 +30,6 @@ class CheckCannon;
|
|||||||
class Flyable;
|
class Flyable;
|
||||||
class Ipo;
|
class Ipo;
|
||||||
|
|
||||||
|
|
||||||
/** This animation shoots the kart to a specified point on the track.
|
/** This animation shoots the kart to a specified point on the track.
|
||||||
*
|
*
|
||||||
* \ingroup karts
|
* \ingroup karts
|
||||||
|
@ -330,17 +330,27 @@ void KartRewinder::restoreState(BareNetworkString *buffer, int count)
|
|||||||
{
|
{
|
||||||
delete m_kart_animation;
|
delete m_kart_animation;
|
||||||
m_kart_animation = NULL;
|
m_kart_animation = NULL;
|
||||||
switch (kat)
|
try
|
||||||
{
|
{
|
||||||
case KAT_RESCUE:
|
switch (kat)
|
||||||
new RescueAnimation(this, buffer);
|
{
|
||||||
break;
|
case KAT_RESCUE:
|
||||||
case KAT_EXPLOSION:
|
new RescueAnimation(this, buffer);
|
||||||
new ExplosionAnimation(this, buffer);
|
break;
|
||||||
break;
|
case KAT_EXPLOSION:
|
||||||
case KAT_CANNON:
|
new ExplosionAnimation(this, buffer);
|
||||||
new CannonAnimation(this, buffer);
|
break;
|
||||||
break;
|
case KAT_CANNON:
|
||||||
|
new CannonAnimation(this, buffer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const KartAnimationCreationException& kace)
|
||||||
|
{
|
||||||
|
Log::error("KartRewinder", "Kart animation creation error: %s",
|
||||||
|
kace.what());
|
||||||
|
buffer->skip(kace.getSkippingOffset());
|
||||||
|
m_kart_animation = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user