Save jumping event in replay file

This commit is contained in:
Benau
2016-02-17 14:02:33 +08:00
parent ee68b5ccce
commit c65b0aaae0
6 changed files with 36 additions and 14 deletions

View File

@@ -457,6 +457,9 @@ public:
// ------------------------------------------------------------------------
/** Returns whether this kart is a ghost (replay) kart. */
virtual bool isGhostKart() const = 0;
// ------------------------------------------------------------------------
/** Returns whether this kart is jumping. */
virtual bool isJumping() const = 0;
}; // AbstractKart

View File

@@ -114,10 +114,22 @@ void GhostKart::update(float dt)
Moveable::updateGraphics(dt, center_shift, btQuaternion(0, 0, 0, 1));
getKartModel()->update(dt, dt*(m_all_physic_info[idx].m_speed),
m_all_physic_info[idx].m_steer, m_all_physic_info[idx].m_speed, idx);
getKartGFX()->update(dt);
Vec3 front(0, 0, getKartLength()*0.5f);
m_xyz_front = getTrans()(front);
getKartGFX()->update(dt);
if (m_all_replay_events[idx].m_jumping && !m_is_jumping)
{
m_is_jumping = true;
getKartModel()->setAnimation(KartModel::AF_JUMP_START);
}
else if (!m_all_replay_events[idx].m_jumping && m_is_jumping)
{
m_is_jumping = false;
getKartModel()->setAnimation(KartModel::AF_DEFAULT);
}
} // update
// ----------------------------------------------------------------------------

View File

@@ -72,6 +72,9 @@ protected:
* new lap is triggered. */
Vec3 m_xyz_front;
/** Is time flying activated */
bool m_is_jumping;
private:
/** Handles speed increase and capping due to powerup, terrain, ... */
MaxSpeed *m_max_speed;
@@ -170,9 +173,6 @@ private:
// Graphical effects
// -----------------
/** Is time flying activated */
bool m_is_jumping;
/** The shadow of a kart. */
Shadow *m_shadow;
@@ -451,6 +451,9 @@ public:
// ------------------------------------------------------------------------
/** Returns whether this kart is a ghost (replay) kart. */
virtual bool isGhostKart() const { return false; }
// ------------------------------------------------------------------------
/** Returns whether this kart is jumping. */
virtual bool isJumping() const { return m_is_jumping; };
}; // Kart

View File

@@ -57,13 +57,14 @@ protected:
}; // PhysicInfo
// ------------------------------------------------------------------------
/** Records all other events - atm nitro and zipper handling. */
/** Records all other events - atm nitro, zipper and jumping handling. */
struct KartReplayEvent
{
/** True if the kart recorded is using nitro/zipper.
* If true, a suitable GFX will be replayed. */
/** True if the kart recorded is using nitro/zipper or jumping.
* If true, a suitable GFX or animation will be replayed. */
bool m_on_nitro;
bool m_on_zipper;
bool m_jumping;
}; // KartReplayEvent
// ------------------------------------------------------------------------
@@ -75,7 +76,7 @@ protected:
/** Returns the version number of the replay file. This is used to check
* that a loaded replay file can still be understood by this
* executable. */
unsigned int getReplayVersion() const { return 1; }
unsigned int getReplayVersion() const { return 2; }
public:
ReplayBase();

View File

@@ -225,17 +225,17 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line)
{
fgets(s, 1023, fd);
float x, y, z, rx, ry, rz, rw, time, speed, steer, w1, w2, w3, w4;
int nitro, zipper;
int nitro, zipper, jumping;
// Check for EV_TRANSFORM event:
// -----------------------------
if(sscanf(s, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %d %d\n",
if(sscanf(s, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %d %d %d\n",
&time,
&x, &y, &z,
&rx, &ry, &rz, &rw,
&speed, &steer, &w1, &w2, &w3, &w4,
&nitro, &zipper
)==16)
&nitro, &zipper, &jumping
)==17)
{
btQuaternion q(rx, ry, rz, rw);
btVector3 xyz(x, y, z);
@@ -249,6 +249,7 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line)
pi.m_suspension_length[3] = w4;
kre.m_on_nitro = (bool)nitro;
kre.m_on_zipper = (bool)zipper;
kre.m_jumping = (bool)jumping;
m_ghost_karts[kart_num].addReplayEvent(time,
btTransform(q, xyz), pi, kre);
}

View File

@@ -169,6 +169,7 @@ void ReplayRecorder::update(float dt)
}
r->m_on_nitro = nitro;
r->m_on_zipper = zipper;
r->m_jumping = kart->isJumping();
} // for i
if (world->getPhase() == World::RESULT_DISPLAY_PHASE && !m_complete_replay)
@@ -255,7 +256,7 @@ void ReplayRecorder::save()
const TransformEvent *p = &(m_transform_events[k][i]);
const PhysicInfo *q = &(m_physic_info[k][i]);
const KartReplayEvent *r = &(m_kart_replay_event[k][i]);
fprintf(fd, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %d %d\n",
fprintf(fd, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %d %d %d\n",
p->m_time,
p->m_transform.getOrigin().getX(),
p->m_transform.getOrigin().getY(),
@@ -271,7 +272,8 @@ void ReplayRecorder::save()
q->m_suspension_length[2],
q->m_suspension_length[3],
(int)r->m_on_nitro,
(int)r->m_on_zipper
(int)r->m_on_zipper,
(int)r->m_jumping
);
} // for i
}