int UdpHandler::spawn(Net::Packet &packet, uint64_t) { uint32_t id_packet; if (packet.size() != 29) return 0; packet >> id_packet; this->testPacketId(id_packet); GameCommand *gc = new GameCommand("spawn"); packet >> gc->idResource; packet >> gc->idObject; packet >> gc->x; packet >> gc->y; packet >> gc->vx; packet >> gc->vy; /*if (_latency > 50) { gc->x += (static_cast<double>(_latency) / 1000) * gc->vx; gc->y += (static_cast<double>(_latency) / 1000) * gc->vy; }*/ //std::cout << "spawn de type " << gc->idResource << " x:" << gc->x << " y:" << gc->y << " vx:" << gc->vx << " vy:" << gc->vy << std::endl; CommandDispatcher::get().pushCommand(*gc); return 1; }
int UdpHandler::handleInputPacket(Net::Packet &packet) { static int (UdpHandler::* const methods[])(Net::Packet&, uint64_t) = { &UdpHandler::spawn, &UdpHandler::destroy, &UdpHandler::move, NULL, NULL, &UdpHandler::retrieve, &UdpHandler::ping, &UdpHandler::pong }; uint64_t time; uint8_t type; if (packet.size() < 9) return 0; packet >> time; packet >> type; if (type < sizeof(methods) / sizeof(*methods) && methods[type] != NULL) return (this->*methods[type])(packet, time); return 0; }