void onPlayerInputWish(ClientId clientId, PlayerInput const& playerInput) { auto client = clients.get(clientId); auto entity = client->entity; if (entity) { auto input = entity->component<PlayerInputComponent>(); auto physics = entity->component<PhysicsComponent>(); ASSERT(input); ASSERT(physics); input->onPlayerInput(playerInput); if (playerInput.shoot) { auto origin = physics->getPosition() + physics->getOrientation() * 0.65f; auto orientation = vec3(playerInput.orientation.x, 0, playerInput.orientation.y); auto components = makeProjectile(netSystem.makeNetEntityId(), clientId, origin, orientation); entities.create(std::move(components)); } #ifdef USE_PREDICTION vec3 newPosition = physics->getPosition(); sendEvent<PlayerPositionOrder>(client->peer, newPosition); #endif } }
void onPing(ClientId clientId) { sendEvent<Pong>(clients.get(clientId)->peer); }
void onDisconnectWish(ClientId clientId) { handleDisconnect(clients.get(clientId)); }