From: terencehill Date: Fri, 29 Jun 2018 11:33:51 +0000 (+0200) Subject: Reduce GetResourceAmount calls in gamemodes code where possible; update hash X-Git-Tag: xonotic-v0.8.5~1968 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f11d1c222f409f970b5dad55ec98734c1b38f68a;p=xonotic%2Fxonotic-data.pk3dir.git Reduce GetResourceAmount calls in gamemodes code where possible; update hash --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9be16a845..153b172f2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,7 +29,7 @@ test_sv_game: - wget -O data/maps/stormkeep.waypoints https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints - wget -O data/maps/stormkeep.waypoints.cache https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints.cache - make - - EXPECT=91764aaadf9642cb4f0f372b96119858 + - EXPECT=b8f4fa5002af1f9f2d5ac3d1809ed188 - HASH=$(${ENGINE} -noconfig -nohome +exec serverbench.cfg | tee /dev/stderr | grep '^:' diff --git a/qcsrc/common/gamemodes/gamemode/assault/assault.qc b/qcsrc/common/gamemodes/gamemode/assault/assault.qc index 9a2d6af1d..96017310f 100644 --- a/qcsrc/common/gamemodes/gamemode/assault/assault.qc +++ b/qcsrc/common/gamemodes/gamemode/assault/assault.qc @@ -31,7 +31,8 @@ void assault_objective_use(entity this, entity actor, entity trigger) vector target_objective_spawn_evalfunc(entity this, entity player, entity spot, vector current) { - if(GetResourceAmount(this, RESOURCE_HEALTH) < 0 || GetResourceAmount(this, RESOURCE_HEALTH) >= ASSAULT_VALUE_INACTIVE) + float hlth = GetResourceAmount(this, RESOURCE_HEALTH); + if (hlth < 0 || hlth >= ASSAULT_VALUE_INACTIVE) return '-1 0 0'; return current; } @@ -61,16 +62,17 @@ void assault_objective_decrease_use(entity this, entity actor, entity trigger) else return; // already activated! cannot activate again! - if(GetResourceAmount(this.enemy, RESOURCE_HEALTH) < ASSAULT_VALUE_INACTIVE) + float hlth = GetResourceAmount(this.enemy, RESOURCE_HEALTH); + if (hlth < ASSAULT_VALUE_INACTIVE) { - if(GetResourceAmount(this.enemy, RESOURCE_HEALTH) - this.dmg > 0.5) + if (hlth - this.dmg > 0.5) { GameRules_scoring_add_team(actor, SCORE, this.dmg); TakeResource(this.enemy, RESOURCE_HEALTH, this.dmg); } else { - GameRules_scoring_add_team(actor, SCORE, GetResourceAmount(this.enemy, RESOURCE_HEALTH)); + GameRules_scoring_add_team(actor, SCORE, hlth); GameRules_scoring_add_team(actor, ASSAULT_OBJECTIVES, 1); SetResourceAmountExplicit(this.enemy, RESOURCE_HEALTH, -1); @@ -334,7 +336,8 @@ spawnfunc(target_objective_decrease) bool destructible_heal(entity targ, entity inflictor, float amount, float limit) { float true_limit = ((limit != RESOURCE_LIMIT_NONE) ? limit : targ.max_health); - if(GetResourceAmount(targ, RESOURCE_HEALTH) <= 0 || GetResourceAmount(targ, RESOURCE_HEALTH) >= true_limit) + float hlth = GetResourceAmount(targ, RESOURCE_HEALTH); + if (hlth <= 0 || hlth >= true_limit) return false; GiveResourceWithLimit(targ, RESOURCE_HEALTH, amount, true_limit); @@ -411,7 +414,8 @@ void havocbot_goalrating_ast_targets(entity this, float ratingscale) entity destr = it; IL_EACH(g_assault_objectivedecreasers, it.targetname == destr.target, { - if(GetResourceAmount(it.enemy, RESOURCE_HEALTH) > 0 && GetResourceAmount(it.enemy, RESOURCE_HEALTH) < ASSAULT_VALUE_INACTIVE) + float hlth = GetResourceAmount(it.enemy, RESOURCE_HEALTH); + if (hlth > 0 && hlth < ASSAULT_VALUE_INACTIVE) { found = true; break; diff --git a/qcsrc/common/gamemodes/gamemode/freezetag/freezetag.qc b/qcsrc/common/gamemodes/gamemode/freezetag/freezetag.qc index 9c5083209..7f126cea2 100644 --- a/qcsrc/common/gamemodes/gamemode/freezetag/freezetag.qc +++ b/qcsrc/common/gamemodes/gamemode/freezetag/freezetag.qc @@ -17,10 +17,10 @@ void freezetag_count_alive_players() FOREACH_CLIENT(IS_PLAYER(it), { switch(it.team) { - case NUM_TEAM_1: ++total_players; if(GetResourceAmount(it, RESOURCE_HEALTH) >= 1 && STAT(FROZEN, it) != 1) ++redalive; break; - case NUM_TEAM_2: ++total_players; if(GetResourceAmount(it, RESOURCE_HEALTH) >= 1 && STAT(FROZEN, it) != 1) ++bluealive; break; - case NUM_TEAM_3: ++total_players; if(GetResourceAmount(it, RESOURCE_HEALTH) >= 1 && STAT(FROZEN, it) != 1) ++yellowalive; break; - case NUM_TEAM_4: ++total_players; if(GetResourceAmount(it, RESOURCE_HEALTH) >= 1 && STAT(FROZEN, it) != 1) ++pinkalive; break; + case NUM_TEAM_1: ++total_players; if(STAT(FROZEN, it) != 1 && GetResourceAmount(it, RESOURCE_HEALTH) >= 1) ++redalive; break; + case NUM_TEAM_2: ++total_players; if(STAT(FROZEN, it) != 1 && GetResourceAmount(it, RESOURCE_HEALTH) >= 1) ++bluealive; break; + case NUM_TEAM_3: ++total_players; if(STAT(FROZEN, it) != 1 && GetResourceAmount(it, RESOURCE_HEALTH) >= 1) ++yellowalive; break; + case NUM_TEAM_4: ++total_players; if(STAT(FROZEN, it) != 1 && GetResourceAmount(it, RESOURCE_HEALTH) >= 1) ++pinkalive; break; } }); FOREACH_CLIENT(IS_REAL_CLIENT(it), { @@ -141,14 +141,14 @@ float freezetag_CheckWinner() entity freezetag_LastPlayerForTeam(entity this) { entity last_pl = NULL; - FOREACH_CLIENT(IS_PLAYER(it) && it != this, { - if(GetResourceAmount(it, RESOURCE_HEALTH) >= 1) - if(!STAT(FROZEN, it)) - if(SAME_TEAM(it, this)) - if(!last_pl) - last_pl = it; - else - return NULL; + FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), { + if (!STAT(FROZEN, it) && GetResourceAmount(it, RESOURCE_HEALTH) >= 1) + { + if (!last_pl) + last_pl = it; + else + return NULL; + } }); return last_pl; } @@ -568,8 +568,8 @@ MUTATOR_HOOKFUNCTION(ft, FragCenterMessage) return; // target was already frozen, so this is just pushing them off the cliff Send_Notification(NOTIF_ONE, frag_attacker, MSG_CHOICE, CHOICE_FRAG_FREEZE, frag_target.netname, kill_count_to_attacker, (IS_BOT_CLIENT(frag_target) ? -1 : CS(frag_target).ping)); - Send_Notification(NOTIF_ONE, frag_target, MSG_CHOICE, CHOICE_FRAGGED_FREEZE, frag_attacker.netname, kill_count_to_target, - GetResourceAmount(frag_attacker, RESOURCE_HEALTH), GetResourceAmount(frag_attacker, RESOURCE_ARMOR), (IS_BOT_CLIENT(frag_attacker) ? -1 : CS(frag_attacker).ping)); + Send_Notification(NOTIF_ONE, frag_target, MSG_CHOICE, CHOICE_FRAGGED_FREEZE, frag_attacker.netname, kill_count_to_target, + GetResourceAmount(frag_attacker, RESOURCE_HEALTH), GetResourceAmount(frag_attacker, RESOURCE_ARMOR), (IS_BOT_CLIENT(frag_attacker) ? -1 : CS(frag_attacker).ping)); return true; } @@ -582,7 +582,7 @@ void freezetag_Initialize() freezetag_teams = BITS(bound(2, freezetag_teams, 4)); GameRules_scoring(freezetag_teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, { - field(SP_FREEZETAG_REVIVALS, "revivals", 0); + field(SP_FREEZETAG_REVIVALS, "revivals", 0); }); round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null); diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc index fd050df0a..f0217de7e 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc @@ -449,15 +449,17 @@ void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker bool ons_ControlPoint_Icon_Heal(entity targ, entity inflictor, float amount, float limit) { + float hlth = GetResourceAmount(targ, RESOURCE_HEALTH); float true_limit = ((limit != RESOURCE_LIMIT_NONE) ? limit : targ.max_health); - if(GetResourceAmount(targ, RESOURCE_HEALTH) <= 0 || GetResourceAmount(targ, RESOURCE_HEALTH) >= true_limit) + if (hlth <= 0 || hlth >= true_limit) return false; GiveResourceWithLimit(targ, RESOURCE_HEALTH, amount, true_limit); + hlth = GetResourceAmount(targ, RESOURCE_HEALTH); if(targ.owner.iscaptured) - WaypointSprite_UpdateHealth(targ.owner.sprite, GetResourceAmount(targ, RESOURCE_HEALTH)); + WaypointSprite_UpdateHealth(targ.owner.sprite, hlth); else - WaypointSprite_UpdateBuildFinished(targ.owner.sprite, time + (targ.max_health - GetResourceAmount(targ, RESOURCE_HEALTH)) / (targ.count / ONS_CP_THINKRATE)); + WaypointSprite_UpdateBuildFinished(targ.owner.sprite, time + (targ.max_health - hlth) / (targ.count / ONS_CP_THINKRATE)); targ.SendFlags |= CPSF_STATUS; return true; } @@ -904,13 +906,14 @@ void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float d } } TakeResource(this, RESOURCE_HEALTH, damage); - WaypointSprite_UpdateHealth(this.sprite, GetResourceAmount(this, RESOURCE_HEALTH)); + float hlth = GetResourceAmount(this, RESOURCE_HEALTH); + WaypointSprite_UpdateHealth(this.sprite, hlth); // choose an animation frame based on health - this.frame = 10 * bound(0, (1 - GetResourceAmount(this, RESOURCE_HEALTH) / this.max_health), 1); + this.frame = 10 * bound(0, (1 - hlth / this.max_health), 1); // see if the generator is still functional, or dying - if (GetResourceAmount(this, RESOURCE_HEALTH) > 0) + if (hlth > 0) { - this.lasthealth = GetResourceAmount(this, RESOURCE_HEALTH); + this.lasthealth = hlth; } else { @@ -964,13 +967,15 @@ void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float d bool ons_GeneratorHeal(entity targ, entity inflictor, float amount, float limit) { float true_limit = ((limit != RESOURCE_LIMIT_NONE) ? limit : targ.max_health); - if(GetResourceAmount(targ, RESOURCE_HEALTH) <= 0 || GetResourceAmount(targ, RESOURCE_HEALTH) >= true_limit) + float hlth = GetResourceAmount(targ, RESOURCE_HEALTH); + if (hlth <= 0 || hlth >= true_limit) return false; GiveResourceWithLimit(targ, RESOURCE_HEALTH, amount, true_limit); - WaypointSprite_UpdateHealth(targ.sprite, GetResourceAmount(targ, RESOURCE_HEALTH)); - targ.frame = 10 * bound(0, (1 - GetResourceAmount(targ, RESOURCE_HEALTH) / targ.max_health), 1); - targ.lasthealth = GetResourceAmount(targ, RESOURCE_HEALTH); + hlth = GetResourceAmount(targ, RESOURCE_HEALTH); + WaypointSprite_UpdateHealth(targ.sprite, hlth); + targ.frame = 10 * bound(0, (1 - hlth / targ.max_health), 1); + targ.lasthealth = hlth; targ.SendFlags |= GSF_STATUS; return true; }