From: terencehill Date: Wed, 6 Sep 2017 15:17:22 +0000 (+0200) Subject: More BITs (and less variables) X-Git-Tag: xonotic-v0.8.5~2479 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e9113dfa049201fd1f843c2aad17f4756017a8c1;p=xonotic%2Fxonotic-data.pk3dir.git More BITs (and less variables) --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 9fc26c564..988cdf35e 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -471,11 +471,10 @@ NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew) int sf = ReadShort(); int lf = ReadShort(); #endif - int p; - for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2) - if(sf & p) + for(i = 0; i < MAX_TEAMSCORE; ++i) + if(sf & BIT(i)) { - if(lf & p) + if(lf & BIT(i)) o.(teamscores(i)) = ReadInt24_t(); else o.(teamscores(i)) = ReadChar(); @@ -587,7 +586,7 @@ NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew) for(i = 1; i <= maxclients; i += 8) { f = ReadByte(); - for(j = i-1, b = 1; b < 256; b *= 2, ++j) + for(j = i-1, b = BIT(0); b < BIT(8); b <<= 1, ++j) if (!(f & b)) if(playerslots[j]) playerslots[j].ready = 0; diff --git a/qcsrc/client/mapvoting.qc b/qcsrc/client/mapvoting.qc index b34bd0f3a..87b6d585b 100644 --- a/qcsrc/client/mapvoting.qc +++ b/qcsrc/client/mapvoting.qc @@ -563,7 +563,7 @@ void MapVote_ReadMask() int i; if ( mv_num_maps < 24 ) { - int mask, power; + int mask; if(mv_num_maps < 8) mask = ReadByte(); else if(mv_num_maps < 16) @@ -571,9 +571,9 @@ void MapVote_ReadMask() else mask = ReadLong(); - for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2) + for(i = 0; i < mv_num_maps; ++i) { - if ( mask & power ) + if (mask & BIT(i)) mv_flags[i] |= GTV_AVAILABLE; else mv_flags[i] &= ~GTV_AVAILABLE; diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index 8cfed5bae..1a786cc7f 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -81,8 +81,9 @@ bool Nagger_SendEntity(entity this, entity to, float sendflags) { for (i = 1; i <= maxclients; i += 8) { - for (f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e)) - if (!IS_REAL_CLIENT(e) || e.ready) f |= b; + for (f = 0, e = edict_num(i), b = BIT(0); b < BIT(8); b <<= 1, e = nextent(e)) + if (!IS_REAL_CLIENT(e) || e.ready) + f |= b; WriteByte(MSG_ENTITY, f); } } diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 266f7734b..11bc60238 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -54,7 +54,7 @@ vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, bool TeamScore_SendEntity(entity this, entity to, float sendflags) { - float i, p, longflags; + float i, longflags; WriteHeader(MSG_ENTITY, ENT_CLIENT_TEAMSCORES); int t = this.team - 1; @@ -62,9 +62,9 @@ bool TeamScore_SendEntity(entity this, entity to, float sendflags) WriteByte(MSG_ENTITY, t); longflags = 0; - for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2) + for(i = 0; i < MAX_TEAMSCORE; ++i) if(this.(teamscores(i)) > 127 || this.(teamscores(i)) <= -128) - longflags |= p; + longflags |= BIT(i); #if MAX_TEAMSCORE <= 8 WriteByte(MSG_ENTITY, sendflags); @@ -73,10 +73,10 @@ bool TeamScore_SendEntity(entity this, entity to, float sendflags) WriteShort(MSG_ENTITY, sendflags); WriteShort(MSG_ENTITY, longflags); #endif - for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2) - if(sendflags & p) + for(i = 0; i < MAX_TEAMSCORE; ++i) + if(sendflags & BIT(i)) { - if(longflags & p) + if(longflags & BIT(i)) WriteInt24_t(MSG_ENTITY, this.(teamscores(i))); else WriteChar(MSG_ENTITY, this.(teamscores(i)));