Use rewinder with binary uid
This commit is contained in:
parent
9b4b283c4c
commit
eb8544b785
@ -50,6 +50,8 @@
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/vs.hpp"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
// static variables:
|
||||
float Flyable::m_st_speed [PowerupManager::POWERUP_MAX];
|
||||
scene::IMesh* Flyable::m_st_model [PowerupManager::POWERUP_MAX];
|
||||
@ -98,6 +100,7 @@ Flyable::Flyable(AbstractKart *kart, PowerupManager::PowerupType type,
|
||||
// Smooth network body for flyable doesn't seem to be needed, most of the
|
||||
// time it rewinds almost the same
|
||||
SmoothNetworkBody::setEnable(false);
|
||||
m_created_ticks = World::getWorld()->getTicksSinceStart();
|
||||
} // Flyable
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -726,8 +729,10 @@ void Flyable::computeError()
|
||||
state_ticks > m_last_deleted_ticks))
|
||||
{
|
||||
const std::string& uid = getUniqueIdentity();
|
||||
Log::debug("Flyable", "Item %s doesn't exist on server, "
|
||||
"remove it.", uid.c_str());
|
||||
Log::debug("Flyable", "Flyable %s by %s created at %d "
|
||||
"doesn't exist on server, remove it.",
|
||||
typeid(*this).name(), StringUtils::wideToUtf8(
|
||||
m_owner->getController()->getName()).c_str(), m_created_ticks);
|
||||
projectile_manager->removeByUID(uid);
|
||||
}
|
||||
} // computeError
|
||||
|
@ -153,6 +153,8 @@ protected:
|
||||
* that may ticks. */
|
||||
int m_max_lifespan;
|
||||
|
||||
/* For debugging purpose */
|
||||
int m_created_ticks;
|
||||
|
||||
void getClosestKart(const AbstractKart **minKart,
|
||||
float *minDistSquared,
|
||||
@ -265,7 +267,8 @@ public:
|
||||
virtual void onFireFlyable();
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void onDeleteFlyable();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void setCreatedTicks(int ticks) { m_created_ticks = ticks; }
|
||||
}; // Flyable
|
||||
|
||||
#endif
|
||||
|
@ -47,7 +47,7 @@ void NetworkItemManager::create()
|
||||
* "I" which is less than "Kx" (kart rewinder with id x)
|
||||
*/
|
||||
NetworkItemManager::NetworkItemManager()
|
||||
: Rewinder("I"), ItemManager()
|
||||
: Rewinder({RN_ITEM_MANAGER}), ItemManager()
|
||||
{
|
||||
m_confirmed_switch_ticks = -1;
|
||||
m_last_confirmed_item_ticks.clear();
|
||||
|
@ -27,10 +27,14 @@
|
||||
#include "items/powerup.hpp"
|
||||
#include "items/rubber_ball.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "karts/controller/controller.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/network_string.hpp"
|
||||
#include "network/rewind_manager.hpp"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
ProjectileManager *projectile_manager=0;
|
||||
|
||||
void ProjectileManager::loadData()
|
||||
@ -233,28 +237,36 @@ int ProjectileManager::getNearbyProjectileCount(const AbstractKart * const kart,
|
||||
std::string ProjectileManager::getUniqueIdentity(AbstractKart* kart,
|
||||
PowerupManager::PowerupType t)
|
||||
{
|
||||
BareNetworkString uid;
|
||||
switch (t)
|
||||
{
|
||||
case PowerupManager::POWERUP_BOWLING:
|
||||
return std::string("B_") +
|
||||
StringUtils::toString(kart->getWorldKartId()) + "_" +
|
||||
StringUtils::toString(World::getWorld()->getTicksSinceStart());
|
||||
{
|
||||
uid.addUInt8(RN_BOWLING);
|
||||
break;
|
||||
}
|
||||
case PowerupManager::POWERUP_PLUNGER:
|
||||
return std::string("P_") +
|
||||
StringUtils::toString(kart->getWorldKartId()) + "_" +
|
||||
StringUtils::toString(World::getWorld()->getTicksSinceStart());
|
||||
{
|
||||
uid.addUInt8(RN_PLUNGER);
|
||||
break;
|
||||
}
|
||||
case PowerupManager::POWERUP_CAKE:
|
||||
return std::string("C_") +
|
||||
StringUtils::toString(kart->getWorldKartId()) + "_" +
|
||||
StringUtils::toString(World::getWorld()->getTicksSinceStart());
|
||||
{
|
||||
uid.addUInt8(RN_CAKE);
|
||||
break;
|
||||
}
|
||||
case PowerupManager::POWERUP_RUBBERBALL:
|
||||
return std::string("R_") +
|
||||
StringUtils::toString(kart->getWorldKartId()) + "_" +
|
||||
StringUtils::toString(World::getWorld()->getTicksSinceStart());
|
||||
{
|
||||
uid.addUInt8(RN_RUBBERBALL);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
return "";
|
||||
}
|
||||
uid.addUInt8((uint8_t)kart->getWorldKartId())
|
||||
.addUInt32(World::getWorld()->getTicksSinceStart());
|
||||
return std::string((char*)uid.getBuffer().data(), uid.getBuffer().size());
|
||||
} // getUniqueIdentity
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -263,38 +275,36 @@ std::string ProjectileManager::getUniqueIdentity(AbstractKart* kart,
|
||||
std::shared_ptr<Rewinder>
|
||||
ProjectileManager::addRewinderFromNetworkState(const std::string& uid)
|
||||
{
|
||||
std::vector<std::string> id = StringUtils::split(uid, '_');
|
||||
if (id.size() != 3)
|
||||
if (uid.size() != 6)
|
||||
return nullptr;
|
||||
if (!(id[0] == "B" || id[0] == "P" || id[0] == "C" || id[0] == "R"))
|
||||
return nullptr;
|
||||
int world_id = -1;
|
||||
if (!StringUtils::fromString(id[1], world_id))
|
||||
return nullptr;
|
||||
AbstractKart* kart = World::getWorld()->getKart(world_id);
|
||||
char first_id = id[0][0];
|
||||
BareNetworkString data(uid.data(), uid.size());
|
||||
|
||||
Log::debug("ProjectileManager",
|
||||
"Missed a firing event, add the flyable %s manually.", uid.c_str());
|
||||
RewinderName rn = (RewinderName)data.getUInt8();
|
||||
if (!(rn == RN_BOWLING || rn == RN_PLUNGER ||
|
||||
rn == RN_CAKE || rn == RN_RUBBERBALL))
|
||||
return nullptr;
|
||||
|
||||
AbstractKart* kart = World::getWorld()->getKart(data.getUInt8());
|
||||
int created_ticks = data.getUInt32();
|
||||
std::shared_ptr<Flyable> f;
|
||||
switch (first_id)
|
||||
switch (rn)
|
||||
{
|
||||
case 'B':
|
||||
case RN_BOWLING:
|
||||
{
|
||||
f = std::make_shared<Bowling>(kart);
|
||||
break;
|
||||
}
|
||||
case 'P':
|
||||
case RN_PLUNGER:
|
||||
{
|
||||
f = std::make_shared<Plunger>(kart);
|
||||
break;
|
||||
}
|
||||
case 'C':
|
||||
case RN_CAKE:
|
||||
{
|
||||
f = std::make_shared<Cake>(kart);
|
||||
break;
|
||||
}
|
||||
case 'R':
|
||||
case RN_RUBBERBALL:
|
||||
{
|
||||
f = std::make_shared<RubberBall>(kart);
|
||||
break;
|
||||
@ -305,8 +315,16 @@ std::shared_ptr<Rewinder>
|
||||
}
|
||||
}
|
||||
assert(f);
|
||||
f->setCreatedTicks(created_ticks);
|
||||
f->onFireFlyable();
|
||||
f->addForRewind(uid);
|
||||
Flyable* flyable = f.get();
|
||||
Log::debug("ProjectileManager", "Missed a firing event, "
|
||||
"add the flyable %s by %s created at %d manually.",
|
||||
typeid(*flyable).name(),
|
||||
StringUtils::wideToUtf8(kart->getController()->getName()).c_str(),
|
||||
created_ticks);
|
||||
|
||||
m_active_projectiles[uid] = f;
|
||||
return f;
|
||||
} // addProjectileFromNetworkState
|
||||
|
@ -44,7 +44,11 @@ KartRewinder::KartRewinder(const std::string& ident,
|
||||
const btTransform& init_transform,
|
||||
PerPlayerDifficulty difficulty,
|
||||
std::shared_ptr<RenderInfo> ri)
|
||||
: Rewinder(std::string("K") + StringUtils::toString(world_kart_id))
|
||||
: Rewinder(
|
||||
{
|
||||
RN_KART,
|
||||
static_cast<char>(world_kart_id)
|
||||
})
|
||||
, Kart(ident, world_kart_id, position, init_transform, difficulty,
|
||||
ri)
|
||||
{
|
||||
|
@ -64,10 +64,12 @@ private:
|
||||
public:
|
||||
// ------------------------------------------------------------------------
|
||||
CTFFlag(FlagColor fc, const btTransform& base_trans)
|
||||
: Rewinder(fc == FC_RED ? "TR" : "TB"), m_flag_base_trans(base_trans)
|
||||
: Rewinder(fc == FC_RED ?
|
||||
std::string{RN_RED_FLAG} : std::string{RN_BLUE_FLAG}),
|
||||
m_flag_base_trans(base_trans)
|
||||
{
|
||||
// UID rewinder with "T" which is after "Kx" for kart so
|
||||
// updateFlagTrans is called after kart is rewound
|
||||
// updateFlagTrans is called after kart is rewound, see rewinder name
|
||||
// defined in rewinder header
|
||||
m_flag_status = IN_BASE;
|
||||
m_flag_trans.setOrigin(Vec3(0.0f));
|
||||
m_flag_trans.setRotation(btQuaternion(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
@ -27,6 +27,19 @@
|
||||
|
||||
class BareNetworkString;
|
||||
|
||||
enum RewinderName : char
|
||||
{
|
||||
RN_ITEM_MANAGER = 0x01,
|
||||
RN_KART = 0x02,
|
||||
RN_RED_FLAG = 0x03,
|
||||
RN_BLUE_FLAG = 0x04,
|
||||
RN_CAKE = 0x05,
|
||||
RN_BOWLING = 0x06,
|
||||
RN_PLUNGER = 0x07,
|
||||
RN_RUBBERBALL = 0x08,
|
||||
RN_PHYSICAL_OBJ = 0x09
|
||||
};
|
||||
|
||||
class Rewinder : public std::enable_shared_from_this<Rewinder>
|
||||
{
|
||||
protected:
|
||||
@ -37,10 +50,10 @@ private:
|
||||
* uid. (see RewindInfoState::restore)
|
||||
* 2. Determine the order of restoring state for each rewinder, this is
|
||||
* used as a key in std::string, Rewinder map, which is less than.
|
||||
* So uid of "I" (item manager) is restored before "Kx" (which kart
|
||||
* id x) and TR / TB (the red / blue flag) is restored after karts,
|
||||
* because the restoreState in CTFFlag read kart transformation.
|
||||
* Otherwise it can be named whatever. */
|
||||
* So uid of "0x01" (item manager) is restored before "0x02, x" (which
|
||||
* kart id x) and 0x03 / 0x04 (the red / blue flag) is restored after
|
||||
* karts, because the restoreState in CTFFlag read kart transformation.
|
||||
*/
|
||||
std::string m_unique_identity;
|
||||
|
||||
public:
|
||||
|
@ -786,8 +786,13 @@ void PhysicalObject::addForRewind()
|
||||
SmoothNetworkBody::setEnable(true);
|
||||
SmoothNetworkBody::setSmoothRotation(false);
|
||||
SmoothNetworkBody::setAdjustVerticalOffset(false);
|
||||
Rewinder::setUniqueIdentity(std::string("P") + StringUtils::toString
|
||||
(Track::getCurrentTrack()->getPhysicalObjectUID()));
|
||||
Rewinder::setUniqueIdentity(
|
||||
{
|
||||
RN_PHYSICAL_OBJ,
|
||||
// We have max moveable physical object defined in stk_config,
|
||||
// which is 15 at the moment
|
||||
static_cast<char>(Track::getCurrentTrack()->getPhysicalObjectUID())
|
||||
});
|
||||
Rewinder::rewinderAdd();
|
||||
} // addForRewind
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user