//-------------------------------------------------------- //-------------------------------------------------------- void TapGesture::OnPointerUp(const Pointer& in_pointer, f64 in_timestamp, Pointer::InputType in_inputType) { CheckForExpiration(in_timestamp); if (in_inputType == m_requiredInputType && m_tapPending == true) { if (m_pendingPointers.size() == m_requiredPointerCount) { bool tapFinished = true; for (auto& pointerInfo : m_pendingPointers) { if (in_pointer.GetId() == pointerInfo.m_pointerId) { pointerInfo.m_isDown = false; } else if (pointerInfo.m_isDown == true) { tapFinished = false; } } if (tapFinished == true) { if (m_tapCount == 0) { m_firstTapPendingPointers = m_pendingPointers; } ResetTap(); m_tapCount++; m_lastTapEndTimestamp = in_timestamp; if (m_tapCount == m_requiredTapCount) { Core::Vector2 gesturePosition = Core::Vector2::k_zero; for (auto& pointerInfo : m_firstTapPendingPointers) { gesturePosition += pointerInfo.m_initialPosition; } gesturePosition /= f32(m_firstTapPendingPointers.size()); Reset(); if (ResolveConflicts() == true) { m_tappedEvent.NotifyConnections(this, gesturePosition); } } } } else { ResetTap(); } } }
/* * Save Snapshot */ void Engine::SaveSnapshot() { EnableUI(false); std::string fileName; if (current_snapshot_.Valid() == false) { fileName = GenerateSaveFileName(); LOGI("Creating new snapshot %s", fileName.c_str()); } else { fileName = current_snapshot_.FileName(); } service_->Snapshots().Open( fileName, gpg::SnapshotConflictPolicy::MANUAL, [this](gpg::SnapshotManager::OpenResponse const & response) { LOGI("Opened file"); if (IsSuccess(response.status)) { gpg::SnapshotMetadata metadata = response.data; if (response.conflict_id != "") { //Conflict detected LOGI("Snapshot conflict detected going to resolve that"); bool b = ResolveConflicts(response, 0); if (!b) { LOGI("Failed resolving conflicts"); EnableUI(true); return; } } //Create image to represent the snapshot //Reading png from asset for now std::vector<uint8_t> pngData; if (!ndk_helper::JNIHelper::GetInstance()->ReadFile("gps.png", &pngData)) { LOGI("Can not open a file:%s", "gps.png"); EnableUI(true); return; } gpg::SnapshotMetadataChange::Builder builder; gpg::SnapshotMetadataChange metadata_change = builder.SetDescription("CollectAllTheStar savedata ") .SetCoverImageFromPngData(pngData).Create(); // Save the snapshot. gpg::SnapshotManager::CommitResponse commitResponse = service_->Snapshots() .CommitBlocking(metadata, metadata_change, SetupSnapshotData()); if (IsSuccess(commitResponse.status)) { LOGI("Saved game"); } else { LOGI("Saved game failed error: %d", commitResponse.status); } } EnableUI(true); }); }
/* * Load snapshot data */ void Engine::LoadFromSnapshot() { if (!current_snapshot_.Valid()) { LOGI("Snapshot is not valid!"); EnableUI(true); return; } LOGI("Opening file"); service_->Snapshots() .Open(current_snapshot_.FileName(), gpg::SnapshotConflictPolicy::MANUAL, [this](gpg::SnapshotManager::OpenResponse const & response) { LOGI("Opened file"); if (IsSuccess(response.status)) { //Do need conflict resolution? if (response.data.Valid() == false) { if (response.conflict_id != "") { LOGI("Need conflict resolution"); bool b = ResolveConflicts(response, 0); if (!b) { LOGI("Failed resolving conflicts"); EnableUI(true); return; } } else { EnableUI(true); return; } } LOGI("Reading file"); gpg::SnapshotManager::ReadResponse responseRead = service_->Snapshots().ReadBlocking(response.data); if (IsSuccess(responseRead.status)) { LOGI("Parsing data"); ParseSnapshotData(responseRead.data); ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this]() { UpdateGameUI(); }); } } EnableUI(true); }); }
void CInstantSend::TryToFinalizeLockCandidate(const CTxLockCandidate& txLockCandidate) { if(!sporkManager.IsSporkActive(SPORK_2_INSTANTSEND_ENABLED)) return; LOCK(cs_main); #ifdef ENABLE_WALLET if (pwalletMain) LOCK(pwalletMain->cs_wallet); #endif LOCK(cs_instantsend); uint256 txHash = txLockCandidate.txLockRequest.tx->GetHash(); if(txLockCandidate.IsAllOutPointsReady() && !IsLockedInstantSendTransaction(txHash)) { // we have enough votes now LogPrint("instantsend", "CInstantSend::TryToFinalizeLockCandidate -- Transaction Lock is ready to complete, txid=%s\n", txHash.ToString()); if(ResolveConflicts(txLockCandidate)) { LockTransactionInputs(txLockCandidate); UpdateLockedTransaction(txLockCandidate); } } }
bool Engine::ResolveConflicts(gpg::SnapshotManager::OpenResponse const &openResponse, const int32_t retry) { if (openResponse.conflict_id == "") { LOGI("No conflict detected"); return true; } // // Note: Expecting ResolveConflicts() is called within callback, we are using // blocking read here // gpg::SnapshotManager &manager = service_->Snapshots(); gpg::SnapshotManager::OpenResponse responseBase = manager.OpenBlocking(openResponse.conflict_base.FileName(), gpg::SnapshotConflictPolicy::MANUAL); gpg::SnapshotManager::ReadResponse responseReadBase = manager.ReadBlocking(responseBase.data); ParseSnapshotData(responseReadBase.data); // Temporary store data, int32_t temp_scores[NUM_GAME_WORLD][NUM_GAME_STAGES]; //960 bytes for (int32_t i = 0; i < NUM_GAME_WORLD; ++i) for (int32_t j = 0; j < NUM_GAME_STAGES; ++j) { temp_scores[i][j] = scores_[i][j]; } gpg::SnapshotManager::OpenResponse responseRemote = manager.OpenBlocking(openResponse.conflict_remote.FileName(), gpg::SnapshotConflictPolicy::MANUAL); gpg::SnapshotManager::ReadResponse responseReadRemote = manager.ReadBlocking(responseRemote.data); ParseSnapshotData(responseReadRemote.data); // Merging them for (int32_t i = 0; i < NUM_GAME_WORLD; ++i) for (int32_t j = 0; j < NUM_GAME_STAGES; ++j) { if (temp_scores[i][j] > scores_[i][j]) scores_[i][j] = temp_scores[i][j]; } //Create image to represent the snapshot //Reading png from asset for now std::vector<uint8_t> pngData; if (!ndk_helper::JNIHelper::GetInstance()->ReadFile("gps.png", &pngData)) { LOGI("Can not open a file:%s", "gps.png"); return false; } gpg::SnapshotMetadataChange::Builder builder; gpg::SnapshotMetadataChange metadata_change = builder.SetDescription("CollectAllTheStar savedata ") .SetCoverImageFromPngData(pngData).Create(); //Resolve conflict gpg::SnapshotManager::CommitResponse commitResponse = manager.ResolveConflictBlocking(openResponse.data, metadata_change, openResponse.conflict_id); if (IsSuccess(commitResponse.status)) { LOGI("Conflict resolution succeeded"); } else { LOGI("Conflict resolution failed error: %d", commitResponse.status); } //Try to re-open, gpg::SnapshotManager::OpenResponse retryResponse = manager.OpenBlocking(current_snapshot_.FileName(), gpg::SnapshotConflictPolicy::MANUAL); if (IsSuccess(retryResponse.status)) { if (retryResponse.conflict_id != "") { if (retry > MAX_RETRY) return false; LOGI("Need conflict resolution again.."); return ResolveConflicts(retryResponse, retry + 1); } } SaveSnapshot(); //Currently, we need to save data again. //We will have convenient API to resolve conflicts and save data //In upcoming release return true; }