This commit is contained in:
Benau 2018-07-02 15:40:27 +08:00
parent 211b107955
commit 674faad226
4 changed files with 25 additions and 26 deletions

View File

@ -59,6 +59,7 @@ LocalPlayerController::LocalPlayerController(AbstractKart *kart,
PerPlayerDifficulty d)
: PlayerController(kart), m_sky_particles_emitter(NULL)
{
m_actions.fill(0);
m_difficulty = d;
m_player = StateManager::get()->getActivePlayer(local_player_id);
if(m_player)
@ -150,14 +151,19 @@ void LocalPlayerController::resetInputState()
bool LocalPlayerController::action(PlayerAction action, int value,
bool dry_run)
{
m_actions.emplace_back(action, value);
if (action == PA_PAUSE_RACE)
{
PlayerController::action(action, value);
return true;
}
m_actions[action] = value;
return true;
} // action
// ----------------------------------------------------------------------------
void LocalPlayerController::handleBufferedActions(double time_spent)
{
if (m_actions.empty())
if (!isLocalPlayerController())
return;
// There is 0.1 delay in server, if time_spent is more than ~0.1, than
@ -166,13 +172,13 @@ void LocalPlayerController::handleBufferedActions(double time_spent)
{
Log::warn("LocalPlayerController", "Update race is too slow to catch"
" up: %lf", time_spent);
m_actions.clear();
return;
}
for (auto& p : m_actions)
for (int i = 0; i < PA_PAUSE_RACE; i++)
{
PlayerAction action = p.first;
int value = p.second;
PlayerAction action = (PlayerAction)i;
int value = m_actions[i];
// If this event does not change the control state (e.g.
// it's a (auto) repeat event), do nothing. This especially
@ -196,7 +202,6 @@ void LocalPlayerController::handleBufferedActions(double time_spent)
}
PlayerController::action(action, value, /*dry_run*/false);
}
m_actions.clear();
} // handleBufferedActions
//-----------------------------------------------------------------------------
@ -331,7 +336,7 @@ void LocalPlayerController::setPosition(int p)
d*/
void LocalPlayerController::finishedRace(float time)
{
// This will implicitely trigger setting the first end camera to be active
// This will implicitly trigger setting the first end camera to be active
Camera::changeCamera(m_camera_index, Camera::CM_TYPE_END);
} // finishedRace

View File

@ -23,8 +23,7 @@
#include "karts/controller/player_controller.hpp"
#include <utility>
#include <vector>
#include <array>
class AbstractKart;
class ParticleEmitter;
@ -66,7 +65,7 @@ private:
virtual void displayPenaltyWarning() OVERRIDE;
void nitroNotFullSound();
std::vector<std::pair<PlayerAction, int> > m_actions;
std::array<int, PA_PAUSE_RACE> m_actions;
public:
LocalPlayerController(AbstractKart *kart,

View File

@ -1311,6 +1311,16 @@ void World::unpause()
//-----------------------------------------------------------------------------
void World::escapePressed()
{
for (unsigned i = 0; i < m_karts.size(); i++)
{
for (unsigned j = 0; j < PA_PAUSE_RACE; j++)
{
if (m_karts[i]->isEliminated() || !m_karts[i]->getController()
->isLocalPlayerController())
continue;
m_karts[i]->getController()->action((PlayerAction)j, 0);
}
}
if (NetworkConfig::get()->isNetworking() || getPhase() >= MUSIC_PHASE)
new RacePausedDialog(0.8f, 0.6f);
} // escapePressed

View File

@ -25,9 +25,6 @@
#include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "karts/controller/controller.hpp"
#include "karts/kart.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "modes/overworld.hpp"
#include "modes/world.hpp"
@ -68,18 +65,6 @@ RacePausedDialog::RacePausedDialog(const float percentWidth,
{
music_manager->pauseMusic();
SFXManager::get()->pauseAll();
for (unsigned i = 0; i < World::getWorld()->getNumKarts(); i++)
{
for (unsigned j = 0; j < PA_PAUSE_RACE; j++)
{
if (World::getWorld()->getKart(i)->isEliminated() ||
!World::getWorld()->getKart(i)->getController()
->isLocalPlayerController())
break;
World::getWorld()->getKart(i)->getController()
->action((PlayerAction)j, 0);
}
}
}
else
{