void InitCharTools () { charbase = (int)((param.y_resolution - 200) / 18); firstnode = 1; lastnode = TestChar.GetNumNodes () -1; curr_node = firstnode; curr_act = firstact; lastact = TestChar.GetNumActs (curr_node) -1; action = TestChar.GetAction (curr_node); StoreAction (action); }
// The Replay packet header: // u32: time (ms => 2^16=65s => u16 sufficient) // Packet is directly an action: // . u32 => type // . u32 => length // . data void Replay::StoreAction(const Action* a) { uint size; ASSERT(is_recorder && replay_state==RECORDING); Action::Action_t type = a->GetType(); if ((type!=Action::ACTION_CHAT_INGAME_MESSAGE && a->IsFrameLess()) || type == Action::ACTION_NETWORK_PING || type == Action::ACTION_NETWORK_VERIFY_RANDOM_SYNC || type == Action::ACTION_TIME_VERIFY_SYNC || type == Action::ACTION_RULES_SET_GAME_MODE) return; // Special case to convert into local packet if (type == Action::ACTION_REQUEST_BONUS_BOX_DROP) { // The timestamp shouldn't have moved Action a(Action::ACTION_DROP_BONUS_BOX); StoreAction(&a); return; } size = a->GetSize(); // Enlarge buffer if it can't contain max packet size if (MemUsed() > bufsize - size + 2) ChangeBufsize(bufsize+30000); if (type != Action::ACTION_GAME_CALCULATE_FRAME) { if (count) { count--; MSG_DEBUG("replay", "Calculate frame repeated %u\n", count); // 16 bits is sufficient, around 22 minutes without other actions SDLNet_Write16(count, ptr); ptr += 2; } MSG_DEBUG("replay", "Storing action %s: type=%i length=%i\n", ActionHandler::GetActionName(type).c_str(), type, size); a->Write((char*)ptr); ptr += size; count = 0; } else { if (!count) { // Packet body a->Write((char*)ptr); ptr += size; } count++; } // Check time if (start_time == 0) start_time = GameTime::GetInstance()->Read(); else old_time = GameTime::GetInstance()->Read(); }
void ChangeNode (int steps) { bool ch; if (steps > 0) ch = (curr_node + steps <= lastnode); else ch = (curr_node + steps >= firstnode); if (ch) { curr_node += steps; curr_act = firstact; lastact = TestChar.GetNumActs (curr_node) -1; action = TestChar.GetAction (curr_node); if (action->num > 0 && action->type[0] == 4) comp = 0; else comp = 1; StoreAction (action); } }