Esempio n. 1
0
File: Main.cpp Progetto: leod/game
    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
        }
    }
Esempio n. 2
0
File: Main.cpp Progetto: leod/game
 void onPing(ClientId clientId) {
     sendEvent<Pong>(clients.get(clientId)->peer);
 }
Esempio n. 3
0
File: Main.cpp Progetto: leod/game
 void onDisconnectWish(ClientId clientId) {
     handleDisconnect(clients.get(clientId));
 }