Move referee frame setting to its own class
This commit is contained in:
parent
3a90e828a4
commit
8a00d1e1ab
@ -17,6 +17,7 @@
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "graphics/referee.hpp"
|
||||
#include "config/stk_config.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/light.hpp"
|
||||
@ -27,6 +28,7 @@
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
@ -278,3 +280,17 @@ void Referee::selectReadySetGo(int rsg)
|
||||
}
|
||||
} // selectReadySetGo
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Set the referee animation frame with created ticks of \ref RescueAnimation,
|
||||
* so that it's synchronized with world ticks, and can be rewound easily.
|
||||
*/
|
||||
void Referee::setAnimationFrameWithCreatedTicks(int created_ticks)
|
||||
{
|
||||
float dur = stk_config->ticks2Time(
|
||||
World::getWorld()->getTicksSinceStart() - created_ticks);
|
||||
dur *= 25.0f;
|
||||
float ref_dur = (float)(m_st_last_rescue_frame - m_st_first_rescue_frame);
|
||||
float frame = std::fmod(dur, ref_dur);
|
||||
frame += (float)m_st_first_rescue_frame;
|
||||
m_scene_node->setCurrentFrame(frame);
|
||||
} // setAnimationFrameWithCreatedTicks
|
||||
|
@ -43,12 +43,6 @@ class AbstractKart;
|
||||
*/
|
||||
class Referee
|
||||
{
|
||||
public:
|
||||
/** Start frame of rescue animation. */
|
||||
static int m_st_first_rescue_frame;
|
||||
|
||||
/** End frame of rescue animation. */
|
||||
static int m_st_last_rescue_frame;
|
||||
private:
|
||||
/** The static mesh, which is loaded from a static function and shared
|
||||
* between all instances. */
|
||||
@ -66,6 +60,12 @@ private:
|
||||
/** End frame of start animation. */
|
||||
static int m_st_last_start_frame;
|
||||
|
||||
/** Start frame of rescue animation. */
|
||||
static int m_st_first_rescue_frame;
|
||||
|
||||
/** End frame of rescue animation. */
|
||||
static int m_st_last_rescue_frame;
|
||||
|
||||
/** The position the referee should be shown relative to the kart
|
||||
* when starting the race. */
|
||||
static Vec3 m_st_start_offset;
|
||||
@ -108,6 +108,8 @@ public:
|
||||
/** Returns true if this referee is attached to the scene graph. */
|
||||
bool isAttached() const {return m_scene_node->getParent()!=NULL;}
|
||||
// ------------------------------------------------------------------------
|
||||
void setAnimationFrameWithCreatedTicks(int created_ticks);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the graphical offset the referee should be drawn at at the
|
||||
* start of a race. */
|
||||
static const Vec3& getStartOffset() {return m_st_start_offset; }
|
||||
|
@ -190,14 +190,7 @@ void RescueAnimation::updateGraphics(float dt)
|
||||
m_referee = new Referee(*m_kart);
|
||||
m_kart->getNode()->addChild(m_referee->getSceneNode());
|
||||
}
|
||||
float dur = stk_config->ticks2Time(
|
||||
World::getWorld()->getTicksSinceStart() - m_created_ticks);
|
||||
dur *= 25.0f;
|
||||
float ref_dur = (float)
|
||||
(Referee::m_st_last_rescue_frame - Referee::m_st_first_rescue_frame);
|
||||
float frame = std::fmod(dur, ref_dur);
|
||||
frame += (float)Referee::m_st_first_rescue_frame;
|
||||
m_referee->getSceneNode()->setCurrentFrame(frame);
|
||||
m_referee->setAnimationFrameWithCreatedTicks(m_created_ticks);
|
||||
AbstractKartAnimation::updateGraphics(dt);
|
||||
} // updateGraphics
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user