bool Hex::HasPendingBattle(const Game& game) const { if (IsOwned() && HasForeignShip(m_colour) && HasPopulation()) return true; if (m_fleets.size() < 2) return false; if (m_fleets.size() == 2) if (HasShip(Colour::None, ShipType::Ancient)) if (Race(game.GetTeam(m_fleets.back().GetColour()).GetRace()).IsAncientsAlly()) return false; return true; }
//========================================================================== // // // //========================================================================== void ADynamicLight::Tick() { if (vid_renderer == 0) { return; } if (IsOwned()) { if (!target || !target->state) { this->Destroy(); return; } if (target->flags & MF_UNMORPHED) return; } // Don't bother if the light won't be shown if (!IsActive()) return; // I am doing this with a type field so that I can dynamically alter the type of light // without having to create or maintain multiple objects. switch(lighttype) { case PulseLight: { float diff = (level.maptime - m_lastUpdate) / (float)TICRATE; m_lastUpdate = level.maptime; m_cycler.Update(diff); m_currentIntensity = m_cycler.GetVal(); break; } case FlickerLight: { BYTE rnd = randLight(); float pct = ANGLE_TO_FLOAT(angle)/360.f; m_currentIntensity = float(m_intensity[rnd >= pct * 255]); break; } case RandomFlickerLight: { int flickerRange = m_intensity[1] - m_intensity[0]; float amt = randLight() / 255.f; m_tickCount++; if (m_tickCount > ANGLE_TO_FLOAT(angle)) { m_currentIntensity = float(m_intensity[0] + (amt * flickerRange)); m_tickCount = 0; } break; } #if 0 // These need some more work elsewhere case ColorFlickerLight: { BYTE rnd = randLight(); float pct = ANGLE_TO_FLOAT(angle)/360.f; m_currentIntensity = m_intensity[rnd >= pct * 255]; break; } case RandomColorFlickerLight: { int flickerRange = m_intensity[1] - m_intensity[0]; float amt = randLight() / 255.f; m_tickCount++; if (m_tickCount > ANGLE_TO_FLOAT(angle)) { m_currentIntensity = m_intensity[0] + (amt * flickerRange); m_tickCount = 0; } break; } #endif case SectorLight: { float intensity; float scale = args[LIGHT_SCALE] / 8.f; if (scale == 0.f) scale = 1.f; intensity = Sector->lightlevel * scale; intensity = clamp<float>(intensity, 0.f, 255.f); m_currentIntensity = intensity; break; } case PointLight: m_currentIntensity = float(m_intensity[0]); break; } UpdateLocation(); }
bool TimestampOrderingTransactionManager::PerformRead( TransactionContext *const current_txn, const ItemPointer &read_location, bool acquire_ownership) { ItemPointer location = read_location; ////////////////////////////////////////////////////////// //// handle READ_ONLY ////////////////////////////////////////////////////////// if (current_txn->GetIsolationLevel() == IsolationLevelType::READ_ONLY) { // do not update read set for read-only transactions. return true; } // end READ ONLY ////////////////////////////////////////////////////////// //// handle SNAPSHOT ////////////////////////////////////////////////////////// // TODO: what if we want to read a version that we write? else if (current_txn->GetIsolationLevel() == IsolationLevelType::SNAPSHOT) { oid_t tile_group_id = location.block; oid_t tuple_id = location.offset; LOG_TRACE("PerformRead (%u, %u)\n", location.block, location.offset); auto &manager = catalog::Manager::GetInstance(); auto tile_group_header = manager.GetTileGroup(tile_group_id)->GetHeader(); // Check if it's select for update before we check the ownership // and modify the last reader cid if (acquire_ownership == true) { // get the latest version of this tuple. location = *(tile_group_header->GetIndirection(location.offset)); tile_group_id = location.block; tuple_id = location.offset; tile_group_header = manager.GetTileGroup(tile_group_id)->GetHeader(); if (IsOwner(current_txn, tile_group_header, tuple_id) == false) { // Acquire ownership if we haven't if (IsOwnable(current_txn, tile_group_header, tuple_id) == false) { // Cannot own return false; } if (AcquireOwnership(current_txn, tile_group_header, tuple_id) == false) { // Cannot acquire ownership return false; } // Record RWType::READ_OWN current_txn->RecordReadOwn(location); } // if we have already owned the version. PL_ASSERT(IsOwner(current_txn, tile_group_header, tuple_id) == true); // Increment table read op stats if (static_cast<StatsType>(settings::SettingsManager::GetInt(settings::SettingId::stats_mode)) != StatsType::INVALID) { stats::BackendStatsContext::GetInstance()->IncrementTableReads( location.block); } return true; } else { // if it's not select for update, then update read set and return true. current_txn->RecordRead(location); // Increment table read op stats if (static_cast<StatsType>(settings::SettingsManager::GetInt(settings::SettingId::stats_mode)) != StatsType::INVALID) { stats::BackendStatsContext::GetInstance()->IncrementTableReads( location.block); } return true; } } // end SNAPSHOT ////////////////////////////////////////////////////////// //// handle READ_COMMITTED ////////////////////////////////////////////////////////// else if (current_txn->GetIsolationLevel() == IsolationLevelType::READ_COMMITTED) { oid_t tile_group_id = location.block; oid_t tuple_id = location.offset; LOG_TRACE("PerformRead (%u, %u)\n", location.block, location.offset); auto &manager = catalog::Manager::GetInstance(); auto tile_group_header = manager.GetTileGroup(tile_group_id)->GetHeader(); // Check if it's select for update before we check the ownership. if (acquire_ownership == true) { // acquire ownership. if (IsOwner(current_txn, tile_group_header, tuple_id) == false) { // Acquire ownership if we haven't if (IsOwnable(current_txn, tile_group_header, tuple_id) == false) { // Cannot own return false; } if (AcquireOwnership(current_txn, tile_group_header, tuple_id) == false) { // Cannot acquire ownership return false; } // Record RWType::READ_OWN current_txn->RecordReadOwn(location); } // if we have already owned the version. PL_ASSERT(IsOwner(current_txn, tile_group_header, tuple_id) == true); // Increment table read op stats if (static_cast<StatsType>(settings::SettingsManager::GetInt(settings::SettingId::stats_mode)) != StatsType::INVALID) { stats::BackendStatsContext::GetInstance()->IncrementTableReads( location.block); } return true; } else { // a transaction can never read an uncommitted version. if (IsOwner(current_txn, tile_group_header, tuple_id) == false) { if (IsOwned(current_txn, tile_group_header, tuple_id) == false) { current_txn->RecordRead(location); // Increment table read op stats if (static_cast<StatsType>(settings::SettingsManager::GetInt(settings::SettingId::stats_mode)) != StatsType::INVALID) { stats::BackendStatsContext::GetInstance()->IncrementTableReads( location.block); } return true; } else { // if the tuple has been owned by some concurrent transactions, // then read fails. LOG_TRACE("Transaction read failed"); return false; } } else { // this version must already be in the read/write set. // so no need to update read set. // current_txn->RecordRead(location); // Increment table read op stats if (static_cast<StatsType>(settings::SettingsManager::GetInt(settings::SettingId::stats_mode)) != StatsType::INVALID) { stats::BackendStatsContext::GetInstance()->IncrementTableReads( location.block); } return true; } } } // end READ_COMMITTED ////////////////////////////////////////////////////////// //// handle SERIALIZABLE and REPEATABLE_READS ////////////////////////////////////////////////////////// else { PL_ASSERT(current_txn->GetIsolationLevel() == IsolationLevelType::SERIALIZABLE || current_txn->GetIsolationLevel() == IsolationLevelType::REPEATABLE_READS); oid_t tile_group_id = location.block; oid_t tuple_id = location.offset; LOG_TRACE("PerformRead (%u, %u)\n", location.block, location.offset); auto &manager = catalog::Manager::GetInstance(); auto tile_group_header = manager.GetTileGroup(tile_group_id)->GetHeader(); // Check if it's select for update before we check the ownership // and modify the last reader cid. if (acquire_ownership == true) { // acquire ownership. if (IsOwner(current_txn, tile_group_header, tuple_id) == false) { // Acquire ownership if we haven't if (IsOwnable(current_txn, tile_group_header, tuple_id) == false) { // Cannot own return false; } if (AcquireOwnership(current_txn, tile_group_header, tuple_id) == false) { // Cannot acquire ownership return false; } // Record RWType::READ_OWN current_txn->RecordReadOwn(location); // now we have already obtained the ownership. // then attempt to set last reader cid. UNUSED_ATTRIBUTE bool ret = SetLastReaderCommitId( tile_group_header, tuple_id, current_txn->GetCommitId(), true); PL_ASSERT(ret == true); // there's no need to maintain read set for timestamp ordering protocol. // T/O does not check the read set during commit phase. } // if we have already owned the version. PL_ASSERT(IsOwner(current_txn, tile_group_header, tuple_id) == true); PL_ASSERT(GetLastReaderCommitId(tile_group_header, tuple_id) == current_txn->GetCommitId() || GetLastReaderCommitId(tile_group_header, tuple_id) == 0); // Increment table read op stats if (static_cast<StatsType>(settings::SettingsManager::GetInt(settings::SettingId::stats_mode)) != StatsType::INVALID) { stats::BackendStatsContext::GetInstance()->IncrementTableReads( location.block); } return true; } else { if (IsOwner(current_txn, tile_group_header, tuple_id) == false) { // if the current transaction does not own this tuple, // then attempt to set last reader cid. if (SetLastReaderCommitId(tile_group_header, tuple_id, current_txn->GetCommitId(), false) == true) { // update read set. current_txn->RecordRead(location); // Increment table read op stats if (static_cast<StatsType>(settings::SettingsManager::GetInt(settings::SettingId::stats_mode)) != StatsType::INVALID) { stats::BackendStatsContext::GetInstance()->IncrementTableReads( location.block); } return true; } else { // if the tuple has been owned by some concurrent transactions, // then read fails. LOG_TRACE("Transaction read failed"); return false; } } else { // if the current transaction has already owned this tuple, // then perform read directly. PL_ASSERT(GetLastReaderCommitId(tile_group_header, tuple_id) == current_txn->GetCommitId() || GetLastReaderCommitId(tile_group_header, tuple_id) == 0); // this version must already be in the read/write set. // so no need to update read set. // current_txn->RecordRead(location); // Increment table read op stats if (static_cast<StatsType>(settings::SettingsManager::GetInt(settings::SettingId::stats_mode)) != StatsType::INVALID) { stats::BackendStatsContext::GetInstance()->IncrementTableReads( location.block); } return true; } } } // end SERIALIZABLE || REPEATABLE_READS }