Fixed history debug files.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5133 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-04-08 12:45:57 +00:00
parent 54fe97f890
commit 1b5f33e210
3 changed files with 45 additions and 45 deletions

View File

@ -130,7 +130,9 @@ void World::init()
for(unsigned int i=0; i<num_karts; i++) for(unsigned int i=0; i<num_karts; i++)
{ {
btTransform init_pos=m_track->getStartTransform(i); btTransform init_pos=m_track->getStartTransform(i);
const std::string& kart_ident = race_manager->getKartIdent(i); const std::string& kart_ident =
history->replayHistory() ? history->getKartIdent(i)
: race_manager->getKartIdent(i);
int local_player_id = race_manager->getKartLocalPlayerId(i); int local_player_id = race_manager->getKartLocalPlayerId(i);
int global_player_id = race_manager->getKartGlobalPlayerId(i); int global_player_id = race_manager->getKartGlobalPlayerId(i);
Kart* newkart = createKart(kart_ident, i, local_player_id, Kart* newkart = createKart(kart_ident, i, local_player_id,

View File

@ -28,8 +28,6 @@
History* history = 0; History* history = 0;
#define KEEP_OLD_FORMAT
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Initialises the history object and sets the mode to none. /** Initialises the history object and sets the mode to none.
*/ */
@ -105,13 +103,13 @@ void History::updateSaving(float dt)
World *world = World::getWorld(); World *world = World::getWorld();
unsigned int num_karts = world->getNumKarts(); unsigned int num_karts = world->getNumKarts();
unsigned int index = m_current*num_karts;
for(unsigned int i=0; i<num_karts; i++) for(unsigned int i=0; i<num_karts; i++)
{ {
unsigned int index = m_current*num_karts+i; const Kart *kart = world->getKart(i);
const Kart *kart = world->getKart(i); m_all_controls[index+i] = kart->getControls();
m_all_controls[index] = kart->getControls(); m_all_xyz[index+i] = kart->getXYZ();
m_all_xyz[index] = kart->getXYZ(); m_all_rotations[index+i] = kart->getRotation();
m_all_rotations[index] = kart->getRotation();
} // for i } // for i
} // updateSaving } // updateSaving
@ -173,35 +171,30 @@ void History::Save()
} }
fprintf(fd, "size: %d\n", m_size); fprintf(fd, "size: %d\n", m_size);
int j = m_wrapped ? m_current : 0; int index = m_wrapped ? m_current : 0;
for(int i=0; i<m_size; i++) for(int i=0; i<m_size; i++)
{ {
fprintf(fd, "delta: %f\n",m_all_deltas[i]); fprintf(fd, "delta: %f\n",m_all_deltas[index]);
j=(j+1)%m_size; index=(index+1)%m_size;
} }
for(int k=0; k<num_karts; k++) index = num_karts * (m_wrapped ? m_current : 0);
for(int i=0; i<m_size; i++)
{ {
//Kart* kart= RaceManager::getKart(k); for(int k=0; k<num_karts; k++)
j = m_wrapped ? m_current : 0;
for(int i=0; i<m_size; i++)
{ {
// FIXME: kart number is not really necessary fprintf(fd, "%f %f %d %f %f %f %f %f %f %f\n",
fprintf(fd, "%d %f %f %d %f %f %f %f %f %f %f\n", m_all_controls[index+k].m_steer,
k, m_all_controls[index+k].m_accel,
m_all_controls[j].m_steer, m_all_controls[index+k].getButtonsCompressed(),
m_all_controls[j].m_accel, m_all_xyz[index+k].getX(), m_all_xyz[index+k].getY(),
m_all_controls[j].getButtonsCompressed(), m_all_xyz[index+k].getZ(),
m_all_xyz[j].getX(), m_all_rotations[index+k].getX(),
#ifdef KEEP_OLD_FORMAT m_all_rotations[index+k].getY(),
m_all_xyz[j].getZ(), m_all_xyz[j].getY(), m_all_rotations[index+k].getZ(),
#else m_all_rotations[index+k].getW() );
m_all_xyz[j].getY(), m_all_xyz[j].getZ(),
#endif
m_all_rotations[j].getX(), m_all_rotations[j].getY(),
m_all_rotations[j].getZ(), m_all_rotations[j].getW() );
j=(j+1)%m_size;
} // for i } // for i
index=(index+num_karts)%(num_karts*m_size);
} // for k } // for k
fprintf(fd, "History file end.\n"); fprintf(fd, "History file end.\n");
fclose(fd); fclose(fd);
@ -292,6 +285,7 @@ void History::Load()
i); i);
exit(-2); exit(-2);
} }
m_kart_ident.push_back(s1);
if(i<race_manager->getNumPlayers()) if(i<race_manager->getNumPlayers())
{ {
race_manager->setLocalKartInfo(i, s1); race_manager->setLocalKartInfo(i, s1);
@ -313,10 +307,10 @@ void History::Load()
sscanf(s, "delta: %f\n",&m_all_deltas[i]); sscanf(s, "delta: %f\n",&m_all_deltas[i]);
} }
for(unsigned int k=0; k<num_karts; k++) for(int i=0; i<m_size; i++)
{ {
int j=0; int j=0;
for(int i=0; i<m_size; i++) for(unsigned int k=0; k<num_karts; k++)
{ {
fgets(s, 1023, fd); fgets(s, 1023, fd);
int buttonsCompressed; int buttonsCompressed;
@ -326,21 +320,13 @@ void History::Load()
&m_all_controls[i].m_steer, &m_all_controls[i].m_steer,
&m_all_controls[i].m_accel, &m_all_controls[i].m_accel,
&buttonsCompressed, &buttonsCompressed,
&x, &x, &y, &z,
#ifdef KEEP_OLD_FORMAT
&z, &y,
//xyz
//yxz
//yzx
&rx, &rz, &ry, &rw
#else
&y, &z,
&rx, &ry, &rz, &rw &rx, &ry, &rz, &rw
#endif
); );
m_all_xyz[i] = Vec3(x,y,z); unsigned int index = num_karts * i+k;
m_all_rotations[i] = btQuaternion(rx,ry,rz,rw); m_all_xyz[index] = Vec3(x,y,z);
m_all_controls[i].setButtonsCompressed(char(buttonsCompressed)); m_all_rotations[index] = btQuaternion(rx,ry,rz,rw);
m_all_controls[index].setButtonsCompressed(char(buttonsCompressed));
} // for i } // for i
} // for k } // for k
fprintf(fd, "History file end.\n"); fprintf(fd, "History file end.\n");

View File

@ -52,6 +52,9 @@ private:
std::vector<KartControl> m_all_controls; std::vector<KartControl> m_all_controls;
std::vector<Vec3> m_all_xyz; std::vector<Vec3> m_all_xyz;
std::vector<btQuaternion> m_all_rotations; std::vector<btQuaternion> m_all_rotations;
/** The identities of the karts to use. */
std::vector<std::string> m_kart_ident;
void allocateMemory(int number_of_frames); void allocateMemory(int number_of_frames);
void updateSaving(float dt); void updateSaving(float dt);
void updateReplay(float dt); void updateReplay(float dt);
@ -62,6 +65,15 @@ public:
void update (float dt); void update (float dt);
void Save (); void Save ();
void Load (); void Load ();
// ------------------------------------------------------------------------
/** Returns the identifier of the n-th kart. */
const std::string& getKartIdent(unsigned int n)
{
return m_kart_ident[n];
}
// ------------------------------------------------------------------------
/** Returns the size of the next timestep. */
float getNextDelta () const { return m_all_deltas[m_current]; } float getNextDelta () const { return m_all_deltas[m_current]; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------