| 108 | } |
| 109 | |
| 110 | bool SystemWorldClient::handleIncomingPacket(PacketPtr packet) { |
| 111 | if (auto updatePacket = as<SystemWorldUpdatePacket>(packet)) { |
| 112 | auto location = m_ship->systemLocation(); |
| 113 | for (auto p : updatePacket->shipUpdates) { |
| 114 | if (m_ship && p.first == m_ship->uuid()) |
| 115 | m_ship->readNetState(p.second, SystemWorldTimestep); |
| 116 | else |
| 117 | m_clientShips[p.first]->readNetState(p.second, SystemWorldTimestep); |
| 118 | } |
| 119 | for (auto p : updatePacket->objectUpdates) { |
| 120 | auto object = getObject(p.first); |
| 121 | object->readNetState(p.second, SystemWorldTimestep); |
| 122 | } |
| 123 | |
| 124 | } else if (auto createPacket = as<SystemObjectCreatePacket>(packet)) { |
| 125 | auto object = netLoadObject(createPacket->objectStore); |
| 126 | m_objects.set(object->uuid(), object); |
| 127 | |
| 128 | } else if (auto destroyPacket = as<SystemObjectDestroyPacket>(packet)) { |
| 129 | m_objects.remove(destroyPacket->objectUuid); |
| 130 | m_universeMap->removeMappedObject(CelestialCoordinate(m_location), destroyPacket->objectUuid); |
| 131 | |
| 132 | } else if (auto shipCreatePacket = as<SystemShipCreatePacket>(packet)) { |
| 133 | auto ship = netLoadShip(shipCreatePacket->shipStore); |
| 134 | m_clientShips.set(ship->uuid(), ship); |
| 135 | |
| 136 | } else if (auto shipDestroyPacket = as<SystemShipDestroyPacket>(packet)) { |
| 137 | m_clientShips.remove(shipDestroyPacket->shipUuid); |
| 138 | |
| 139 | } else if (auto startPacket = as<SystemWorldStartPacket>(packet)) { |
| 140 | m_objects.clear(); |
| 141 | m_clientShips.clear(); |
| 142 | m_location = startPacket->location; |
| 143 | for (auto netStore: startPacket->objectStores) { |
| 144 | auto object = netLoadObject(netStore); |
| 145 | m_objects.set(object->uuid(), object); |
| 146 | } |
| 147 | for (auto netStore : startPacket->shipStores) { |
| 148 | auto ship = netLoadShip(netStore); |
| 149 | m_clientShips.set(ship->uuid(), ship); |
| 150 | } |
| 151 | m_ship = make_shared<SystemClientShip>(this, startPacket->clientShip.first, startPacket->clientShip.second); |
| 152 | |
| 153 | m_universeMap->addMappedCoordinate(CelestialCoordinate(m_location)); |
| 154 | m_universeMap->filterMappedObjects(CelestialCoordinate(m_location), m_objects.keys()); |
| 155 | } else { |
| 156 | // packet type not handled by system world client |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | // packet was handled |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | List<PacketPtr> SystemWorldClient::pullOutgoingPackets() { |
| 165 | return take(m_outgoingPackets); |
no test coverage detected