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(), 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(), orb_send(), 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(), Team_IndexToBit(), Team_TeamToBit(), TeamBalance_CheckAllowedTeams(), TeamScore_AddToTeam(), TeamScore_SendEntity(), 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.

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

Function Documentation

◆ GiveBit()

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

Definition at line 86 of file bits.qh.

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

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 116 of file bits.qh.

117{
118 int v0 = e.(fld);
119 switch (op)
120 {
121 case OP_SET:
122 e.(fld) = val;
123 break;
124 case OP_MIN:
125 e.(fld) = max(e.(fld), val); // min 100 cells = at least 100 cells
126 break;
127 case OP_MAX:
128 e.(fld) = min(e.(fld), val);
129 break;
130 case OP_PLUS:
131 e.(fld) += val;
132 break;
133 case OP_MINUS:
134 e.(fld) -= val;
135 break;
136 }
137 int v1 = e.(fld);
138 return v0 != v1;
139}
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 for (int f = 1; f <= bits; f *= 2)
37 if (bits & f)
38 {
39 ++n;
40 r *= n;
41 if (r <= 1)
42 b = f;
43 else
44 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 && k > 0)
60 return -1;
61 // all
62 return r;
63}
ERASEABLE int randombit(int bits)
Definition bits.qh:28

References randombit().