Allow changing camera target after finishing network race

This commit is contained in:
Benau
2019-01-28 01:17:26 +08:00
parent a0c6bc41a2
commit efb6b9e2cf
3 changed files with 47 additions and 2 deletions

View File

@@ -39,10 +39,12 @@
#include "graphics/irr_driver.hpp"
#endif
#include "graphics/camera.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/max_speed.hpp"
#include "karts/rescue_animation.hpp"
#include "modes/linear_world.hpp"
#include "network/protocols/client_lobby.hpp"
#include "race/race_manager.hpp"
#include "states_screens/race_result_gui.hpp"
#include "tracks/drive_graph.hpp"
@@ -55,6 +57,8 @@ EndController::EndController(AbstractKart *kart,
Controller *prev_controller)
: AIBaseLapController(kart)
{
m_network_spectate_time = std::numeric_limits<uint64_t>::max();
m_use_normal_camera_spectating = false;
m_previous_controller = prev_controller;
if(!race_manager->isBattleMode() &&
race_manager->getMinorMode()!=RaceManager::MINOR_MODE_SOCCER)
@@ -164,6 +168,18 @@ void EndController::newLap(int lap)
*/
bool EndController::action(PlayerAction action, int value, bool dry_run)
{
auto cl = LobbyProtocol::get<ClientLobby>();
if (StkTime::getRealTimeMs() > m_network_spectate_time && cl)
{
if (!m_use_normal_camera_spectating)
{
// Only 1 local player will be able to change target
m_use_normal_camera_spectating = true;
Camera::changeCamera(0, Camera::CM_TYPE_NORMAL);
}
cl->changeSpectateTarget(action, value);
return true;
}
if(action!=PA_FIRE) return true;
RaceResultGUI *race_result_gui =
dynamic_cast<RaceResultGUI*>(World::getWorld()->getRaceGUI());
@@ -325,4 +341,3 @@ int EndController::calcSteps()
return steps;
} // calcSteps

View File

@@ -69,6 +69,10 @@ private:
* is targeting at. */
irr::scene::ISceneNode *m_debug_sphere;
uint64_t m_network_spectate_time;
bool m_use_normal_camera_spectating;
/*Functions called directly from update(). They all represent an action
*that can be done, and end up setting their respective m_controls
*variable.
@@ -114,7 +118,9 @@ public:
/** Returns the name of the previous controller (which has the right
* player name associated). */
core::stringw getName() const { return m_previous_controller->getName(); }
// ------------------------------------------------------------------------
void setNetworkSpectateTime(uint64_t time)
{ m_network_spectate_time = time; }
}; // EndKart
#endif

View File

@@ -68,6 +68,7 @@
#include "modes/profile_world.hpp"
#include "modes/soccer_world.hpp"
#include "network/network_config.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/race_event_manager.hpp"
#include "network/rewind_info.hpp"
#include "network/rewind_manager.hpp"
@@ -987,6 +988,29 @@ void Kart::finishedRace(float time, bool from_server)
}
} // !from_server
#ifndef ANDROID
auto cl = LobbyProtocol::get<ClientLobby>();
if (cl && m_controller->isLocalPlayerController() &&
race_manager->getNumLocalPlayers() == 1 &&
race_manager->modeHasLaps() && from_server)
{
static bool msg_shown = false;
if (!msg_shown)
{
msg_shown = true;
cl->addSpectateHelperMessage();
}
EndController* ec = dynamic_cast<EndController*>(m_controller);
if (ec)
{
// Enable spectate mode after 3 seconds which allow player to
// release left / right button if they keep pressing it during
// finishing line
ec->setNetworkSpectateTime(StkTime::getRealTimeMs() + 3000);
}
}
#endif
m_finished_race = true;
m_finish_time = time;