Add document for uid of rewinder

This commit is contained in:
Benau 2018-12-25 01:24:14 +08:00
parent f8f571e40e
commit b69216f242
3 changed files with 16 additions and 20 deletions

View File

@ -40,9 +40,14 @@ void NetworkItemManager::create()
// ============================================================================
/** Creates a new instance of the item manager. This is done at startup
* of each race. */
* of each race.
* We must save the item state first (so that it is restored first), otherwise
* state updates for a kart could be overwritten by e.g. simulating the item
* collection later (which resets bubblegum counter), so a rewinder uid of
* "I" which is less than "Kx" (kart rewinder with id x)
*/
NetworkItemManager::NetworkItemManager()
: Rewinder("N"), ItemManager()
: Rewinder("I"), ItemManager()
{
m_confirmed_switch_ticks = -1;
m_last_confirmed_item_ticks.clear();

View File

@ -155,26 +155,8 @@ void RewindManager::saveState()
m_overall_state_size = 0;
std::vector<std::string> rewinder_using;
// We must save the item state first (so that it is restored first),
// otherwise state updates for a kart could be overwritten by
// e.g. simulating the item collection later (which resets bubblegum
// counter).
BareNetworkString* buffer = NULL;
if(auto r = m_all_rewinder["N"].lock())
buffer = r->saveState(&rewinder_using);
if (buffer)
{
m_overall_state_size += buffer->size();
gp->addState(buffer);
}
delete buffer; // buffer can be freed
for (auto& p : m_all_rewinder)
{
// The Network ItemManager was saved first before this loop,
// so skip it here.
if(p.first=="N") continue;
// TODO: check if it's worth passing in a sufficiently large buffer from
// GameProtocol - this would save the copy operation.
BareNetworkString* buffer = NULL;

View File

@ -32,6 +32,15 @@ class Rewinder : public std::enable_shared_from_this<Rewinder>
protected:
void setUniqueIdentity(const std::string& uid) { m_unique_identity = uid; }
private:
/** Currently it has 2 usages:
* 1. Create the required flyable if the firing event missed using this
* 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. */
std::string m_unique_identity;
public: