Don't recreate locally destroyed projectile

This commit is contained in:
Benau 2018-07-30 01:56:14 +08:00
parent 982220daf8
commit 59ebc48fe1
5 changed files with 78 additions and 23 deletions

View File

@ -721,6 +721,7 @@ void Flyable::handleUndoDestruction()
hideNodeWhenUndoDestruction();
std::shared_ptr<Flyable> f = getShared<Flyable>();
std::string uid = f->getUniqueIdentity();
projectile_manager->addDeletedUID(uid);
RewindManager::get()->addRewindInfoEventFunction(new
RewindInfoEventFunction(World::getWorld()->getTicksSinceStart(),
/*undo_function*/[f, uid]()

View File

@ -28,6 +28,7 @@
#include "items/rubber_ball.hpp"
#include "karts/abstract_kart.hpp"
#include "modes/world.hpp"
#include "network/dummy_rewinder.hpp"
#include "network/rewind_manager.hpp"
ProjectileManager *projectile_manager=0;
@ -48,6 +49,7 @@ void ProjectileManager::removeTextures()
void ProjectileManager::cleanup()
{
m_active_projectiles.clear();
m_deleted_projectiles.clear();
for(HitEffects::iterator i = m_active_hit_effects.begin();
i != m_active_hit_effects.end(); ++i)
{
@ -262,8 +264,17 @@ std::shared_ptr<Rewinder>
return nullptr;
AbstractKart* kart = World::getWorld()->getKart(world_id);
char first_id = id[0][0];
Log::debug("ProjectileManager", "Missed a firing event or locally deleted,"
" add the flyable %s manually", uid.c_str());
auto it = m_deleted_projectiles.find(uid);
if (it != m_deleted_projectiles.end())
{
Log::debug("ProjectileManager", "Flyable %s locally (early) deleted,"
" use a dummy rewinder to skip.", uid.c_str());
return std::make_shared<DummyRewinder>();
}
Log::debug("ProjectileManager",
"Missed a firing event, add the flyable %s manually.", uid.c_str());
switch (first_id)
{
case 'B':

View File

@ -21,6 +21,7 @@
#include <map>
#include <memory>
#include <unordered_set>
#include <vector>
namespace irr
@ -50,6 +51,8 @@ private:
* currently moving on the track. */
std::map<std::string, std::shared_ptr<Flyable> > m_active_projectiles;
std::unordered_set<std::string> m_deleted_projectiles;
/** All active hit effects, i.e. hit effects which are currently
* being shown or have a sfx playing. */
HitEffects m_active_hit_effects;
@ -87,7 +90,9 @@ public:
// ------------------------------------------------------------------------
void removeByUID(const std::string& uid)
{ m_active_projectiles.erase(uid); }
// ------------------------------------------------------------------------
void addDeletedUID(const std::string& uid)
{ m_deleted_projectiles.insert(uid); }
};
extern ProjectileManager *projectile_manager;

View File

@ -0,0 +1,53 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2018 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_DUMMY_REWINDER_HPP
#define HEADER_DUMMY_REWINDER_HPP
#include "network/event_rewinder.hpp"
#include "network/network_string.hpp"
#include "network/rewinder.hpp"
/** A dummy Rewinder and EventRewinder class for unit testing and handle undo
* destruction of projectiles. */
class DummyRewinder : public Rewinder, public EventRewinder
{
public:
// -------------------------------------------------------------------------
BareNetworkString* saveState(std::vector<std::string>* ru) { return NULL; }
// -------------------------------------------------------------------------
virtual void undoEvent(BareNetworkString* s) {}
// -------------------------------------------------------------------------
virtual void rewindToEvent(BareNetworkString* s) {}
// -------------------------------------------------------------------------
virtual void restoreState(BareNetworkString* s, int count)
{ s->skip(count); }
// -------------------------------------------------------------------------
virtual void undoState(BareNetworkString *s) {}
// -------------------------------------------------------------------------
virtual void undo(BareNetworkString *s) {}
// -------------------------------------------------------------------------
virtual void rewind(BareNetworkString *s) {}
// -------------------------------------------------------------------------
virtual void saveTransform() {}
// -------------------------------------------------------------------------
virtual void computeError() {}
};
#endif

View File

@ -20,6 +20,7 @@
#include "config/stk_config.hpp"
#include "modes/world.hpp"
#include "network/dummy_rewinder.hpp"
#include "network/network_config.hpp"
#include "network/rewinder.hpp"
#include "network/rewind_info.hpp"
@ -405,24 +406,6 @@ void RewindQueue::unitTesting()
{
// Some classes need the RewindManager (to register themselves with)
RewindManager::create();
// A dummy Rewinder and EventRewinder class since some of the calls being
// tested here need an instance.
class DummyRewinder : public Rewinder, public EventRewinder
{
public:
BareNetworkString* saveState(std::vector<std::string>* ru)
{ return NULL; }
virtual void undoEvent(BareNetworkString *s) {}
virtual void rewindToEvent(BareNetworkString *s) {}
virtual void restoreState(BareNetworkString *s, int count) {}
virtual void undoState(BareNetworkString *s) {}
virtual void undo(BareNetworkString *s) {}
virtual void rewind(BareNetworkString *s) {}
virtual void saveTransform() {}
virtual void computeError() {}
DummyRewinder() : Rewinder() {}
};
auto dummy_rewinder = std::make_shared<DummyRewinder>();
// First tests: add a state first, then an event, and make
@ -494,7 +477,8 @@ void RewindQueue::unitTesting()
assert(!b1.hasMoreRewindInfo());
b1.addLocalEvent(NULL, NULL, true, 2);
RewindInfo *ri = b1.getCurrent();
assert(ri->getTicks() == 2);
if (ri->getTicks() != 2)
Log::fatal("RewindQueue", "ri->getTicks() != 2");
// 2) Make sure when adding an event at the same time as an existing
// event, that m_current pooints to the first event, otherwise
@ -504,7 +488,8 @@ void RewindQueue::unitTesting()
b1.addLocalEvent(NULL, NULL, true, 2);
// Make sure that current was not modified, i.e. the new event at time
// 2 was added at the end of the list:
assert(current_old == b1.m_current);
if (current_old != b1.m_current)
Log::fatal("RewindQueue", "current_old != b1.m_current");
// This should not trigger an exception, now current points to the
// second event at the same time: