void FieldCutscene::UpdateCharacters(int delta, vector<HeightMap *> *pHeightMapList) { vector<PositionalSound> soundsToPlayList; if (GetIsFinished() || (pCurrentPhase != NULL && pCurrentPhase->GetAllowsCharacterUpdates())) { for (map<string, FieldCharacter *>::iterator iter = idToCharacterMap.begin(); iter != idToCharacterMap.end(); ++iter) { iter->second->UpdateAnimation(delta); iter->second->SetExtraHeightFromHeightMaps(pHeightMapList); AnimationSound *pSoundToPlay = iter->second->GetSoundToPlay(); if (pSoundToPlay != NULL) { soundsToPlayList.push_back(PositionalSound(pSoundToPlay, iter->second->GetMidPoint())); } } } for (unsigned int i = 0; i < soundsToPlayList.size(); i++) { AnimationSound *pSoundToPlay = soundsToPlayList[i].pSound; Vector2 soundOriginPosition = soundsToPlayList[i].location; double distanceToOrigin = (soundOriginPosition - currentCameraPosition).Length(); double zeroDistance = max(gScreenWidth, gScreenHeight);//sqrt(gScreenWidth * gScreenWidth + gScreenHeight * gScreenHeight); double volume = max(0.0, 1.0 - distanceToOrigin / zeroDistance); pSoundToPlay->Play(volume); } }
void FieldCutscene::FieldCutsceneOrient::Update(int delta) { if (!GetIsFinished()) { pCharacter->SetDirection(direction); pCharacter->SetSpriteDirection(spriteDirection); SetIsFinished(true); } }
void TransferItem::UpdateStats( ) { if(m_type != TRANSFERTYPE_CHAT_UPLOAD && // when uploading we set the size ourself with SetLoadedSize and SetCompleteSize m_type != TRANSFERTYPE_PEER2PEER_DOWNLOAD) { m_size = 0; m_url->GetAttribute(URL::KContentSize, &m_size); // Don't poll something that is done. BOOL update_loaded = FALSE; if (GetIsFinished()) update_loaded = (m_loaded < m_size); // m_loaded might not necessarily be updated even if we're finished. else { if (m_type != TRANSFERTYPE_CHAT_DOWNLOAD) update_loaded = HeaderLoaded(); else update_loaded = TRUE; } if (update_loaded) { m_url->GetAttribute(URL::KContentLoaded_Update, &m_loaded); } } double timer = m_timer.Get(); if(m_calc_cps) { if(m_lastLoaded > m_loaded) { m_lastLoaded = 0; m_loaded = 0; } AddPoint(timer, (m_loaded - m_lastLoaded)); m_kibs = AverageSpeed(); OP_ASSERT(m_kibs >= 0); if(m_kibs < 0) { m_kibs = 0; } if(m_kibs != 0) { m_timeLeft = (int)((m_size - m_loaded) / m_kibs); // kibs is actually bps here. } m_kibs /= 1024.0; } AddPointUpload(timer, (m_uploaded - m_lastUploaded)); m_kibsUpload = AverageSpeedUpload(); m_kibsUpload /= 1024.0; if(m_loaded > 0) { m_calc_cps = TRUE; } NotifyListener(); }
void FieldCutscene::UpdatePhase(int delta) { if (GetIsFinished()) { return; } if (pCurrentPhase == NULL || pCurrentPhase->GetIsFinished()) { StartNextPhase(); if (GetIsFinished()) { return; } } pCurrentPhase->Update(delta); }
void FieldCutscene::Draw(Vector2 offsetVector, list<ZOrderableObject *> *pObjectsFromLocation) { if (pBackgroundSprite == NULL || backgroundSpriteOpacity < 1) { list<ZOrderableObject *> objectsInZOrder; for (list<ZOrderableObject *>::iterator iter = pObjectsFromLocation->begin(); iter != pObjectsFromLocation->end(); ++iter) { objectsInZOrder.push_back(*iter); } for (map<string, FieldCharacter *>::iterator iter = idToCharacterMap.begin(); iter != idToCharacterMap.end(); ++iter) { objectsInZOrder.push_back(iter->second); } objectsInZOrder.sort(CompareByZOrder); for (list<ZOrderableObject *>::iterator iter = objectsInZOrder.begin(); iter != objectsInZOrder.end(); ++iter) { (*iter)->Draw(offsetVector); } } if (pBackgroundSprite != NULL) { pBackgroundSprite->Draw(Vector2(0, 0), Color(backgroundSpriteOpacity, 1.0, 1.0, 1.0)); } if (pReplacementBackgroundSprite != NULL) { pReplacementBackgroundSprite->Draw(Vector2(0, 0), Color(replacementBackgroundSpriteOpacity, 1.0, 1.0, 1.0)); } if (GetIsFinished()) { return; } if (pCurrentPhase != NULL) { pCurrentPhase->Draw(); } }
void TransitionFade::OnUpdate() { float cp = 0.0f; float cn = 0.0f; if (time < fadeoutDuration) { cp = 1.0f - time / fadeoutDuration; } else if (time <= fadeoutDuration + fadeinDuration) { if (!IsSceneChanged()) { ChangeScene(); } cn = (time - fadeoutDuration) / fadeinDuration; } else { if (!IsSceneChanged()) { ChangeScene(); } if (!GetIsFinished()) { Finish(); } cn = 1.0f; } uint8_t cp_ = Clamp(cp * 255, 255, 0); uint8_t cn_ = Clamp(cn * 255, 255, 0); DrawRectangleWithPreviousScene( Vector2DF(0.0, 0.0), Vector2DF(1.0, 0.0), Vector2DF(1.0, 1.0), Vector2DF(0.0, 1.0), Color(255, 255, 255, cp_), Color(255, 255, 255, cp_), Color(255, 255, 255, cp_), Color(255, 255, 255, cp_), Vector2DF(0.0, 0.0), Vector2DF(1.0, 0.0), Vector2DF(1.0, 1.0), Vector2DF(0.0, 1.0)); DrawRectangleWithNextScene( Vector2DF(0.0, 0.0), Vector2DF(1.0, 0.0), Vector2DF(1.0, 1.0), Vector2DF(0.0, 1.0), Color(255, 255, 255, cn_), Color(255, 255, 255, cn_), Color(255, 255, 255, cn_), Color(255, 255, 255, cn_), Vector2DF(0.0, 0.0), Vector2DF(1.0, 0.0), Vector2DF(1.0, 1.0), Vector2DF(0.0, 1.0)); time += Engine::GetDeltaTime(); }
void Dialog::Update(int delta) { bool newCharacterDrawn = false; double lastCurrentTime = currentTime; currentTime += delta; // If we're now ready to play the dialog, do so. if (timeBeforeDialog >= lastCurrentTime && timeBeforeDialog < currentTime) { if (filePath.length() > 0 && gVoiceVolume > 0 && !GetIsFinished()) { playDialog(filePath); } } if (!dialogEventIteratorSet && !dialogEventList.empty()) { dialogEventIterator = dialogEventList.begin(); pCurrentDialogEvent = *dialogEventIterator; ++dialogEventIterator; dialogEventIteratorSet = true; } if (!GetIsPaused()) { lastPausePosition = -1; if (!GetIsFinished()) { millisecondsSinceLastUpdate += delta; if (!GetIsStarted() || millisecondsSinceLastUpdate > millisecondsPerCharacterUpdate) { int positionsToAdvance = (int)(millisecondsSinceLastUpdate / millisecondsPerCharacterUpdate); try { string::const_iterator begin = GetText().begin() + curTextPosition; string::const_iterator end = begin; utf8::advance(end, positionsToAdvance, GetText().end()); curTextPosition = curTextPosition + distance(begin, end); } catch (utf8::not_enough_room ex) { curTextPosition = (int)GetText().length(); } millisecondsSinceLastUpdate = max(millisecondsSinceLastUpdate - positionsToAdvance * millisecondsPerCharacterUpdate, 0.0); newCharacterDrawn = true; } } } else { millisecondsSinceLastUpdate = 0; millisecondsUntilPauseCompletes -= delta; millisecondsUntilAudioPauseCompletes -= delta; if (millisecondsUntilPauseCompletes < 0) { // Account for going over by adding the amount we went over // to the milliseconds since we updated, // such that we'll update sooner if we went over. millisecondsSinceLastUpdate += -millisecondsUntilPauseCompletes; millisecondsUntilPauseCompletes = 0; } if (millisecondsUntilAudioPauseCompletes < 0) { millisecondsUntilAudioPauseCompletes = 0; } } if (!GetIsPaused() && pCurrentDialogEvent != NULL) { while (curTextPosition >= pCurrentDialogEvent->GetPosition()) { int eventPosition = pCurrentDialogEvent->GetPosition(); pCurrentDialogEvent->RaiseEvent(); if (dialogEventIterator != dialogEventList.end()) { pCurrentDialogEvent = *dialogEventIterator; ++dialogEventIterator; } else { pCurrentDialogEvent = NULL; } if (GetIsPaused() || pCurrentDialogEvent == NULL) { if (GetIsPaused()) { lastPausePosition = eventPosition; } break; } } } // We'll only play the letter blips if voice acting isn't enabled. if (gVoiceVolume <= 0 && !GetIsReadyToProgress()) { timeSinceLetterBlipPlayed += delta; if (newCharacterDrawn && timeSinceLetterBlipPlayed > 50)// TODO letterBlipSoundEffect.Duration.TotalMilliseconds) { playSound(LetterBlipSoundEffect); timeSinceLetterBlipPlayed = 0; } } if (GetIsReadyToProgress()) { if (presentEvidenceAutomatically && !pEvidenceSelector->GetIsShowing()) { if (!evidenceSelectorShownOnce) { pEvidenceSelector->Show(); evidenceSelectorShownOnce = true; Confrontation *pConfrontation = pState->GetCurrentConfrontation(); if (pConfrontation != NULL) { pConfrontation->HideHealthIcons(); } } else { if (!evidencePresented) { // If the evidence selector isn't showing and it was shown once, // and if no evidence has been shown, then the player must've // clicked Cancel, so we'll end the conversation here // since progress depends on presenting the right evidence. OnEndRequested(); } endRequested = true; } } else if (!presentEvidenceAutomatically) { endRequested = true; } if (isInterrogation) { if (pEvidenceSelector->GetIsShowing()) { pEvidenceSelector->Update(delta); } else if (!pState->WasInterjectionOngoing()) { if (!isPassive) { pPressForInfoTab->Update(); pPresentEvidenceTab->Update(); if (Case::GetInstance()->GetPartnerManager()->GetCurrentPartnerId().length() > 0 && pCurrentPartner->GetConversationAbilityName().length() > 0) { pUsePartnerTab->Update(); } } if (!isConfrontation || Confrontation::GetEnabledConfrontationTopicCount() > 1) { pEndInterrogationTab->Update(); } pInterrogationUpArrow->Update(delta); pInterrogationDownArrow->Update(delta); } } else { if (pEvidenceSelector->GetIsShowing()) { pEvidenceSelector->Update(delta); } else if (!GetIsAutomatic() && !isStatic) { pConversationDownArrow->Update(delta); } } } if (isInterrogation && !pState->WasInterjectionOngoing()) { if (!isPassive) { pPressForInfoTab->SetIsEnabled(GetIsReadyToProgress()); pPresentEvidenceTab->SetIsEnabled(GetIsReadyToProgress() && Case::GetInstance()->GetEvidenceManager()->GetHasEvidence()); if (Case::GetInstance()->GetPartnerManager()->GetCurrentPartnerId().length() > 0 && pCurrentPartner->GetConversationAbilityName().length() > 0) { pUsePartnerTab->SetIsEnabled(GetIsReadyToProgress()); } } if (!isConfrontation || Confrontation::GetEnabledConfrontationTopicCount() > 1) { pEndInterrogationTab->SetIsEnabled(GetIsReadyToProgress()); } } }