Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
bits.qh File Reference
#include "log.qh"
Include dependency graph for bits.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define BIT(n)
 Only ever assign into the first 24 bits in QC (so max is BIT(23)).
#define BITS(n)
#define BITSET(var, mask, flag)

Enumerations

enum  {
  OP_SET , OP_MIN , OP_MAX , OP_PLUS ,
  OP_MINUS
}

Functions

ERASEABLE bool GiveBit (entity e,.int fld, int bit, int op, int val)
ERASEABLE bool GiveValue (entity e,.int fld, int op, int val)
ERASEABLE int lowestbit (int f)
ERASEABLE int randombit (int bits)
ERASEABLE int randombits (int bits, int k, bool error_return)

Macro Definition Documentation

◆ BIT

#define BIT ( n)
Value:
(1 << (n))

Only ever assign into the first 24 bits in QC (so max is BIT(23)).

QC converts the float to int, performs the bit operation, then converts it back. Assigning to the highest bits means some of the low ones might get lost due to float precision.

Definition at line 8 of file bits.qh.

Referenced by _entcs_send(), _GametypeFlags_FromGametype(), _WepSet_FromWeapon(), accuracy_add(), CA_CheckWinner(), CA_PreventStalemate(), ClientData_Send(), compressShotOrigin(), corner_send(), CPM_PM_Aircontrol(), CSQCModel_Hook_PostUpdate(), CSQCPlayer_ApplyBobbing(), CSQCPlayer_CalcRefdef(), ctf_DelayedInit(), ctf_FlagSetup(), Damage_DamageInfo(), decompressShotOrigin(), dom_spawnteams(), door_init_keys(), EliminatedPlayers_SendEntity(), Ent_WaypointSprite(), entcs_force_origin(), entcs_think(), g_clientmodel_dropbyspawnflags(), g_clientmodel_genericsendentity(), g_clientmodel_setcolormaptoactivator(), g_clientmodel_think(), g_model_setcolormaptoactivator(), get_team_list(), gettooltip(), GiveItems(), havocbot_goalrating_ons_controlpoints_attack(), HUD_Mod_CTF(), HUD_Physics(), HUD_StrafeHUD(), IL_INIT(), Inventory_Write(), Item_GiveTo(), kh_GetMissingTeams(), MapVote_Init(), MapVote_ReadMask(), MapVote_SendEntity(), MapVote_TouchMask(), MapVote_TouchVotes(), MapVote_Winner(), MapVote_WriteMask(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), Nagger_ReadyCounted(), Nagger_SendEntity(), Nagger_VoteChanged(), Nagger_VoteCountChanged(), nb_spawnteams(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NumTeams(), ons_ControlPoint_CanBeLinked(), onslaught_updatelinks(), PlayerScore_Add(), PlayerScore_Clear(), PlayerScore_SendEntity(), PlayerScore_Set(), PM_check_specialcommand(), ReadEntcs(), relocate_spawnpoint(), Score_ClearAll(), ScoreInfo_Init(), SelectSpawnPoint(), set_dom_state(), setDependent_Check(), setDependentAND(), setDependentNOT(), setDependentOR(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), STATIC_INIT(), StatusEffects_Write(), SUB_UseTargets_Ex(), SurvivalStatuses_SendEntity(), tdm_DelayedInit(), Team_IndexToBit(), Team_TeamToBit(), TeamBalance_CheckAllowedTeams(), TeamScore_AddToTeam(), TeamScore_SendEntity(), tmayhem_DelayedInit(), TossGib(), trigger_common_write(), viewloc_PlayerPhysics(), W_GunAlign(), WarpZone_PostTeleportPlayer_Callback(), WarpZone_Touch(), WaypointSprite_Ping(), and WaypointSprite_UpdateTeamRadar().

◆ BITS

◆ BITSET

#define BITSET ( var,
mask,
flag )

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OP_SET 
OP_MIN 
OP_MAX 
OP_PLUS 
OP_MINUS 

Definition at line 76 of file bits.qh.

76 {
77 OP_SET,
78 OP_MIN,
79 OP_MAX,
80 OP_PLUS,
82};
@ OP_MIN
Definition bits.qh:78
@ OP_PLUS
Definition bits.qh:80
@ OP_MAX
Definition bits.qh:79
@ OP_SET
Definition bits.qh:77
@ OP_MINUS
Definition bits.qh:81

Function Documentation

◆ GiveBit()

ERASEABLE bool GiveBit ( entity e,
.int fld,
int bit,
int op,
int val )

Definition at line 85 of file bits.qh.

86{
87 int v0 = (e.(fld) & bit);
88 switch (op)
89 {
90 case OP_SET:
91 if (val > 0) e.(fld) |= bit;
92 else e.(fld) &= ~bit;
93 break;
94 case OP_MIN:
95 case OP_PLUS:
96 if (val > 0) e.(fld) |= bit;
97 break;
98 case OP_MAX:
99 if (val <= 0) e.(fld) &= ~bit;
100 break;
101 case OP_MINUS:
102 if (val > 0) e.(fld) &= ~bit;
103 break;
104 }
105 int v1 = (e.(fld) & bit);
106 return v0 != v1;
107}

References entity(), OP_MAX, OP_MIN, OP_MINUS, OP_PLUS, and OP_SET.

Referenced by GiveItems().

◆ GiveValue()

ERASEABLE bool GiveValue ( entity e,
.int fld,
int op,
int val )

Definition at line 110 of file bits.qh.

111{
112 int v0 = e.(fld);
113 switch (op)
114 {
115 case OP_SET:
116 e.(fld) = val;
117 break;
118 case OP_MIN:
119 e.(fld) = max(e.(fld), val); // min 100 cells = at least 100 cells
120 break;
121 case OP_MAX:
122 e.(fld) = min(e.(fld), val);
123 break;
124 case OP_PLUS:
125 e.(fld) += val;
126 break;
127 case OP_MINUS:
128 e.(fld) -= val;
129 break;
130 }
131 int v1 = e.(fld);
132 return v0 != v1;
133}
float min(float f,...)
float max(float f,...)

References entity(), max(), min(), OP_MAX, OP_MIN, OP_MINUS, OP_PLUS, and OP_SET.

◆ lowestbit()

ERASEABLE int lowestbit ( int f)

Definition at line 17 of file bits.qh.

18{
19 f &= ~(f << 1);
20 f &= ~(f << 2);
21 f &= ~(f << 4);
22 f &= ~(f << 8);
23 f &= ~(f << 16);
24 return f;
25}

Referenced by item_keys_keylist(), and spawnfunc().

◆ randombit()

ERASEABLE int randombit ( int bits)

Definition at line 28 of file bits.qh.

29{
30 if (!(bits & (bits - 1))) // this ONLY holds for powers of two!
31 return bits;
32
33 int r = random();
34 int b = 0;
35 int n = 0;
36
37 for (int f = 1; f <= bits; f *= 2)
38 {
39 if (bits & f)
40 {
41 ++n;
42 r *= n;
43 if (r <= 1) b = f;
44 else r = (r - 1) / (n - 1);
45 }
46 }
47 return b;
48}
float random(void)

References random().

Referenced by randombits().

◆ randombits()

ERASEABLE int randombits ( int bits,
int k,
bool error_return )

Definition at line 51 of file bits.qh.

52{
53 int r = 0;
54 while (k > 0 && bits != r)
55 {
56 r += randombit(bits - r);
57 --k;
58 }
59 if (error_return)
60 if (k > 0) return -1;
61 // all
62 return r;
63}
ERASEABLE int randombit(int bits)
Definition bits.qh:28

References randombit().