Allow racing against the replay on equal footing

It make record while replay possible too.

We show the ghost only when start racing, fixing the overlapping issue.
This commit is contained in:
Benau 2016-03-19 14:57:22 +08:00
parent a42ee39240
commit 07afd444a8
7 changed files with 84 additions and 17 deletions

View File

@ -3,13 +3,23 @@
<div x="5%" y="5%" width="90%" height="90%" layout="vertical-row">
<div x="5%" y="0%" width="90%" proportion="6" layout="horizontal-row">
<div width="40%" height="100%" layout="vertical-row">
<icon id="icon" align="center" proportion="8" width="100%" icon="gui/loading.png" />
<spacer proportion="1" />
<icon id="icon" align="center" width="100%" icon="gui/loading.png" />
</div>
<spacer proportion="1" />
<div width="60%" height="50%" layout="vertical-row">
<label id="name" width="100%" text_align="left"/>
<spacer height="10"/>
</div>
</div>
<div width="90%" align="center" layout="vertical-row" height="fit">
<div width="100%" height="fit" layout="horizontal-row" >
<checkbox width="fit" id="record-race" I18N="Ghost replay info action" text_align="left"/>
<spacer width="10"/>
<label proportion="1" id="record-race-text" height="100%" text_align="left" I18N="Ghost replay info action" text="Record the race for ghost replay"/>
</div>
<div width="100%" height="fit" layout="horizontal-row" >
<checkbox width="fit" id="watch-only" I18N="Ghost replay info action" text_align="left"/>
<spacer width="10"/>
<label proportion="1" height="100%" text_align="left" I18N="Ghost replay info action" text="Watch the race"/>
</div>
</div>

View File

@ -83,6 +83,16 @@ void GhostKart::update(float dt)
}
const unsigned int idx = gc->getCurrentReplayIndex();
if (idx == 0)
{
m_node->setVisible(false);
}
if (idx == 1)
{
// Start showing the ghost when it start racing
m_node->setVisible(true);
}
const float rd = gc->getReplayDelta();
assert(idx < m_all_transform.size());

View File

@ -322,8 +322,12 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
RaceManager::KartType kart_type,
PerPlayerDifficulty difficulty)
{
unsigned int gk = 0;
if (race_manager->hasGhostKarts())
gk = ReplayPlay::get()->getNumGhostKart();
int position = index+1;
btTransform init_pos = getStartTransform(index);
btTransform init_pos = getStartTransform(index - gk);
AbstractKart *new_kart = new Kart(kart_ident, index, position, init_pos,
difficulty);
new_kart->init(race_manager->getKartType(index));
@ -440,6 +444,8 @@ World::~World()
ReplayPlay::create();
}
m_karts.clear();
if(race_manager->willRecordRace())
ReplayRecorder::get()->reset();
race_manager->setRaceGhostKarts(false);
race_manager->setRecordRace(false);

View File

@ -50,16 +50,31 @@ ReplayRecorder::~ReplayRecorder()
} // ~Replay
//-----------------------------------------------------------------------------
/** Initialise the replay recorder. It especially allocates memory
* to store the replay data.
*/
void ReplayRecorder::init()
/** Reset the replay recorder. */
void ReplayRecorder::reset()
{
m_complete_replay = false;
m_incorrect_replay = false;
m_transform_events.clear();
m_physic_info.clear();
m_kart_replay_event.clear();
m_count_transforms.clear();
m_last_saved_time.clear();
#ifdef DEBUG
m_count = 0;
m_count_skipped_time = 0;
m_count_skipped_interpolation = 0;
#endif
} // clear
//-----------------------------------------------------------------------------
/** Initialise the replay recorder. It especially allocates memory
* to store the replay data.
*/
void ReplayRecorder::init()
{
reset();
m_transform_events.resize(race_manager->getNumberOfKarts());
m_physic_info.resize(race_manager->getNumberOfKarts());
m_kart_replay_event.resize(race_manager->getNumberOfKarts());
@ -71,16 +86,10 @@ void ReplayRecorder::init()
m_physic_info[i].resize(max_frames);
m_kart_replay_event[i].resize(max_frames);
}
m_count_transforms.clear();
m_count_transforms.resize(race_manager->getNumberOfKarts(), 0);
m_last_saved_time.clear();
m_last_saved_time.resize(race_manager->getNumberOfKarts(), -1.0f);
#ifdef DEBUG
m_count = 0;
m_count_skipped_time = 0;
m_count_skipped_interpolation = 0;
#endif
} // init
//-----------------------------------------------------------------------------

View File

@ -70,8 +70,9 @@ private:
~ReplayRecorder();
public:
void init();
void update(float dt);
void reset();
void save();
void update(float dt);
// ------------------------------------------------------------------------
/** Creates a new instance of the replay object. */

View File

@ -31,6 +31,9 @@ GhostReplayInfoDialog::GhostReplayInfoDialog(unsigned int replay_id)
: ModalDialog(0.8f,0.5f), m_replay_id(replay_id)
{
m_self_destroy = false;
m_record_race = false;
m_watch_only = false;
m_rd = ReplayPlay::get()->getReplayData(m_replay_id);
loadFromFile("ghost_replay_info_dialog.stkgui");
@ -41,6 +44,12 @@ GhostReplayInfoDialog::GhostReplayInfoDialog(unsigned int replay_id)
m_back_widget = getWidget<IconButtonWidget>("back");
m_back_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
m_action_widget = getWidget<RibbonWidget>("actions");
m_record_widget = getWidget<CheckBoxWidget>("record-race");
m_watch_widget = getWidget<CheckBoxWidget>("watch-only");
m_record_widget->setState(false);
m_watch_widget->setState(false);
} // GhostReplayInfoDialog
// -----------------------------------------------------------------------------
@ -64,10 +73,12 @@ GUIEngine::EventPropagation
std::string track_name = m_rd.m_track_name;
int laps = m_rd.m_laps;
int replay_id = m_replay_id;
bool record = m_record_race;
ModalDialog::dismiss();
ReplayPlay::get()->setReplayFile(replay_id);
race_manager->setRaceGhostKarts(true);
race_manager->setRecordRace(record);
race_manager->setNumKarts(race_manager->getNumLocalPlayers());
// Disable accidentally unlocking of a challenge
@ -92,6 +103,20 @@ GUIEngine::EventPropagation
return GUIEngine::EVENT_BLOCK;
}
}
if (event_source == "record-race")
{
m_record_race = m_record_widget->getState();
}
else if (event_source == "watch-only")
{
m_watch_only = m_watch_widget->getState();
m_record_race = false;
m_record_widget->setState(false);
m_record_widget->setVisible(!m_watch_only);
getWidget<LabelWidget>("record-race-text")->setVisible(!m_watch_only);
}
return GUIEngine::EVENT_LET;
} // processEvent

View File

@ -20,6 +20,7 @@
#define HEADER_GHOST_REPLAY_INFO_DIALOG_HPP
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "replay/replay_play.hpp"
@ -34,11 +35,16 @@ private:
bool m_self_destroy;
bool m_record_race;
bool m_watch_only;
const unsigned int m_replay_id;
ReplayPlay::ReplayData m_rd;
GUIEngine::RibbonWidget* m_action_widget;
GUIEngine::IconButtonWidget* m_back_widget;
GUIEngine::CheckBoxWidget* m_record_widget;
GUIEngine::CheckBoxWidget* m_watch_widget;
public:
GhostReplayInfoDialog(unsigned int replay_id);