SuperTuxKart
abstract_kart_animation.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2012-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_ABSTRACT_KART_ANIMATION_HPP
20 #define HEADER_ABSTRACT_KART_ANIMATION_HPP
21 
22 #include "LinearMath/btTransform.h"
23 
24 #include "config/stk_config.hpp"
25 #include "utils/no_copy.hpp"
26 #include "utils/vec3.hpp"
27 
28 #include <exception>
29 #include <limits>
30 #include <string>
31 
32 class AbstractKart;
33 class BareNetworkString;
34 
35 enum KartAnimationType : uint8_t
36 {
37  KAT_RESCUE = 0,
38  KAT_EXPLOSION = 1,
39  KAT_CANNON = 2
40 };
41 
44 class KartAnimationCreationException : public std::exception
45 {
46 public:
47  virtual int getSkippingOffset() const = 0;
48 };
49 
60 {
61 private:
63  std::string m_name;
64 
65 protected:
68 
71 
74 
77  btTransform m_created_transform;
78 
79  /* Compressed values for server to send to avoid compressing everytime. */
80  int m_created_transform_compressed[4];
81 
82  void resetPowerUp();
83  // ------------------------------------------------------------------------
85  // ------------------------------------------------------------------------
86  float getMaximumHeight(const Vec3& up_vector, float height_remove);
87 
88 public:
90  const std::string &name);
91  virtual ~AbstractKartAnimation();
92  virtual void update(int ticks);
93  // ------------------------------------------------------------------------
94  virtual void updateGraphics(float dt);
95  // ------------------------------------------------------------------------
96  virtual float getAnimationTimer() const;
97  // ------------------------------------------------------------------------
100  virtual const std::string &getName() const { return m_name; }
101  // ------------------------------------------------------------------------
102  virtual KartAnimationType getAnimationType() const = 0;
103  // ------------------------------------------------------------------------
104  /* Used to ignore adding karts back to physics when destroying world. */
105  void handleResetRace() { m_end_ticks = std::numeric_limits<int>::max(); }
106  // ------------------------------------------------------------------------
107  /* Used to recreate animation in \ref KartRewinder. */
108  virtual void saveState(BareNetworkString* buffer);
109  // ------------------------------------------------------------------------
110  /* Called when kart animation is the same in kart state, which make sure
111  * for example the end or created ticks are the same. */
112  virtual void restoreState(BareNetworkString* buffer)
113  { restoreBasicState(buffer); }
114 }; // AbstractKartAnimation
115 
116 #endif
The base class for all kart animation, like rescue, explosion, or cannon.
Definition: abstract_kart_animation.hpp:60
float getMaximumHeight(const Vec3 &up_vector, float height_remove)
Determine maximum rescue height with up-raycast.
Definition: abstract_kart_animation.cpp:160
AbstractKartAnimation(AbstractKart *kart, const std::string &name)
Constructor.
Definition: abstract_kart_animation.cpp:41
void restoreBasicState(BareNetworkString *buffer)
Used in constructor of sub-class as no virtual function can be used there.
Definition: abstract_kart_animation.cpp:194
virtual const std::string & getName() const
To easily allow printing the name of the animation being used atm.
Definition: abstract_kart_animation.hpp:100
virtual float getAnimationTimer() const
Returns the current animation timer.
Definition: abstract_kart_animation.cpp:149
void resetPowerUp()
In CTF mode call this to reset kart powerup when get hit.
Definition: abstract_kart_animation.cpp:107
int m_created_ticks
Time in ticks for the animation creation.
Definition: abstract_kart_animation.hpp:73
int m_end_ticks
Time in ticks for the animation which ends in world count up ticks.
Definition: abstract_kart_animation.hpp:70
virtual void update(int ticks)
Updates the timer, and if it expires, the kart animation will be removed from the kart and this objec...
Definition: abstract_kart_animation.cpp:121
std::string m_name
Name of this animation, used for debug prints only.
Definition: abstract_kart_animation.hpp:63
btTransform m_created_transform
Transformation by the time the animation was created, used for rewind to recreate the animation with ...
Definition: abstract_kart_animation.hpp:77
AbstractKart * m_kart
A pointer to the kart which is animated by this class.
Definition: abstract_kart_animation.hpp:67
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Exception for kart animation creation in networking, so if thrown it will tell the num of bytes skipp...
Definition: abstract_kart_animation.hpp:45
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35