本文整理汇总了C++中log::Logger类的典型用法代码示例。如果您正苦于以下问题:C++ Logger类的具体用法?C++ Logger怎么用?C++ Logger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ScaleDamageAccounts
// TODO: Move credits array to HealthComponent.
void HealthComponent::ScaleDamageAccounts(float healthRestored) {
if (healthRestored <= 0.0f) return;
// Get total damage account and remember relevant clients.
float totalAccreditedDamage = 0.0f;
std::vector<Entity*> relevantClients;
ForEntities<ClientComponent>([&](Entity& other, ClientComponent& client) {
float clientDamage = entity.oldEnt->credits[other.oldEnt->s.number].value;
if (clientDamage > 0.0f) {
totalAccreditedDamage += clientDamage;
relevantClients.push_back(&other);
}
});
if (relevantClients.empty()) return;
// Calculate account scale factor.
float scale;
if (healthRestored < totalAccreditedDamage) {
scale = (totalAccreditedDamage - healthRestored) / totalAccreditedDamage;
healthLogger.Debug("Scaling damage accounts of %i client(s) by %.2f.",
relevantClients.size(), scale);
} else {
// Clear all accounts.
scale = 0.0f;
healthLogger.Debug("Clearing damage accounts of %i client(s).", relevantClients.size());
}
// Scale down or clear damage accounts.
for (Entity* other : relevantClients) {
entity.oldEnt->credits[other->oldEnt->s.number].value *= scale;
}
}
示例2: GetLocationalDamageMod
float ArmorComponent::GetLocationalDamageMod(float angle, float height) {
class_t pcl = (class_t)entity.oldEnt->client->ps.stats[STAT_CLASS];
bool crouching = (entity.oldEnt->client->ps.pm_flags & PMF_DUCKED);
for (int regionNum = 0; regionNum < g_numDamageRegions[pcl]; regionNum++) {
damageRegion_t *region = &g_damageRegions[pcl][regionNum];
// Ignore the non-locational pseudo region.
if (region->nonlocational) continue;
// Crouch state must match.
if (region->crouch != crouching) continue;
// Height must be within given range.
if (height < region->minHeight || height > region->maxHeight) continue;
// Angle must be within given range.
if ((region->minAngle <= region->maxAngle && (angle < region->minAngle || angle > region->maxAngle)) ||
(region->minAngle > region->maxAngle && (angle > region->maxAngle && angle < region->minAngle))) {
continue;
}
armorLogger.Debug("Locational damage modifier of %.2f found for angle %.2f and height %.2f (%s).",
region->modifier, angle, height, region->name);
return region->modifier;
}
armorLogger.Debug("Locational damage modifier for angle %.2f and height %.2f not found.",
angle, height);
return 1.0f;
}
示例3: ConsiderStop
void IgnitableComponent::ConsiderStop(int timeDelta) {
if (!onFire) return;
// Don't stop freshly (re-)ignited fires.
if (igniteTime + MIN_BURN_TIME > level.time) {
fireLogger.Debug("(Re-)Ignited %i ms ago, skipping stop check.", level.time - igniteTime);
return;
}
float burnStopChance = STOP_CHANCE;
// Lower burn stop chance if there are other burning entities nearby.
ForEntities<IgnitableComponent>([&](Entity &other, IgnitableComponent &ignitable){
if (&other == &entity) return;
if (!ignitable.onFire) return;
if (G_Distance(other.oldEnt, entity.oldEnt) > STOP_RADIUS) return;
float frac = G_Distance(entity.oldEnt, other.oldEnt) / STOP_RADIUS;
float mod = frac * 1.0f + (1.0f - frac) * STOP_CHANCE;
burnStopChance *= mod;
});
// Attempt to stop burning.
if (random() < burnStopChance) {
fireLogger.Debug("Stopped burning (chance was %.0f%%)", burnStopChance * 100.0f);
entity.Extinguish(0);
return;
} else {
fireLogger.Debug("Didn't stop burning (chance was %.0f%%)", burnStopChance * 100.0f);
}
}
示例4: ConsiderSpread
void IgnitableComponent::ConsiderSpread(int timeDelta) {
if (!onFire) return;
if (level.time < spreadAt) return;
fireLogger.Notice("Trying to spread.");
ForEntities<IgnitableComponent>([&](Entity &other, IgnitableComponent &ignitable){
if (&other == &entity) return;
// Don't re-ignite.
if (ignitable.onFire) return;
// TODO: Use LocationComponent.
float distance = G_Distance(other.oldEnt, entity.oldEnt);
if (distance > SPREAD_RADIUS) return;
float distanceFrac = distance / SPREAD_RADIUS;
float distanceMod = 1.0f - distanceFrac;
float spreadChance = distanceMod;
if (random() < spreadChance) {
if (G_LineOfSight(entity.oldEnt, other.oldEnt) && other.Ignite(fireStarter)) {
fireLogger.Notice("Ignited a neighbour, chance to do so was %.0f%%.",
spreadChance*100.0f);
}
}
});
// Don't spread again until re-ignited.
spreadAt = INT_MAX;
}
示例5: HandleIgnite
void IgnitableComponent::HandleIgnite(gentity_t* fireStarter) {
if (!fireStarter) {
// TODO: Find out why this happens.
fireLogger.Notice("Received ignite message with no fire starter.");
}
if (level.time < immuneUntil) {
fireLogger.Debug("Not ignited: Immune against fire.");
return;
}
// Refresh ignite time even if already burning.
igniteTime = level.time;
if (!onFire) {
onFire = true;
this->fireStarter = fireStarter;
fireLogger.Debug("Ignited.");
} else {
if (alwaysOnFire && !this->fireStarter) {
// HACK: Igniting an alwaysOnFire entity will initialize the fire starter.
this->fireStarter = fireStarter;
fireLogger.Debug("Firestarter initialized.");
} else {
fireLogger.Debug("Re-Ignited.");
}
}
}
示例6: TargetValid
bool TurretComponent::TargetValid(Entity& target, bool newTarget) {
if (!target.Get<ClientComponent>() ||
target.Get<SpectatorComponent>() ||
Entities::IsDead(target) ||
(target.oldEnt->flags & FL_NOTARGET) ||
!Entities::OnOpposingTeams(entity, target) ||
G_Distance(entity.oldEnt, target.oldEnt) > range ||
!trap_InPVS(entity.oldEnt->s.origin, target.oldEnt->s.origin)) {
if (!newTarget) {
turretLogger.Verbose("Target lost: Out of range or eliminated.");
}
return false;
}
// New targets require a line of sight.
if (G_LineOfFire(entity.oldEnt, target.oldEnt)) {
lastLineOfSightToTarget = level.time;
} else if (newTarget) {
return false;
}
// Give up on an existing target if there was no line of sight for a while.
if (lastLineOfSightToTarget + GIVEUP_TARGET_TIME <= level.time) {
turretLogger.Verbose("Giving up on target: No line of sight for %d ms.",
level.time - lastLineOfSightToTarget
);
return false;
}
return true;
}
示例7: ConsiderStop
void IgnitableComponent::ConsiderStop(int timeDelta) {
if (!onFire) return;
// Don't stop freshly (re-)ignited fires.
if (igniteTime + MIN_BURN_TIME > level.time) {
fireLogger.DoDebugCode([&]{
int elapsed = level.time - igniteTime;
int remaining = MIN_BURN_TIME - elapsed;
fireLogger.Debug("Burning for %.1fs, skipping stop check for another %.1fs.",
(float)elapsed/1000.0f, (float)remaining/1000.0f);
});
return;
}
float averagePostMinBurnTime = BASE_AVERAGE_BURN_TIME - MIN_BURN_TIME;
// Increase average burn time dynamically for burning entities in range.
ForEntities<IgnitableComponent>([&](Entity &other, IgnitableComponent &ignitable){
if (&other == &entity) return;
if (!ignitable.onFire) return;
// TODO: Use LocationComponent.
float distance = G_Distance(other.oldEnt, entity.oldEnt);
if (distance > EXTRA_BURN_TIME_RADIUS) return;
float distanceFrac = distance / EXTRA_BURN_TIME_RADIUS;
float distanceMod = 1.0f - distanceFrac;
averagePostMinBurnTime += EXTRA_AVERAGE_BURN_TIME * distanceMod;
});
// The burn stop chance follows an exponential distribution.
float lambda = 1.0f / averagePostMinBurnTime;
float burnStopChance = 1.0f - std::exp(-1.0f * lambda * (float)timeDelta);
float averageTotalBurnTime = averagePostMinBurnTime + (float)MIN_BURN_TIME;
// Attempt to stop burning.
if (random() < burnStopChance) {
fireLogger.Notice("Stopped burning after %.1fs, target average lifetime was %.1fs.",
(float)(level.time - igniteTime) / 1000.0f, averageTotalBurnTime / 1000.0f);
entity.Extinguish(0);
return;
} else {
fireLogger.Debug("Burning for %.1fs, target average lifetime is %.1fs.",
(float)(level.time - igniteTime) / 1000.0f, averageTotalBurnTime / 1000.0f);
}
}
示例8: ResetDirection
void TurretComponent::ResetDirection() {
directionToTarget = baseDirection;
turretLogger.Verbose("Target direction reset. New direction: %s.",
Utility::Print(directionToTarget)
);
}
示例9: HandleDie
void AlienBuildableComponent::HandleDie(gentity_t* killer, meansOfDeath_t meansOfDeath) {
entity.oldEnt->powered = false;
// Warn if in main base and there's an overmind.
gentity_t *om;
if ((om = G_ActiveOvermind()) && om != entity.oldEnt && level.time > om->warnTimer
&& G_InsideBase(entity.oldEnt, true) && G_IsWarnableMOD(meansOfDeath)) {
om->warnTimer = level.time + ATTACKWARN_NEARBY_PERIOD;
G_BroadcastEvent(EV_WARN_ATTACK, 0, TEAM_ALIENS);
Beacon::NewArea(BCT_DEFEND, entity.oldEnt->s.origin, entity.oldEnt->buildableTeam);
}
// Set blast timer.
int blastDelay = 0;
if (entity.oldEnt->spawned && GetBuildableComponent().GetHealthComponent().Health() /
GetBuildableComponent().GetHealthComponent().MaxHealth() > -1.0f) {
blastDelay += GetBlastDelay();
}
alienBuildableLogger.Debug("Alien buildable dies, will blast in %i ms.", blastDelay);
GetBuildableComponent().SetState(BuildableComponent::PRE_BLAST);
GetBuildableComponent().REGISTER_THINKER(Blast, ThinkingComponent::SCHEDULER_BEFORE, blastDelay);
}
示例10: HandleDie
void ResourceStorageComponent::HandleDie(gentity_t* killer, meansOfDeath_t meansOfDeath) {
// TODO: Add TeamComponent and/or Utility::Team.
team_t team = entity.oldEnt->buildableTeam;
float storedFraction = GetStoredFraction();
// Removes some of the owner's team's build points, proportional to the amount this structure
// acquired and the amount of health lost (before deconstruction).
float loss = (1.0f - entity.oldEnt->deconHealthFrac) * storedFraction *
level.team[team].buildPoints * g_buildPointLossFraction.value;
resourceStorageLogger.Notice(
"A resource storage died, removing %.0f BP from the team's pool "
"(%.1f × %.0f%% stored × %.0f%% health lost × %.0f total).",
loss, g_buildPointLossFraction.value, 100.0f * storedFraction,
100.0f * (1.0f - entity.oldEnt->deconHealthFrac), level.team[team].buildPoints
);
G_ModifyBuildPoints(team, -loss);
// Main structures keep their account of acquired build points across lifecycles, it's saved
// in a per-team variable and copied over to the ResourceStorageComponent whenever it's modified.
if (!entity.Get<MainBuildableComponent>()) {
G_ModifyTotalBuildPointsAcquired(team, -acquiredBuildPoints);
}
acquiredBuildPoints = 0.0f;
}
示例11: G_RGSPredictEfficiencyDelta
/**
* @brief Predict the total efficiency gain for a team when a miner is constructed at a given point.
* @return Predicted efficiency delta in percent points.
* @todo Consider RGS set for deconstruction.
*/
float G_RGSPredictEfficiencyDelta(vec3_t origin, team_t team) {
float delta = G_RGSPredictOwnEfficiency(origin);
buildpointLogger.Debug("Predicted efficiency of new miner itself: %f.", delta);
ForEntities<MiningComponent>([&] (Entity& miner, MiningComponent& miningComponent) {
if (G_Team(miner.oldEnt) != team) return;
delta += RGSPredictEfficiencyLoss(miner, origin);
});
buildpointLogger.Debug("Predicted efficiency delta: %f. Build point delta: %f.", delta,
delta * g_buildPointBudgetPerMiner.value);
return delta;
}
示例12: HandleDamage
// TODO: Consider location as well as direction when both given.
void KnockbackComponent::HandleDamage(float amount, gentity_t* source, Util::optional<Vec3> location,
Util::optional<Vec3> direction, int flags, meansOfDeath_t meansOfDeath) {
if (!(flags & DAMAGE_KNOCKBACK)) return;
if (amount <= 0.0f) return;
if (!direction) {
knockbackLogger.Warn("Received damage message with knockback flag set but no direction.");
return;
}
if (Math::Length(direction.value()) == 0.0f) {
knockbackLogger.Warn("Attempt to do knockback with null vector direction.");
return;
}
// TODO: Remove dependency on client.
gclient_t *client = entity.oldEnt->client;
assert(client);
// Check for immunity.
if (client->noclip) return;
if (client->sess.spectatorState != SPECTATOR_NOT) return;
float mass = (float)BG_Class(client->ps.stats[ STAT_CLASS ])->mass;
if (mass <= 0.0f) {
knockbackLogger.Warn("Attempt to do knockback against target with no mass, assuming normal mass.");
mass = KNOCKBACK_NORMAL_MASS;
}
float massMod = Math::Clamp(KNOCKBACK_NORMAL_MASS / mass, KNOCKBACK_MIN_MASSMOD, KNOCKBACK_MAX_MASSMOD);
float strength = amount * DAMAGE_TO_KNOCKBACK * massMod;
// Change client velocity.
Vec3 clientVelocity = Vec3::Load(client->ps.velocity);
clientVelocity += Math::Normalize(direction.value()) * strength;
clientVelocity.Store(client->ps.velocity);
// Set pmove timer so that the client can't cancel out the movement immediately.
if (!client->ps.pm_time) {
client->ps.pm_time = KNOCKBACK_PMOVE_TIME;
client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
}
knockbackLogger.Debug("Knockback: client: %i, strength: %.1f (massMod: %.1f).",
entity.oldEnt->s.number, strength, massMod);
}
示例13: SetHealth
void HealthComponent::SetHealth(float health) {
Math::Clamp(health, FLT_EPSILON, maxHealth);
healthLogger.Debug("Changing health: %3.1f → %3.1f.", this->health, health);
ScaleDamageAccounts(health - this->health);
HealthComponent::health = health;
}
示例14: GetNonLocationalDamageMod
float ArmorComponent::GetNonLocationalDamageMod() {
class_t pcl = (class_t)entity.oldEnt->client->ps.stats[STAT_CLASS];
for (int regionNum = 0; regionNum < g_numDamageRegions[pcl]; regionNum++) {
damageRegion_t *region = &g_damageRegions[pcl][regionNum];
if (!region->nonlocational) continue;
armorLogger.Debug("Found non-locational damage modifier of %.2f.", region->modifier);
return region->modifier;
}
armorLogger.Debug("No non-locational damage modifier found.");
return 1.0f;
}
示例15: ResetPitch
void TurretComponent::ResetPitch() {
Vec3 targetRelativeAngles = relativeAimAngles;
targetRelativeAngles[PITCH] = 0.0f;
directionToTarget = RelativeAnglesToDirection(targetRelativeAngles);
turretLogger.Debug("Target pitch reset. New direction: %s.", directionToTarget);
}