void IngameState::handleEvent(const SDL_Event& event) { auto player = game->getPlayer(); switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_ESCAPE: StateManager::get().enter(new PauseState(game)); break; case SDLK_m: StateManager::get().enter(new DebugState(game, _look.position, _look.rotation)); break; case SDLK_SPACE: if( getWorld()->state->currentCutscene ) { getWorld()->state->skipCutscene = true; } break; case SDLK_c: camMode = CameraMode((camMode+(CameraMode)1)%CAMERA_MAX); break; case SDLK_w: _movement.x = 1.f; break; case SDLK_s: _movement.x =-1.f; break; case SDLK_a: _movement.y = 1.f; break; case SDLK_d: _movement.y =-1.f; break; default: break; } break; case SDL_KEYUP: switch(event.key.keysym.sym) { case SDLK_w: case SDLK_s: _movement.x = 0.f; break; case SDLK_a: case SDLK_d: _movement.y = 0.f; break; default: break; } break; default: break; } if( player && player->isInputEnabled() ) { handlePlayerInput(event); } State::handleEvent(event); }
void MidiPort::processInEvent( const MidiEvent& event, const MidiTime& time ) { // mask event if( isInputEnabled() && ( inputChannel() == 0 || inputChannel()-1 == event.channel() ) ) { MidiEvent inEvent = event; if( event.type() == MidiNoteOn || event.type() == MidiNoteOff || event.type() == MidiKeyPressure ) { if( inEvent.key() < 0 || inEvent.key() >= NumKeys ) { return; } } if( fixedInputVelocity() >= 0 && inEvent.velocity() > 0 ) { inEvent.setVelocity( fixedInputVelocity() ); } m_midiEventProcessor->processInEvent( inEvent, time ); } }
void IngameState::handleEvent(const sf::Event &event) { auto player = game->getPlayer(); switch(event.type) { case sf::Event::KeyPressed: switch(event.key.code) { case sf::Keyboard::Escape: StateManager::get().enter(new PauseState(game)); break; case sf::Keyboard::M: StateManager::get().enter(new DebugState(game, _look.position, _look.rotation)); break; case sf::Keyboard::Space: if( getWorld()->state->currentCutscene ) { getWorld()->state->skipCutscene = true; } break; case sf::Keyboard::C: camMode = CameraMode((camMode+(CameraMode)1)%CAMERA_MAX); break; case sf::Keyboard::W: _movement.x = 1.f; break; case sf::Keyboard::S: _movement.x =-1.f; break; case sf::Keyboard::A: _movement.y = 1.f; break; case sf::Keyboard::D: _movement.y =-1.f; break; default: break; } break; case sf::Event::KeyReleased: switch(event.key.code) { case sf::Keyboard::W: case sf::Keyboard::S: _movement.x = 0.f; break; case sf::Keyboard::A: case sf::Keyboard::D: _movement.y = 0.f; break; default: break; } break; default: break; } if( player && player->isInputEnabled() ) { handlePlayerInput(event); } State::handleEvent(event); }
void MidiPort::subscribeReadablePort( const QString& port, bool subscribe ) { m_readablePorts[port] = subscribe; // make sure, MIDI-port is configured for input if( subscribe == true && !isInputEnabled() ) { m_readableModel.setValue( true ); } m_midiClient->subscribeReadablePort( this, port, subscribe ); }
void MidiPort::saveSettings( QDomDocument& doc, QDomElement& thisElement ) { m_inputChannelModel.saveSettings( doc, thisElement, "inputchannel" ); m_outputChannelModel.saveSettings( doc, thisElement, "outputchannel" ); m_inputControllerModel.saveSettings( doc, thisElement, "inputcontroller" ); m_outputControllerModel.saveSettings( doc, thisElement, "outputcontroller" ); m_fixedInputVelocityModel.saveSettings( doc, thisElement, "fixedinputvelocity" ); m_fixedOutputVelocityModel.saveSettings( doc, thisElement, "fixedoutputvelocity" ); m_fixedOutputNoteModel.saveSettings( doc, thisElement, "fixedoutputnote" ); m_outputProgramModel.saveSettings( doc, thisElement, "outputprogram" ); m_baseVelocityModel.saveSettings( doc, thisElement, "basevelocity" ); m_readableModel.saveSettings( doc, thisElement, "readable" ); m_writableModel.saveSettings( doc, thisElement, "writable" ); if( isInputEnabled() ) { QString rp; for( Map::ConstIterator it = m_readablePorts.begin(); it != m_readablePorts.end(); ++it ) { if( it.value() ) { rp += it.key() + ","; } } // cut off comma if( rp.length() > 0 ) { rp.truncate( rp.length() - 1 ); } thisElement.setAttribute( "inports", rp ); } if( isOutputEnabled() ) { QString wp; for( Map::ConstIterator it = m_writablePorts.begin(); it != m_writablePorts.end(); ++it ) { if( it.value() ) { wp += it.key() + ","; } } // cut off comma if( wp.length() > 0 ) { wp.truncate( wp.length() - 1 ); } thisElement.setAttribute( "outports", wp ); } }
void MidiPort::loadSettings( const QDomElement& thisElement ) { m_inputChannelModel.loadSettings( thisElement, "inputchannel" ); m_outputChannelModel.loadSettings( thisElement, "outputchannel" ); m_inputControllerModel.loadSettings( thisElement, "inputcontroller" ); m_outputControllerModel.loadSettings( thisElement, "outputcontroller" ); m_fixedInputVelocityModel.loadSettings( thisElement, "fixedinputvelocity" ); m_fixedOutputVelocityModel.loadSettings( thisElement, "fixedoutputvelocity" ); m_outputProgramModel.loadSettings( thisElement, "outputprogram" ); m_baseVelocityModel.loadSettings( thisElement, "basevelocity" ); m_readableModel.loadSettings( thisElement, "readable" ); m_writableModel.loadSettings( thisElement, "writable" ); // restore connections if( isInputEnabled() ) { QStringList rp = thisElement.attribute( "inports" ).split( ',' ); for( Map::ConstIterator it = m_readablePorts.begin(); it != m_readablePorts.end(); ++it ) { if( it.value() != ( rp.indexOf( it.key() ) != -1 ) ) { subscribeReadablePort( it.key() ); } } emit readablePortsChanged(); } if( isOutputEnabled() ) { QStringList wp = thisElement.attribute( "outports" ).split( ',' ); for( Map::ConstIterator it = m_writablePorts.begin(); it != m_writablePorts.end(); ++it ) { if( it.value() != ( wp.indexOf( it.key() ) != -1 ) ) { subscribeWritablePort( it.key() ); } } emit writablePortsChanged(); } if( thisElement.hasAttribute( "basevelocity" ) == false ) { // for projects created by LMMS < 0.9.92 there's no value for the base // velocity and for compat reasons we have to stick with maximum velocity // which did not allow note volumes > 100% m_baseVelocityModel.setValue( MidiMaxVelocity ); } }
void MidiPort::updateMidiPortMode() { // this small lookup-table makes everything easier static const Modes modeTable[2][2] = { { Disabled, Output }, { Input, Duplex } } ; setMode( modeTable[m_readableModel.value()][m_writableModel.value()] ); // check whether we have to dis-check items in connection-menu if( !isInputEnabled() ) { for( Map::ConstIterator it = m_readablePorts.begin(); it != m_readablePorts.end(); ++it ) { // subscribed? if( it.value() ) { subscribeReadablePort( it.key(), false ); } } } if( !isOutputEnabled() ) { for( Map::ConstIterator it = m_writablePorts.begin(); it != m_writablePorts.end(); ++it ) { // subscribed? if( it.value() ) { subscribeWritablePort( it.key(), false ); } } } emit readablePortsChanged(); emit writablePortsChanged(); emit modeChanged(); if( Engine::getSong() ) { Engine::getSong()->setModified(); } }
void IngameState::tick(float dt) { autolookTimer = std::max(autolookTimer - dt, 0.f); auto player = game->getPlayer(); if( player && player->isInputEnabled() ) { sf::Vector2f screenSize(getWindow().getSize()); sf::Vector2f screenCenter(screenSize / 2.f); sf::Vector2f mouseMove; if (game->hasFocus()) { sf::Vector2f mousePos(sf::Mouse::getPosition(getWindow())); sf::Vector2f deltaMouse = (mousePos - screenCenter); mouseMove = sf::Vector2f(deltaMouse.x / screenSize.x, deltaMouse.y / screenSize.y); sf::Mouse::setPosition(sf::Vector2i(screenCenter), getWindow()); if(deltaMouse.x != 0 || deltaMouse.y != 0) { autolookTimer = kAutoLookTime; if (!m_invertedY) { mouseMove.y = -mouseMove.y; } m_cameraAngles += glm::vec2(mouseMove.x, mouseMove.y); m_cameraAngles.y = glm::clamp(m_cameraAngles.y, kCameraPitchLimit, glm::pi<float>() - kCameraPitchLimit); } } float viewDistance = 4.f; switch( camMode ) { case IngameState::CAMERA_CLOSE: viewDistance = 2.f; break; case IngameState::CAMERA_NORMAL: viewDistance = 4.0f; break; case IngameState::CAMERA_FAR: viewDistance = 6.f; break; case IngameState::CAMERA_TOPDOWN: viewDistance = 15.f; break; default: viewDistance = 4.f; } auto target = getWorld()->pedestrianPool.find(getWorld()->state->cameraTarget); if( target == nullptr ) { target = player->getCharacter(); } glm::vec3 targetPosition = target->getPosition(); glm::vec3 lookTargetPosition = targetPosition; targetPosition += glm::vec3(0.f, 0.f, 1.f); lookTargetPosition += glm::vec3(0.f, 0.f, 0.5f); btCollisionObject* physTarget = player->getCharacter()->physObject; auto vehicle = ( target->type() == GameObject::Character ) ? static_cast<CharacterObject*>(target)->getCurrentVehicle() : nullptr; if( vehicle ) { auto model = vehicle->model; float maxDist = 0.f; for(auto& g : model->resource->geometries) { float partSize = glm::length(g->geometryBounds.center) + g->geometryBounds.radius; maxDist = std::max(partSize, maxDist); } viewDistance = viewDistance + maxDist; targetPosition = vehicle->getPosition(); lookTargetPosition = targetPosition; lookTargetPosition.z += (vehicle->info->handling.dimensions.z); targetPosition.z += (vehicle->info->handling.dimensions.z * 1.f); physTarget = vehicle->physBody; if (!m_vehicleFreeLook) { m_cameraAngles.y = kVehicleCameraPitch; } // Rotate the camera to the ideal angle if the player isn't moving it float velocity = vehicle->getVelocity(); if (autolookTimer <= 0.f && glm::abs(velocity) > kAutolookMinVelocity) { auto idealYaw = -glm::roll(vehicle->getRotation()) + glm::half_pi<float>(); const auto idealPitch = kVehicleCameraPitch; if (velocity < 0.f) { idealYaw = glm::mod(idealYaw - glm::pi<float>(), glm::pi<float>() * 2.f); } float currentYaw = glm::mod(m_cameraAngles.x, glm::pi<float>()*2); float currentPitch = m_cameraAngles.y; float deltaYaw = idealYaw - currentYaw; float deltaPitch = idealPitch - currentPitch; if (glm::abs(deltaYaw) > glm::pi<float>()) { deltaYaw -= glm::sign(deltaYaw) * glm::pi<float>()*2.f; } m_cameraAngles.x += glm::sign(deltaYaw) * std::min(kMaxRotationRate * dt, glm::abs(deltaYaw)); m_cameraAngles.y += glm::sign(deltaPitch) * std::min(kMaxRotationRate * dt, glm::abs(deltaPitch)); } } // Non-topdown camera can orbit if( camMode != IngameState::CAMERA_TOPDOWN ) { // Determine the "ideal" camera position for the current view angles auto yaw = glm::angleAxis(m_cameraAngles.x, glm::vec3(0.f, 0.f,-1.f)); auto pitch = glm::angleAxis(m_cameraAngles.y, glm::vec3(0.f, 1.f, 0.f)); auto cameraOffset = yaw * pitch * glm::vec3(0.f, 0.f, viewDistance); cameraPosition = targetPosition + cameraOffset; } else { cameraPosition = targetPosition + glm::vec3(0.f, 0.f, viewDistance); } glm::quat angle; auto camtotarget = targetPosition - cameraPosition; auto dir = glm::normalize(camtotarget); float correction = glm::length(camtotarget) - viewDistance; if( correction < 0.f ) { float innerDist = viewDistance * 0.1f; correction = glm::min(0.f, correction + innerDist); } cameraPosition += dir * 10.f * correction * dt; auto lookdir = glm::normalize(lookTargetPosition - cameraPosition); // Calculate the yaw to look at the target. float angleYaw = glm::atan(lookdir.y, lookdir.x); angle = glm::quat( glm::vec3(0.f, 0.f, angleYaw) ); // Update player with camera yaw if( player->isInputEnabled() ) { if (player->getCharacter()->getCurrentVehicle()) { player->setMoveDirection(_movement); } else { float length = glm::length(_movement); float movementAngle = angleYaw - M_PI/2.f; if (length > 0.1f) { glm::vec3 direction = glm::normalize(_movement); movementAngle += atan2(direction.y, direction.x); player->setMoveDirection(glm::vec3(1.f, 0.f, 0.f)); } else { player->setMoveDirection(glm::vec3(0.f)); } if (player->getCharacter()->canTurn()) { player->getCharacter()->rotation = glm::angleAxis(movementAngle, glm::vec3(0.f, 0.f, 1.f)); } } } else { player->setMoveDirection(glm::vec3(0.f)); } float len2d = glm::length(glm::vec2(lookdir)); float anglePitch = glm::atan(lookdir.z, len2d); angle *= glm::quat( glm::vec3(0.f, -anglePitch, 0.f) ); // Use rays to ensure target is visible from cameraPosition auto rayEnd = cameraPosition; auto rayStart = targetPosition; auto to = btVector3(rayEnd.x, rayEnd.y, rayEnd.z); auto from = btVector3(rayStart.x, rayStart.y, rayStart.z); ClosestNotMeRayResultCallback ray(physTarget, from, to); getWorld()->dynamicsWorld->rayTest(from, to, ray); if( ray.hasHit() && ray.m_closestHitFraction < 1.f ) { cameraPosition = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(), ray.m_hitPointWorld.z()); cameraPosition += glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(), ray.m_hitNormalWorld.z()) * 0.1f; } _look.position = cameraPosition; _look.rotation = angle; } }
//------------------------------------------------------------------------------ // publishAndSubscribe() //------------------------------------------------------------------------------ bool NetIO::publishAndSubscribeMunitionDetonation() { RTI::RTIambassador* p = getRTIambassador(); bool ok = true; // ---------- // Get handles to the class, attributes and parameters // ---------- try { // --- // Munition detonation Interaction class handle and parameter handles // --- { RTI::InteractionClassHandle handle = p->getInteractionClassHandle(MunitionDetonation::getInteractionFedName()); setInteractionClassHandle(MUNITION_DETONATION_INTERACTION, handle ); setInteractionParameterHandle( DETONATION_LOCATION_MD_PI, p->getParameterHandle( MunitionDetonation::getDetonationLocationParameterFedName(), handle) ); setInteractionParameterHandle( DETONATION_RESULT_CODE_MD_PI, p->getParameterHandle( MunitionDetonation::getDetonationResultCodeParameterFedName(), handle) ); setInteractionParameterHandle( EVENT_IDENTIFIER_MD_PI, p->getParameterHandle( MunitionDetonation::getEventIdentifierParameterFedName(), handle) ); setInteractionParameterHandle( FIRING_OBJECT_IDENTIFIER_MD_PI, p->getParameterHandle( MunitionDetonation::getFiringObjectIdentifierParameterFedName(), handle) ); setInteractionParameterHandle( FINAL_VELOCITY_VECTOR_MD_PI, p->getParameterHandle( MunitionDetonation::getFinalVelocityVectorParameterFedName(), handle) ); setInteractionParameterHandle( FUSE_TYPE_MD_PI, p->getParameterHandle( MunitionDetonation::getFuseTypeParameterFedName(), handle) ); setInteractionParameterHandle( MUNITION_OBJECT_IDENTIFIER_MD_PI, p->getParameterHandle( MunitionDetonation::getMunitionObjectIdentifierParameterFedName(), handle) ); setInteractionParameterHandle( MUNITION_TYPE_MD_PI, p->getParameterHandle( MunitionDetonation::getMunitionTypeParameterFedName(), handle) ); setInteractionParameterHandle( QUANTITY_FIRED_MD_PI, p->getParameterHandle( MunitionDetonation::getQuantityFiredParameterFedName(), handle) ); setInteractionParameterHandle( RATE_OF_FIRE_MD_PI, p->getParameterHandle( MunitionDetonation::getRateOfFireParameterFedName(), handle) ); setInteractionParameterHandle( RELATIVE_DETONATION_LOCATION_MD_PI, p->getParameterHandle( MunitionDetonation::getRelativeDetonationLocationParameterFedName(), handle) ); setInteractionParameterHandle( TARGET_OBJECT_IDENTIFIER_MD_PI, p->getParameterHandle( MunitionDetonation::getTargetObjectIdentifierParameterFedName(), handle) ); setInteractionParameterHandle( WARHEAD_TYPE_MD_PI, p->getParameterHandle( MunitionDetonation::getWarheadTypeParameterFedName(), handle) ); } } catch( RTI::Exception& e) { std::cerr << &e << std::endl; ok = false; } // ---------- // Publish & Subscribe to class attributes // ---------- if (ok) { try { // --- // Publish these interactions // --- if (isOutputEnabled()) { p->publishInteractionClass(getInteractionClassHandle(MUNITION_DETONATION_INTERACTION)); setInteractionClassPublished(MUNITION_DETONATION_INTERACTION, true); } // --- // Subscribe to these interactions // --- if (isInputEnabled()) { p->subscribeInteractionClass(getInteractionClassHandle(MUNITION_DETONATION_INTERACTION)); setInteractionClassSubscribed(MUNITION_DETONATION_INTERACTION, true); } } catch (RTI::Exception& e) { std::cerr << &e << std::endl; ok = false; } } return ok; }
void APlayerOvi::Tick(float DeltaSeconds){ //get own deltaTime DeltaSeconds = TimeManager::Instance()->GetDeltaTime(DeltaSeconds); Super::Tick(DeltaSeconds); //initilize raycast query param //Initialize TraceParam if (!m_isValid) { //Get ATowardsTheLightGameMode if (!m_gameMode) m_gameMode = Cast<ATowardsTheLightGameMode>(UGameplayStatics::GetGameMode(this)); m_gameMode->FindActualPlayer(); static FName FireTraceIdent = FName(TEXT("Platform")); FCollisionQueryParams TraceParams(FireTraceIdent, true, this); TraceParams.bTraceAsyncScene = true; TraceParams.bFindInitialOverlaps = false; TraceParams.bTraceComplex = true; TArray<AActor *> ignorados; for (TActorIterator<ATappable > ActorItr(GetWorld()); ActorItr; ++ActorItr) { if (ActorItr->ActorHasTag("Tappable")) ignorados.Add(*ActorItr); } for (TActorIterator<ACheckPoint > checkItr(GetWorld()); checkItr; ++checkItr) ignorados.Add(*checkItr); for (TActorIterator<ATutorial > tutItr(GetWorld()); tutItr; ++tutItr) ignorados.Add(*tutItr); if (ignorados.Num() > 0) TraceParams.AddIgnoredActors(ignorados); m_TraceParams = TraceParams; m_isValid = true; } //pause animations if is game paused Mesh->bPauseAnims = isPlayerPaused(); //first tick initialize viewport properties, dont work at begin play if (m_limitViewPort0 == 0 && m_limitViewPort1 == 0) { m_limitViewPort0 = GEngine->GameViewport->Viewport->GetSizeXY().X * 0.45; m_limitViewPort1 = GEngine->GameViewport->Viewport->GetSizeXY().X * 0.55; } //update elapsed time if push button animation is running if (m_isPushingButton) { m_elapsedButton += DeltaSeconds; if (m_elapsedButton >= 1.0f) { m_elapsedButton = 0.0f; m_isPushingButton = false; } } if (m_isPickingPortal) { m_elapsedPortal += DeltaSeconds; float t = 1.0f - (m_elapsedPortal / 1.2f); Mesh->SetRelativeScale3D(FVector(t, t, t)); if (m_elapsedPortal >= 0.6f) { m_elapsedPortal = 0.0f; m_isPickingPortal = false; Mesh->SetRelativeScale3D(FVector(1, 1, 1)); } } if (m_isPickingAltar) { m_elapsedAltar += DeltaSeconds; if (m_elapsedAltar >= 0.7f) { m_elapsedAltar = 0.0f; m_isPickingAltar = false; } } //get last position for this frame. m_lastPosition = GetActorLocation(); float value = 0.0f; if (isInputEnabled()) value = UpdateState(); else{ value = 0; m_doJump = false; } DoMovement(DeltaSeconds, value); if (!m_isPickingPortal) { DoJump(DeltaSeconds); CalculateGravity(DeltaSeconds); } CheckCollision(); CalculateOrientation(); }