void ReadyEvent::OnReadyEventPacketUpdate(Packet *packet) { RakNet::BitStream incomingBitStream(packet->data, packet->length, false); incomingBitStream.IgnoreBits(8); int eventId; incomingBitStream.Read(eventId); bool objectExists; unsigned readyIndex = readyEventNodeList.GetIndexFromKey(eventId, &objectExists); if (objectExists) { ReadyEventNode *ren = readyEventNodeList[readyIndex]; bool systemExists; unsigned systemIndex = ren->systemList.GetIndexFromKey(packet->systemAddress, &systemExists); if (systemExists) { // Just return if no change if (ren->systemList[systemIndex].lastReceivedStatus == packet->data[0]) return; bool wasCompleted = IsEventCompletedByIndex(readyIndex); ren->systemList[systemIndex].lastReceivedStatus = packet->data[0]; // If forced all set, doesn't matter what the new packet is if (ren->eventStatus == ID_READY_EVENT_FORCE_ALL_SET) return; UpdateReadyStatus(readyIndex); if (wasCompleted == false && IsEventCompletedByIndex(readyIndex)) PushCompletionPacket(readyIndex); } } }
bool ReadyEvent::SetEventByIndex(int eventIndex, bool isReady) { ReadyEventNode *ren = readyEventNodeList[eventIndex]; if ((ren->eventStatus==ID_READY_EVENT_ALL_SET || ren->eventStatus==ID_READY_EVENT_SET) && isReady==true) return true; // Success - no change if (ren->eventStatus==ID_READY_EVENT_UNSET && isReady==false) return true; // Success - no change if (ren->eventStatus==ID_READY_EVENT_FORCE_ALL_SET) return true; // Can't change if (isReady) ren->eventStatus=ID_READY_EVENT_SET; else ren->eventStatus=ID_READY_EVENT_UNSET; UpdateReadyStatus(eventIndex); // Check if now completed, and if so, tell the user about it if (IsEventCompletedByIndex(eventIndex)) { PushCompletionPacket(ren->eventId); } return true; }
bool ReadyEvent::RemoveFromWaitList(int eventId, SystemAddress address) { bool eventExists; unsigned eventIndex = readyEventNodeList.GetIndexFromKey(eventId, &eventExists); if (eventExists) { if (address==UNASSIGNED_SYSTEM_ADDRESS) { // Remove all waiters readyEventNodeList[eventIndex]->systemList.Clear(); UpdateReadyStatus(eventIndex); } else { bool systemExists; unsigned systemIndex = readyEventNodeList[eventIndex]->systemList.GetIndexFromKey(address, &systemExists); if (systemExists) { bool isCompleted = IsEventCompletedByIndex(eventIndex); readyEventNodeList[eventIndex]->systemList.RemoveAtIndex(systemIndex); if (isCompleted==false && IsEventCompletedByIndex(eventIndex)) PushCompletionPacket(readyEventNodeList[eventIndex]->eventId); UpdateReadyStatus(eventIndex); return true; } } } return false; }
void ReadyEvent::RemoveFromAllLists(SystemAddress address) { unsigned eventIndex; for (eventIndex = 0; eventIndex < readyEventNodeList.Size(); eventIndex++) { bool isCompleted = IsEventCompletedByIndex(eventIndex); bool systemExists; unsigned systemIndex; systemIndex = readyEventNodeList[eventIndex]->systemList.GetIndexFromKey(address, &systemExists); if (systemExists) readyEventNodeList[eventIndex]->systemList.RemoveAtIndex(systemIndex); UpdateReadyStatus(eventIndex); if (isCompleted == false && IsEventCompletedByIndex(eventIndex)) PushCompletionPacket(readyEventNodeList[eventIndex]->eventId); } }
void ReadyEvent::OnReadyEventForceAllSet(Packet *packet) { RakNet::BitStream incomingBitStream(packet->data, packet->length, false); incomingBitStream.IgnoreBits(8); int eventId; incomingBitStream.Read(eventId); bool objectExists; unsigned readyIndex = readyEventNodeList.GetIndexFromKey(eventId, &objectExists); if (objectExists) { ReadyEventNode *ren = readyEventNodeList[readyIndex]; if (ren->eventStatus != ID_READY_EVENT_FORCE_ALL_SET) { ren->eventStatus = ID_READY_EVENT_FORCE_ALL_SET; PushCompletionPacket(ren->eventId); } } }